/// <summary> /// Mounts a drive /// </summary> /// <param name="credentials"></param> /// <param name="azureDriveContainerName"></param> /// <param name="azureDrivePageBlobName"></param> /// <param name="azureDriveCacheDirName"></param> /// <param name="azureDriveCacheSizeInMB"></param> /// <param name="azureDriveSizeInMB"></param> /// <returns></returns> public static string MountAzureDrive(CloudStorageAccount csa, string azureDriveContainerName, string azureDrivePageBlobName, string azureDriveCacheDirName, int azureDriveCacheSizeInMB, int azureDriveSizeInMB, DriveMountOptions driveOptions, out bool wasAlreadyMounted) { // Create the blob client CloudBlobClient client = csa.CreateCloudBlobClient(); // Create the blob container which will contain the pageblob corresponding to the azure drive. CloudBlobContainer container = client.GetContainerReference(azureDriveContainerName); container.CreateIfNotExist(); // Get the page blob reference which will be used by the azure drive. CloudPageBlob blob = container.GetPageBlobReference(azureDrivePageBlobName); return(MountAzureDrive(csa, blob.Uri, azureDriveCacheDirName, azureDriveCacheSizeInMB, azureDriveSizeInMB, driveOptions, out wasAlreadyMounted)); }
/// <summary> /// /// </summary> /// <param name="accountName"></param> /// <param name="accountKey"></param> /// <param name="vhdUri"></param> /// <param name="azureDriveCacheDirName"></param> /// <param name="azureDriveCacheSizeInMB"></param> /// <param name="azureDriveSizeInMB"></param> /// <param name="driveOptions"></param> /// <returns></returns> public static string MountAzureDrive(string accountName, string accountKey, Uri vhdUri, string azureDriveCacheDirName, int azureDriveCacheSizeInMB, int azureDriveSizeInMB, DriveMountOptions driveOptions, out bool wasAlreadyMounted) { // StorageCredentialsAccountAndKey credentials = new StorageCredentialsAccountAndKey(accountName, accountKey); CloudStorageAccount csa = WAStorageHelper.GetCloudStorageAccount(accountName, accountKey, false); return(MountAzureDrive(csa, vhdUri, azureDriveCacheDirName, azureDriveCacheSizeInMB, azureDriveSizeInMB, driveOptions, out wasAlreadyMounted)); }
/// <summary> /// /// </summary> /// <param name="csa"></param> /// <param name="vhdUri"></param> /// <param name="azureDriveCacheDirName"></param> /// <param name="azureDriveCacheSizeInMB"></param> /// <param name="azureDriveSizeInMB"></param> /// <param name="driveOptions"></param> /// <returns></returns> public static string MountAzureDrive(CloudStorageAccount csa, Uri vhdUri, string azureDriveCacheDirName, int azureDriveCacheSizeInMB, int azureDriveSizeInMB, DriveMountOptions driveOptions, out bool wasAlreadyMounted) { wasAlreadyMounted = false; // Initialize the cache for mounting the drive. CloudDrive.InitializeCache(azureDriveCacheDirName, azureDriveCacheSizeInMB); CloudDrive drive = null; drive = new CloudDrive(vhdUri, csa.Credentials); Uri driveUri = CloudDrive.GetMountedDrives().Values.Where(tuple => tuple == vhdUri).FirstOrDefault(); // Find out whether the drive has already been mounted by some other instance. if (driveUri == null) { try { // Create the drive. Currently no method is provided to verify whether the // drive is already created or not. drive.Create(azureDriveSizeInMB); } catch (CloudDriveException) { // An exception can be thrown if the drive already exists. Hence ignore the // exception here. If anything is not right, the Mount() will fail. } // Mount the drive. string driveLetter = drive.Mount(azureDriveCacheSizeInMB, driveOptions); return(driveLetter); } else { //Drive is already mounted. So get the drive letter for the drive IDictionary <string, Uri> drives = CloudDrive.GetMountedDrives(); IEnumerator <KeyValuePair <string, Uri> > e = drives.GetEnumerator(); while (e.MoveNext()) { if (e.Current.Value == vhdUri) { wasAlreadyMounted = true; return(e.Current.Key); } } } throw new Exception("Unable to mount the drive." + vhdUri.ToString()); }