From 181bb0ba23a4d7f532f3b06fa7444c1d80101c90 Mon Sep 17 00:00:00 2001 From: DanHam Date: Sun, 8 Jul 2018 17:22:27 +0100 Subject: [PATCH] Add calling code and skeleton driver to make tests pass --- builder/hyperv/common/driver.go | 2 ++ builder/hyperv/common/driver_ps_4.go | 6 ++++++ builder/hyperv/common/step_collate_artifacts.go | 15 ++++++++++++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/builder/hyperv/common/driver.go b/builder/hyperv/common/driver.go index c1bceed27..0001bd989 100644 --- a/builder/hyperv/common/driver.go +++ b/builder/hyperv/common/driver.go @@ -96,6 +96,8 @@ type Driver interface { PreserveLegacyExportBehaviour(string, string) error + MoveCreatedVHDsToOutputDir(string, string) error + CompactDisks(string) (string, error) RestartVirtualMachine(string) error diff --git a/builder/hyperv/common/driver_ps_4.go b/builder/hyperv/common/driver_ps_4.go index ff9ef1407..59eea7673 100644 --- a/builder/hyperv/common/driver_ps_4.go +++ b/builder/hyperv/common/driver_ps_4.go @@ -223,6 +223,12 @@ func (d *HypervPS4Driver) PreserveLegacyExportBehaviour(srcPath string, dstPath return hyperv.PreserveLegacyExportBehaviour(srcPath, dstPath) } +func (d *HypervPS4Driver) MoveCreatedVHDsToOutputDir(srcPath string, dstPath string) error { + // Not implemented yet + err := fmt.Errorf("Not implemented yet") + return err +} + func (d *HypervPS4Driver) CompactDisks(path string) (result string, err error) { return hyperv.CompactDisks(path) } diff --git a/builder/hyperv/common/step_collate_artifacts.go b/builder/hyperv/common/step_collate_artifacts.go index 4f506218b..5942c73ba 100644 --- a/builder/hyperv/common/step_collate_artifacts.go +++ b/builder/hyperv/common/step_collate_artifacts.go @@ -22,11 +22,20 @@ func (s *StepCollateArtifacts) Run(_ context.Context, state multistep.StateBag) ui.Say("Collating build artifacts...") if s.SkipExport { + // Get the path to the main build directory from the statebag + var packerTempDir string + if v, ok := state.GetOk("packerTempDir"); ok { + packerTempDir = v.(string) + } // If the user has chosen to skip a full export of the VM the only // artifacts that they are interested in will be the VHDs - - // TODO: Grab the disks from the build directory and place them in - // a folder named 'Virtual Hard Disks' under the output directory + err := driver.MoveCreatedVHDsToOutputDir(packerTempDir, s.OutputDir) + if err != nil { + err = fmt.Errorf("Error moving VHDs from build dir to output dir: %s", err) + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } } else { // Get the full path to the export directory from the statebag var exportPath string