Files
Packer-Cn/builder/qemu/step_create_disk.go
T

56 lines
1.2 KiB
Go
Raw Normal View History

package qemu
import (
2018-01-22 15:32:33 -08:00
"context"
"fmt"
2015-05-17 17:35:39 +03:00
"path/filepath"
2018-01-19 16:18:44 -08:00
"github.com/hashicorp/packer/helper/multistep"
2017-04-04 13:39:01 -07:00
"github.com/hashicorp/packer/packer"
)
// This step creates the virtual disk that will be used as the
// hard drive for the virtual machine.
type stepCreateDisk struct{}
2018-01-22 15:31:41 -08:00
func (s *stepCreateDisk) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
2015-05-27 13:39:43 -07:00
config := state.Get("config").(*Config)
driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui)
2015-05-17 17:35:39 +03:00
name := config.VMName
2014-01-06 01:02:30 +00:00
path := filepath.Join(config.OutputDir, name)
command := []string{
"create",
"-f", config.Format,
}
if config.UseBackingFile {
isoPath := state.Get("iso_path").(string)
command = append(command, "-b", isoPath)
}
command = append(command,
path,
fmt.Sprintf("%vM", config.DiskSize),
)
if config.DiskImage && !config.UseBackingFile {
2014-10-28 08:43:19 -07:00
return multistep.ActionContinue
}
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-06 01:02:30 +00:00
state.Put("disk_filename", name)
return multistep.ActionContinue
}
func (s *stepCreateDisk) Cleanup(state multistep.StateBag) {}