Exemple #1
0
 public void MountVirtualDiskAndGetName(string path, out string deviceName, out int deviceIndex)
 {
     this.MountVirtualDisk(path);
     try
     {
         IDiskDrive diskDrive1 = CUtils.Retry <IDiskDrive>(20, 2000, (Func <IDiskDrive>)(() =>
         {
             using (MountedStorageImage mountedStorageImage = MountedStorageImage.GetMountedStorageImage(this._Host, path))
             {
                 IDiskDrive diskDrive = DiskDrive.Query(this._Host, "SCSIBus={0} and SCSILogicalUnit={1} and SCSIPort={2} And SCSITargetId={3}", (object)mountedStorageImage.PathId, (object)mountedStorageImage.Lun, (object)mountedStorageImage.PortNumber, (object)mountedStorageImage.TargetId).FirstOrDefault <IDiskDrive>();
                 if (diskDrive == null)
                 {
                     throw new HyperVException("Couldn't locate the disk drive for the mounted storage " + path);
                 }
                 return(diskDrive);
             }
         }));
         deviceIndex = (int)diskDrive1.Index;
         deviceName  = diskDrive1.Name;
     }
     catch (Exception ex)
     {
         this.UnmountVirtualDisk(path);
         throw new HyperVException("Unable to mount " + path, ex);
     }
 }
 public static MountedStorageImage GetMountedStorageImage(IComputerSystem host, string path)
 {
     foreach (MountedStorageImage mountedStorageImage in MountedStorageImage.GetAllMountedStorageImages(host))
     {
         if (string.Equals(mountedStorageImage.Name, path, StringComparison.OrdinalIgnoreCase))
         {
             return(mountedStorageImage);
         }
         mountedStorageImage.Dispose();
     }
     throw new HyperVException("MountedStorageImage not found for " + path);
 }
Exemple #3
0
 public IDiskDrive GetStorageDeviceInfo(string path)
 {
     return(CUtils.Retry <IDiskDrive>(20, 2000, (Func <IDiskDrive>)(() =>
     {
         using (MountedStorageImage mountedStorageImage = MountedStorageImage.GetMountedStorageImage(this._Host, path))
         {
             IDiskDrive diskDrive = DiskDrive.Query(this._Host, "SCSIBus={0} and SCSILogicalUnit={1} and SCSIPort={2} And SCSITargetId={3}", (object)mountedStorageImage.PathId, (object)mountedStorageImage.Lun, (object)mountedStorageImage.PortNumber, (object)mountedStorageImage.TargetId).FirstOrDefault <IDiskDrive>();
             if (diskDrive == null)
             {
                 throw new HyperVException("Couldn't locate the disk drive for the mounted storage " + path);
             }
             return diskDrive;
         }
     })));
 }
Exemple #4
0
 public void UnmountVirtualDisk(string path)
 {
     try
     {
         using (MountedStorageImage mountedStorageImage = MountedStorageImage.GetMountedStorageImage(this._Host, path))
             mountedStorageImage.DetachVirtualHardDisk();
     }
     catch (HyperVException ex)
     {
         if (ex.Message.Contains("MountedStorageImage not found"))
         {
             return;
         }
         throw;
     }
 }