github.com/rothwerx/packer@v0.9.0/builder/qemu/step_create_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 creates the virtual disk that will be used as the 12 // hard drive for the virtual machine. 13 type stepCreateDisk struct{} 14 15 func (s *stepCreateDisk) 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 name := config.VMName 20 path := filepath.Join(config.OutputDir, name) 21 22 command := []string{ 23 "create", 24 "-f", config.Format, 25 path, 26 fmt.Sprintf("%vM", config.DiskSize), 27 } 28 29 if config.DiskImage == true { 30 return multistep.ActionContinue 31 } 32 33 ui.Say("Creating hard drive...") 34 if err := driver.QemuImg(command...); err != nil { 35 err := fmt.Errorf("Error creating hard drive: %s", err) 36 state.Put("error", err) 37 ui.Error(err.Error()) 38 return multistep.ActionHalt 39 } 40 41 state.Put("disk_filename", name) 42 43 return multistep.ActionContinue 44 } 45 46 func (s *stepCreateDisk) Cleanup(state multistep.StateBag) {}