github.com/StackPointCloud/packer@v0.10.2-0.20180716202532-b28098e0f79b/builder/qemu/step_create_disk.go (about) 1 package qemu 2 3 import ( 4 "context" 5 "fmt" 6 "path/filepath" 7 8 "github.com/hashicorp/packer/helper/multistep" 9 "github.com/hashicorp/packer/packer" 10 ) 11 12 // This step creates the virtual disk that will be used as the 13 // hard drive for the virtual machine. 14 type stepCreateDisk struct{} 15 16 func (s *stepCreateDisk) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { 17 config := state.Get("config").(*Config) 18 driver := state.Get("driver").(Driver) 19 ui := state.Get("ui").(packer.Ui) 20 name := config.VMName 21 path := filepath.Join(config.OutputDir, name) 22 23 command := []string{ 24 "create", 25 "-f", config.Format, 26 path, 27 fmt.Sprintf("%vM", config.DiskSize), 28 } 29 30 if config.DiskImage == true { 31 return multistep.ActionContinue 32 } 33 34 ui.Say("Creating hard drive...") 35 if err := driver.QemuImg(command...); err != nil { 36 err := fmt.Errorf("Error creating hard drive: %s", err) 37 state.Put("error", err) 38 ui.Error(err.Error()) 39 return multistep.ActionHalt 40 } 41 42 state.Put("disk_filename", name) 43 44 return multistep.ActionContinue 45 } 46 47 func (s *stepCreateDisk) Cleanup(state multistep.StateBag) {}