github.com/rothwerx/packer@v0.9.0/builder/qemu/step_copy_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 copies the virtual disk that will be used as the 12 // hard drive for the virtual machine. 13 type stepCopyDisk struct{} 14 15 func (s *stepCopyDisk) Run(state multistep.StateBag) multistep.StepAction { 16 config := state.Get("config").(*Config) 17 driver := state.Get("driver").(Driver) 18 isoPath := state.Get("iso_path").(string) 19 ui := state.Get("ui").(packer.Ui) 20 path := filepath.Join(config.OutputDir, fmt.Sprintf("%s", config.VMName)) 21 name := config.VMName 22 23 command := []string{ 24 "convert", 25 "-f", config.Format, 26 "-O", config.Format, 27 isoPath, 28 path, 29 } 30 31 if config.DiskImage == false { 32 return multistep.ActionContinue 33 } 34 35 ui.Say("Copying hard drive...") 36 if err := driver.QemuImg(command...); err != nil { 37 err := fmt.Errorf("Error creating hard drive: %s", err) 38 state.Put("error", err) 39 ui.Error(err.Error()) 40 return multistep.ActionHalt 41 } 42 43 state.Put("disk_filename", name) 44 45 return multistep.ActionContinue 46 } 47 48 func (s *stepCopyDisk) Cleanup(state multistep.StateBag) {}