2013-09-02 23:23:52 -04:00
|
|
|
package qemu
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-05-17 10:35:39 -04:00
|
|
|
"path/filepath"
|
|
|
|
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2013-09-02 23:23:52 -04:00
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
)
|
|
|
|
|
|
|
|
// This step creates the virtual disk that will be used as the
|
|
|
|
// hard drive for the virtual machine.
|
|
|
|
type stepCreateDisk struct{}
|
|
|
|
|
|
|
|
func (s *stepCreateDisk) Run(state multistep.StateBag) multistep.StepAction {
|
2015-05-27 16:39:43 -04:00
|
|
|
config := state.Get("config").(*Config)
|
2013-09-02 23:23:52 -04:00
|
|
|
driver := state.Get("driver").(Driver)
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
2015-05-17 10:35:39 -04:00
|
|
|
name := config.VMName
|
2014-01-05 20:02:30 -05:00
|
|
|
path := filepath.Join(config.OutputDir, name)
|
2013-09-02 23:23:52 -04:00
|
|
|
|
|
|
|
command := []string{
|
|
|
|
"create",
|
|
|
|
"-f", config.Format,
|
|
|
|
path,
|
|
|
|
fmt.Sprintf("%vM", config.DiskSize),
|
|
|
|
}
|
|
|
|
|
2014-10-28 11:43:19 -04:00
|
|
|
if config.DiskImage == true {
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
2014-07-17 10:01:19 -04:00
|
|
|
|
2013-09-02 23:23:52 -04:00
|
|
|
ui.Say("Creating hard drive...")
|
|
|
|
if err := driver.QemuImg(command...); err != nil {
|
|
|
|
err := fmt.Errorf("Error creating hard drive: %s", err)
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2014-01-05 20:02:30 -05:00
|
|
|
state.Put("disk_filename", name)
|
|
|
|
|
2013-09-02 23:23:52 -04:00
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stepCreateDisk) Cleanup(state multistep.StateBag) {}
|