public void TakesSnapshotOnPoweredOnVirtualMachineWhenTakeSnapshotIsCalledAndVirtualMachineIsOn() { IVirtualMachine vm = CreateVirtualMachine(); vm.Start(); string snapshotName = Guid.NewGuid().ToString( "N" ); ManagedObjectReference initialSnapshot = _vmWareVirtualMachine.Snapshot.CurrentSnapshot; try { vm.TakeSnapshot( snapshotName, "Some description" ); _vmWareVirtualMachine.UpdateViewData(); } finally { if ( initialSnapshot.ToString() != _vmWareVirtualMachine.Snapshot.CurrentSnapshot.ToString() ) { VirtualMachineSnapshot snapshot = new VirtualMachineSnapshot( _vmWareVirtualMachine.Client, _vmWareVirtualMachine.Snapshot.CurrentSnapshot ); snapshot.UpdateViewData(); snapshot.RemoveSnapshot( false, null ); } } }
public void RevertsToPoweredOnVmWhenSnapshotWasDoneOnPoweredOnVirtualMachine() { IVirtualMachine vm = CreateVirtualMachine(); vm.Start(); string snapshotName = Guid.NewGuid().ToString( "N" ); ManagedObjectReference initialSnapshot = _vmWareVirtualMachine.Snapshot.CurrentSnapshot; try { vm.TakeSnapshot( snapshotName, "Some description" ); VirtualMachineSnapshot snapshot = new VirtualMachineSnapshot( _vmWareVirtualMachine.Client, initialSnapshot ); snapshot.RevertToSnapshot( null, false ); _vmWareVirtualMachine.UpdateViewData(); Assert.IsFalse( vm.VirtualMachineIsRunning() ); vm.RevertToSnapshot( snapshotName ); Assert.IsTrue( vm.VirtualMachineIsRunning() ); } finally { if ( initialSnapshot.ToString() != _vmWareVirtualMachine.Snapshot.CurrentSnapshot.ToString() ) { VirtualMachineSnapshot snapshot = new VirtualMachineSnapshot( _vmWareVirtualMachine.Client, _vmWareVirtualMachine.Snapshot.CurrentSnapshot ); snapshot.UpdateViewData(); snapshot.RemoveSnapshot( false, null ); } } }