github.com/rahart/packer@v0.12.2-0.20161229105310-282bb6ad370f/builder/parallels/common/step_compact_disk.go (about) 1 package common 2 3 import ( 4 "fmt" 5 6 "github.com/mitchellh/multistep" 7 "github.com/mitchellh/packer/packer" 8 ) 9 10 // StepCompactDisk is a step that removes all empty blocks from expanding 11 // Parallels virtual disks and reduces the result disk size 12 // 13 // Uses: 14 // driver Driver 15 // vmName string 16 // ui packer.Ui 17 // 18 // Produces: 19 // <nothing> 20 type StepCompactDisk struct { 21 Skip bool 22 } 23 24 // Run runs the compaction of the virtual disk attached to the VM. 25 func (s *StepCompactDisk) Run(state multistep.StateBag) multistep.StepAction { 26 driver := state.Get("driver").(Driver) 27 vmName := state.Get("vmName").(string) 28 ui := state.Get("ui").(packer.Ui) 29 30 if s.Skip { 31 ui.Say("Skipping disk compaction step...") 32 return multistep.ActionContinue 33 } 34 35 ui.Say("Compacting the disk image") 36 diskPath, err := driver.DiskPath(vmName) 37 if err != nil { 38 err = fmt.Errorf("Error detecting virtual disk path: %s", err) 39 state.Put("error", err) 40 ui.Error(err.Error()) 41 return multistep.ActionHalt 42 } 43 44 if err := driver.CompactDisk(diskPath); err != nil { 45 state.Put("error", fmt.Errorf("Error compacting disk: %s", err)) 46 ui.Error(err.Error()) 47 return multistep.ActionHalt 48 } 49 50 return multistep.ActionContinue 51 } 52 53 // Cleanup does nothing. 54 func (*StepCompactDisk) Cleanup(multistep.StateBag) {}