protected IVirtualDisk ValidateVirtualDisk(string path) { Invariant.ArgumentAssert(File.Exists(path), nameof(path), "The file provided doesn't actually exist"); using (IImageManagementService managementService = ImageManagementService.GetImageManagementService(this._Host)) { managementService.ValidateVirtualHardDisk(path); return((IVirtualDisk) new VirtualDisk(this._Host, path, this._Logger)); } }
public VHDInfo GetCfg() { using (IImageManagementService managementService = ImageManagementService.GetImageManagementService(this._Host)) { using (IVirtualHardDiskSettingData hardDiskSettingData = managementService.GetVirtualHardDiskSettingData(this._Path)) { using (IVirtualHardDiskState virtualHardDiskState = managementService.GetVirtualHardDiskState(this._Path)) return new VHDInfo() { Path = this._Path, FileSize = (long)virtualHardDiskState.FileSize, MaxInternalSize = (long)hardDiskSettingData.MaxInternalSize, ParentPath = hardDiskSettingData.ParentPath, Type = (int)hardDiskSettingData.Type }; } } }
public void MountVirtualDisk(string path, bool assignDriveLetter, bool readOnly) { using (IImageManagementService managementService = ImageManagementService.GetImageManagementService(this._Host)) managementService.AttachVirtualHardDisk(path, assignDriveLetter, readOnly); }
public void MountVirtualDisk(string path) { using (IImageManagementService managementService = ImageManagementService.GetImageManagementService(this._Host)) managementService.AttachVirtualHardDisk(path, false, false); }
public void ChainVhd(string childVhd, string parentVhd) { using (IImageManagementService managementService = ImageManagementService.GetImageManagementService(this._Host)) managementService.SetParentVirtualHardDisk(childVhd, parentVhd, (string)null, true); }
public void CreateVirtualDisk(string path, ulong size, string virtualDiskType, ushort format) { if (File.Exists(path)) { this._Logger.Information(string.Format("Validating existing disk {0}...", (object)path)); try { using (IVirtualDisk virtualDisk = this.ValidateVirtualDisk(path)) { if (virtualDisk != null) { if (virtualDisk.GetCfg().MaxInternalSize >= (long)size) { this._Logger.Information("Existing disk validated."); return; } } } } catch (Exception ex) { if (this.HandleException(ex)) { throw; } else { this._Logger.Warning(ex, "Existing disk validation failed"); } } this._Logger.Information(string.Format("Deleting existing disk {0}...", (object)path)); File.Delete(path); } if ((long)(size % 4096UL) != 0L) { size += 4096UL - size % 4096UL; } using (IImageManagementService managementService = ImageManagementService.GetImageManagementService(this._Host)) { using (IVirtualHardDiskSettingData hardDiskSettingData = VirtualHardDiskSettingData.CreateVirtualHardDiskSettingData(this._Host)) { hardDiskSettingData.Path = path; hardDiskSettingData.MaxInternalSize = size; if (!(virtualDiskType == "Fixed")) { if (!(virtualDiskType == "Dynamic")) { throw new HyperVException("Don't know how to create a disk of type " + virtualDiskType); } hardDiskSettingData.Type = (ushort)3; } else { hardDiskSettingData.Type = (ushort)2; } hardDiskSettingData.Format = format; hardDiskSettingData.PhysicalSectorSize = 512U; managementService.CreateVirtualHardDisk(hardDiskSettingData); } } }