From da2df693013d1724d742e3dc3a92db9210504d1e Mon Sep 17 00:00:00 2001 From: DanHam Date: Sat, 7 Jul 2018 12:27:09 +0100 Subject: [PATCH] Remove disk compaction from the export step --- builder/hyperv/common/step_export_vm.go | 42 ++++++------------------- builder/hyperv/iso/builder.go | 5 ++- builder/hyperv/vmcx/builder.go | 5 ++- 3 files changed, 13 insertions(+), 39 deletions(-) diff --git a/builder/hyperv/common/step_export_vm.go b/builder/hyperv/common/step_export_vm.go index dfed94bf7..89aee37f0 100644 --- a/builder/hyperv/common/step_export_vm.go +++ b/builder/hyperv/common/step_export_vm.go @@ -10,51 +10,27 @@ import ( ) type StepExportVm struct { - OutputDir string - SkipCompaction bool - SkipExport bool + OutputDir string + SkipExport bool } func (s *StepExportVm) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { driver := state.Get("driver").(Driver) ui := state.Get("ui").(packer.Ui) - // Get the VM name; Get the temp directory used to store the VMs files - // during the build process - var vmName, tmpPath string - if v, ok := state.GetOk("vmName"); ok { - vmName = v.(string) - } - if v, ok := state.GetOk("packerTempDir"); ok { - tmpPath = v.(string) - } - - // Compact disks first so the export process has less to do - if s.SkipCompaction { - ui.Say("Skipping disk compaction...") - } else { - ui.Say("Compacting disks...") - // CompactDisks searches for all VHD/VHDX files under the supplied - // path and runs the compacting process on each of them. If no disks - // are found under the supplied path this is treated as a 'soft' error - // and a warning message is printed. All other errors halt the build. - result, err := driver.CompactDisks(tmpPath) - if err != nil { - err := fmt.Errorf("Error compacting disks: %s", err) - state.Put("error", err) - ui.Error(err.Error()) - return multistep.ActionHalt - } - // Report disk compaction results/warn if no disks were found - ui.Message(result) - } - if s.SkipExport { ui.Say("Skipping export of virtual machine...") return multistep.ActionContinue } ui.Say("Exporting virtual machine...") + + // The VM name is needed for the export command + var vmName string + if v, ok := state.GetOk("vmName"); ok { + vmName = v.(string) + } + // The export process exports the VM to a folder named 'vmName' under // the output directory. This contains the usual 'Snapshots', 'Virtual // Hard Disks' and 'Virtual Machines' directories. diff --git a/builder/hyperv/iso/builder.go b/builder/hyperv/iso/builder.go index d50e5e26a..d01dd27d6 100644 --- a/builder/hyperv/iso/builder.go +++ b/builder/hyperv/iso/builder.go @@ -467,9 +467,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe Generation: b.config.Generation, }, &hypervcommon.StepExportVm{ - OutputDir: b.config.OutputDir, - SkipCompaction: b.config.SkipCompaction, - SkipExport: b.config.SkipExport, + OutputDir: b.config.OutputDir, + SkipExport: b.config.SkipExport, }, // the clean up actions for each step will be executed reverse order diff --git a/builder/hyperv/vmcx/builder.go b/builder/hyperv/vmcx/builder.go index 987c41a12..7e7bc748a 100644 --- a/builder/hyperv/vmcx/builder.go +++ b/builder/hyperv/vmcx/builder.go @@ -476,9 +476,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe Generation: b.config.Generation, }, &hypervcommon.StepExportVm{ - OutputDir: b.config.OutputDir, - SkipCompaction: b.config.SkipCompaction, - SkipExport: b.config.SkipExport, + OutputDir: b.config.OutputDir, + SkipExport: b.config.SkipExport, }, // the clean up actions for each step will be executed reverse order