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 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; } }))); }