From d4de89e0575e050fdd1962b81c166d0e438d85cd Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Wed, 19 Dec 2018 16:35:02 -0800 Subject: [PATCH] move powershell templating into separate script so we can test it --- common/powershell/hyperv/hyperv.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/common/powershell/hyperv/hyperv.go b/common/powershell/hyperv/hyperv.go index 729dadb3b..1c4201c96 100644 --- a/common/powershell/hyperv/hyperv.go +++ b/common/powershell/hyperv/hyperv.go @@ -204,10 +204,9 @@ Hyper-V\Set-VMFloppyDiskDrive -VMName $vmName -Path $null return err } -func CreateVirtualMachine(vmName string, path string, harddrivePath string, ram int64, +func getCreateVMScript(vmName string, path string, harddrivePath string, ram int64, diskSize int64, diskBlockSize int64, switchName string, generation uint, - diffDisks bool, fixedVHD bool, version string) error { - + diffDisks bool, fixedVHD bool, version string) string { type scriptOptions struct { VersionTag string VMName string @@ -287,7 +286,18 @@ else { DiffDisks: diffDisks, FixedVHD: fixedVHD, }) - script := scriptBuilder.String() + + return scriptBuilder.String() +} + +func CreateVirtualMachine(vmName string, path string, harddrivePath string, ram int64, + diskSize int64, diskBlockSize int64, switchName string, generation uint, + diffDisks bool, fixedVHD bool, version string) error { + + script := getCreateVMScript(vmName, path, harddrivePath, ram, + diskSize, diskBlockSize, switchName, generation, + diffDisks, fixedVHD, version) + var ps powershell.PowerShellCmd if err := ps.Run(script); err != nil { return err