Skip to content

Commit

Permalink
Merge pull request #102 from microsoft/save_bugfix
Browse files Browse the repository at this point in the history
Add command to restore VM
  • Loading branch information
jonah-kohn authored Mar 15, 2024
2 parents 248633d + 7854ffe commit edf3c97
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/virtualization/core/virtualsystem/virtualmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,15 @@ func (vm *VirtualMachine) Resume() error {
return vm.WaitForState(Running, StateChangeTimeoutSeconds)
}

// Restore Virtual Machine
func (vm *VirtualMachine) Restore() error {
err := vm.ChangeState(Running, job.ConcreteJob_JobType_Restore_Virtual_Machine, -1)
if err != nil {
return err
}
return vm.WaitForState(Running, StateChangeTimeoutSeconds)
}

// Pause Virtual Machine
func (vm *VirtualMachine) Pause() error {
err := vm.ChangeState(Paused, job.ConcreteJob_JobType_Pause_Virtual_Machine, -1)
Expand Down
17 changes: 17 additions & 0 deletions pkg/virtualization/core/virtualsystem/virtualmachine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,23 @@ func TestVirtualMachineResume(t *testing.T) {
}
}

func TestVirtualMachineRestore(t *testing.T) {
vm, err := GetVirtualMachineByVMName(whost, "test")
if err != nil {
t.Fatal("Failed " + err.Error())
}
defer vm.Close()

err = vm.Save()
if err != nil {
t.Fatal("Failed " + err.Error())
}
err = vm.Restore()
if err != nil {
t.Fatal("Failed " + err.Error())
}
}

func TestGetVirtualMachineSetting(t *testing.T) {
vm, err := GetVirtualMachineByVMName(whost, "test")
if err != nil {
Expand Down

0 comments on commit edf3c97

Please sign in to comment.