github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/builder/qemu/step_copy_disk.go (about)

     1  package qemu
     2  
     3  import (
     4  	"fmt"
     5  	"path/filepath"
     6  
     7  	"github.com/hashicorp/packer/packer"
     8  	"github.com/mitchellh/multistep"
     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  		"-O", config.Format,
    26  		isoPath,
    27  		path,
    28  	}
    29  
    30  	if config.DiskImage == false {
    31  		return multistep.ActionContinue
    32  	}
    33  
    34  	ui.Say("Copying 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 *stepCopyDisk) Cleanup(state multistep.StateBag) {}