以上可以通过简单以下两种方式来完成:
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)快照。
你能发表一些相关的代码吗? –
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