使用Hyper-V经理,我可以连接到一个遥远的虚拟机主机,进入设置虚拟机,并添加一个现有的。虚拟文件作为一个新的硬盘。如果虚拟机主机服务器运行,2008年R2,并且在磁盘被连接到一个控制器,我甚至可以这样做的同时,虚拟机运行(见 What's new in Hyper-V R2).

这样做的手,一切伟大工程。麻烦的是,现在我要自动执行它所以我可以将不同的虚拟硬盘上飞过一些自动化测试。

我已经有C#代码连接到的遥远的虚拟机主机在WMI和启动/停止虚拟机通过调用 RequestStateChange, 我想把它扩大到能够说"这里的路到一个硬盘,将其作为一个驱动器给这个虚拟机"。但是看着 列表WMI虚拟化的课程, 我可以弄清楚如何做到这一点。

最近我已经找到了是的 方法 Msvm_ImageManagementService, 但这看来安装一个虚拟内部目前操作系统,这不是我想要的。

有帮助吗?

解决方案

有必要加入 合成磁盘 (资源类型.磁盘,ResourceSubType.DiskSynthetic)使用Msvm_VirtualSystemManagementService.AddVirtualSystemResources.Parent=SCSI控制器的WMI的道路。

ManagementObject synthetic = Utilities.GetResourceAllocationSettingData(scope,
    ResourceType.Disk, ResourceSubType.DiskSynthetic);
synthetic["Parent"] = <ideControllerPath>; //or SCSI controller path (WMI path)
synthetic["Address"] = <diskDriveAddress>; //0 or 1 for IDE
string[] RASDs = new string[1];
RASDs[0] = synthetic.GetText(TextFormat.CimDtd20);

然后附上 虚拟的硬盘 (资源类型.StorageExtent,ResourceSubType.硬盘)使用Msvm_VirtualSystemManagementService.AddVirtualSystemResources.Parent=合成磁盘的WMI的路径, 连接 =*.硬盘文件的道路。

ManagementObject hardDisk = Utilities.GetResourceAllocationSettingData(scope,  
    ResourceType.StorageExtent, ResourceSubType.VHD);
hardDisk["Parent"] = <syntheticPath>; //WMI path
string[] connection = { <vhdPath> }; //Path to *.vhd file
hardDisk["Connection"] = connection;
string[] RASDs = new string[1];
RASDs[0] = hardDisk.GetText(TextFormat.CimDtd20);

使用 共同事业的虚拟化样品的WMI资源管理器.

其他提示

还看看 http://hypervlib.codeplex.com 对于一个例子。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top