接上回,继续整理针对虚拟机的各种操作。
5、创建与恢复快照
-
-
-
- public void CreateSnapshot()
- {
-
- string path = "DataCenter/vm/vm100";
-
-
- ManagedObjectReference vmRef = m_Service.FindByInventoryPath(m_Content.searchIndex, path);
- if(vmRef != null)
- {
-
- ManagedObjectReference taskRef = m_Service.CreateSnapshot_Task(vmRef, "SnapshotName", "Description", true, true);
- }
- }
-
-
-
-
- public void RevertToCurrentSnapshot()
- {
-
- string path = "DataCenter/vm/vm100";
-
-
- ManagedObjectReference vmRef = m_Service.FindByInventoryPath(m_Content.searchIndex, path);
- if(vmRef != null)
- {
-
- ManagedObjectReference taskRef = m_Service.RevertToCurrentSnapshot_Task(vmRef, null);
- }
- }
6、在同一台主机上从模板复制虚拟机
先要指出,模板本身也是虚拟机,以VI系统中它的类型就是VirtualMachine,只是有特殊属性标明它是模板,因此不能运行。
注意此方法要求源与目标在同一台主机上,后面会讲到如何在不同主机间复制。
-
-
-
- public void Deploy()
- {
-
- string templatePath = "DataCenter/vm/template100";
-
- ManagedObjectReference templateRef = m_Service.FindByInventoryPath(m_Content.searchIndex, templatePath);
-
- ManagedObjectReference folderRef = m_Service.FindByInventoryPath(m_Content.searchIndex, "DataCenter/vm");
-
- ManagedObjectReference poolRef = m_Service.FindByInventoryPath(m_Content.searchIndex, "DataCenter/host/host10/Resources");
-
-
- VirtualMachineRelocateSpec vmRelocSpec = new VirtualMachineRelocateSpec();
- vmRelocSpec.transform = VirtualMachineRelocateTransformation.sparse;
- vmRelocSpec.pool = poolRef;
-
-
- VirtualMachineCloneSpec vmCloneSpec = new VirtualMachineCloneSpec();
- vmCloneSpec.template = false;
- vmCloneSpec.location = vmRelocSpec;
- vmCloneSpec.powerOn = true;
-
-
- ManagedObjectReference taskRef = m_Service.CloneVM_Task(templateRef, folderRef, vmName, vmCloneSpec);
- }
未完待续……
本文转自 BoyTNT 51CTO博客,原文链接:http://blog.51cto.com/boytnt/1029417,如需转载请自行联系原作者