github.com/rothwerx/packer@v0.9.0/builder/qemu/step_resize_disk.go (about) 1 package qemu 2 3 import ( 4 "fmt" 5 "path/filepath" 6 7 "github.com/mitchellh/multistep" 8 "github.com/mitchellh/packer/packer" 9 ) 10 11 // This step resizes the virtual disk that will be used as the 12 // hard drive for the virtual machine. 13 type stepResizeDisk struct{} 14 15 func (s *stepResizeDisk) Run(state multistep.StateBag) multistep.StepAction { 16 config := state.Get("config").(*Config) 17 driver := state.Get("driver").(Driver) 18 ui := state.Get("ui").(packer.Ui) 19 path := filepath.Join(config.OutputDir, config.VMName) 20 21 command := []string{ 22 "resize", 23 path, 24 fmt.Sprintf("%vM", config.DiskSize), 25 } 26 27 if config.DiskImage == false { 28 return multistep.ActionContinue 29 } 30 31 ui.Say("Resizing hard drive...") 32 if err := driver.QemuImg(command...); err != nil { 33 err := fmt.Errorf("Error creating hard drive: %s", err) 34 state.Put("error", err) 35 ui.Error(err.Error()) 36 return multistep.ActionHalt 37 } 38 39 return multistep.ActionContinue 40 } 41 42 func (s *stepResizeDisk) Cleanup(state multistep.StateBag) {}