2017-02-06 69 views
0

我有Windows桌面应用程序命令或自动化VMware功能。我想重命名现有快照并使用以下流程进行更新,但我没有看到任何vmware API重命名现有快照。任何人都可以提供有关如何重命名vmware快照的信息吗? 感谢重命名vmware快照

点击 '注册并启动快照' - >启动客户VM Shutdown->重新命名当前Snapshot- SS1至温 - SS1->以新快照 与当前快照名称(如SS1) - >删除以前更名为 的快照(即Temp-SS1)。

+0

你能发表一些相关的代码吗? –

+0

VirtualMachine vmObject =(VirtualMachine)vimClient.FindEntityViews(typeof(VirtualMachine),null,filter,null).FirstOrDefault(); (vmObject!= null) { vmObject.ShutdownGuest();如果(vmObject!= null) \t \t \t \t \t “在这里,我要重命名我的以前的快照(SS为 '临时SS1'!)” \t \t \t \t \t vmObject.CreateSnapshot(snapShotName,snapShotDescription,假的,假的); } – user7393522

回答

0

以上可以通过简单以下两种方式来完成:

public bool CreateSnapShot(string vmName, string snapShotName, string snapShotDescription, bool replaceSnapShot, string currentSnapShotName) 
    { 
     try 
     { 
      NameValueCollection filter = new NameValueCollection(); 
      filter.Add(Constants.VM_FILTER_NAME, vmName); 

      ManagedObjectReference snapShotMor = null; 
      VirtualMachine vmObject = (VirtualMachine) vimClient.FindEntityViews(typeof(VirtualMachine), null, filter, null).FirstOrDefault(); 
      if (vmObject != null) 
      { 
       if (vmObject.Runtime.PowerState == VirtualMachinePowerState.poweredOn) 
        vmObject.ShutdownGuest(); 
       while (vmObject.Runtime.PowerState == VirtualMachinePowerState.poweredOn) 
       { 
        Thread.Sleep(5000); 
        vmObject.UpdateViewData();//This will refresh VM object state 
       } 

       if (replaceSnapShot && currentSnapShotName!= "") 
       { 
        if (RenameSnapshot(snapShotName, vmObject)) 
         snapShotMor = vmObject.CreateSnapshot(snapShotName, snapShotDescription, false, false); 
       } 
       else snapShotMor = vmObject.CreateSnapshot(snapShotName, snapShotDescription, false, false); 

       if (snapShotMor != null) 
        return true; 
       else return false; 
      } 
      else return false; 
     } 
     catch (Exception ex) 
     { 
      return false; 
     }   
    } 

快照重命名可以通过以下方法来完成:您可以删除更名

public bool RenameSnapshot(string snapShotName, VirtualMachine vmObject) 
    { 
     try 
     {             
      ManagedObjectReference snapshotObject = vmObject.Snapshot.CurrentSnapshot; 
      VirtualMachineSnapshot currentSnapshotName = new VirtualMachineSnapshot(vimClient, snapshotObject); 
      currentSnapshotName.RenameSnapshot("Temp-" + snapShotName, "Renamed for deletion"); 

      return true; 
     } 

     catch (Exception ex) 
     { 
      return false; 
     } 
    } 

经过以上两步(TEMP)快照。