From 95d82b4637c7361b39f1623c518ad29a2d07816b Mon Sep 17 00:00:00 2001 From: Patrick Lang Date: Tue, 24 Oct 2017 22:20:46 -0700 Subject: [PATCH 1/2] Fixing auto checkpoints for generation 2 VMs. Resolves #5506 Also cleaning up ifs --- common/powershell/hyperv/hyperv.go | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/common/powershell/hyperv/hyperv.go b/common/powershell/hyperv/hyperv.go index 0c649c450..fd32d75a6 100644 --- a/common/powershell/hyperv/hyperv.go +++ b/common/powershell/hyperv/hyperv.go @@ -202,8 +202,11 @@ if ($harddrivePath){ } ` var ps powershell.PowerShellCmd - err := ps.Run(script, vmName, path, harddrivePath, vhdRoot, strconv.FormatInt(ram, 10), strconv.FormatInt(diskSize, 10), switchName, strconv.FormatInt(int64(generation), 10)) - return err + if err := ps.Run(script, vmName, path, harddrivePath, vhdRoot, strconv.FormatInt(ram, 10), strconv.FormatInt(diskSize, 10), switchName, strconv.FormatInt(int64(generation), 10)); err != nil { + return err + } + + return DisableAutomaticCheckpoints(vmName) } else { var script = ` param([string]$vmName, [string]$path, [string]$harddrivePath, [string]$vhdRoot, [long]$memoryStartupBytes, [long]$newVHDSizeBytes, [string]$switchName) @@ -217,15 +220,11 @@ if ($harddrivePath){ } ` var ps powershell.PowerShellCmd - err := ps.Run(script, vmName, path, harddrivePath, vhdRoot, strconv.FormatInt(ram, 10), strconv.FormatInt(diskSize, 10), switchName) - - if err != nil { + if err := ps.Run(script, vmName, path, harddrivePath, vhdRoot, strconv.FormatInt(ram, 10), strconv.FormatInt(diskSize, 10), switchName); err != nil { return err } - err = DisableAutomaticCheckpoints(vmName) - - if err != nil { + if err := DisableAutomaticCheckpoints(vmName); err != nil { return err } @@ -368,21 +367,18 @@ if ($vm) { func CloneVirtualMachine(cloneFromVmxcPath string, cloneFromVmName string, cloneFromSnapshotName string, cloneAllSnapshots bool, vmName string, path string, harddrivePath string, ram int64, switchName string) error { if cloneFromVmName != "" { - err := ExportVmxcVirtualMachine(path, cloneFromVmName, cloneFromSnapshotName, cloneAllSnapshots) - if err != nil { + if err := ExportVmxcVirtualMachine(path, cloneFromVmName, cloneFromSnapshotName, cloneAllSnapshots); err != nil { return err } } if cloneFromVmxcPath != "" { - err := CopyVmxcVirtualMachine(path, cloneFromVmxcPath) - if err != nil { + if err := CopyVmxcVirtualMachine(path, cloneFromVmxcPath); err != nil { return err } } - err := ImportVmxcVirtualMachine(path, vmName, harddrivePath, ram, switchName) - if err != nil { + if err := ImportVmxcVirtualMachine(path, vmName, harddrivePath, ram, switchName); err != nil { return err } From 6d5f75e1180233ce4bbdfc52c0946e49eee3c8ef Mon Sep 17 00:00:00 2001 From: Patrick Lang Date: Wed, 25 Oct 2017 21:47:14 -0700 Subject: [PATCH 2/2] run gofmt --- common/powershell/hyperv/hyperv.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/powershell/hyperv/hyperv.go b/common/powershell/hyperv/hyperv.go index fd32d75a6..f34004f60 100644 --- a/common/powershell/hyperv/hyperv.go +++ b/common/powershell/hyperv/hyperv.go @@ -205,7 +205,7 @@ if ($harddrivePath){ if err := ps.Run(script, vmName, path, harddrivePath, vhdRoot, strconv.FormatInt(ram, 10), strconv.FormatInt(diskSize, 10), switchName, strconv.FormatInt(int64(generation), 10)); err != nil { return err } - + return DisableAutomaticCheckpoints(vmName) } else { var script = `