github.com/daniellockard/packer@v0.7.6-0.20141210173435-5a9390934716/builder/qemu/step_resize_disk.go (about) 1 package qemu 2 3 import ( 4 "fmt" 5 "github.com/mitchellh/multistep" 6 "github.com/mitchellh/packer/packer" 7 "path/filepath" 8 "strings" 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, fmt.Sprintf("%s.%s", config.VMName, 20 strings.ToLower(config.Format))) 21 22 command := []string{ 23 "resize", 24 path, 25 fmt.Sprintf("%vM", config.DiskSize), 26 } 27 28 if config.DiskImage == false { 29 return multistep.ActionContinue 30 } 31 32 ui.Say("Resizing hard drive...") 33 if err := driver.QemuImg(command...); err != nil { 34 err := fmt.Errorf("Error creating hard drive: %s", err) 35 state.Put("error", err) 36 ui.Error(err.Error()) 37 return multistep.ActionHalt 38 } 39 40 return multistep.ActionContinue 41 } 42 43 func (s *stepResizeDisk) Cleanup(state multistep.StateBag) {}