github.com/sneal/packer@v0.5.2/builder/qemu/step_create_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 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 path := filepath.Join(config.OutputDir, fmt.Sprintf("%s.%s", config.VMName, 20 strings.ToLower(config.Format))) 21 22 command := []string{ 23 "create", 24 "-f", config.Format, 25 path, 26 fmt.Sprintf("%vM", config.DiskSize), 27 } 28 29 ui.Say("Creating hard drive...") 30 if err := driver.QemuImg(command...); err != nil { 31 err := fmt.Errorf("Error creating hard drive: %s", err) 32 state.Put("error", err) 33 ui.Error(err.Error()) 34 return multistep.ActionHalt 35 } 36 37 return multistep.ActionContinue 38 } 39 40 func (s *stepCreateDisk) Cleanup(state multistep.StateBag) {}