Added options for chipset and firmware.
This commit is contained in:
parent
fca92b1953
commit
fa844543ec
|
@ -44,6 +44,14 @@ type Config struct {
|
||||||
vboxcommon.VBoxVersionConfig `mapstructure:",squash"`
|
vboxcommon.VBoxVersionConfig `mapstructure:",squash"`
|
||||||
vboxcommon.VBoxBundleConfig `mapstructure:",squash"`
|
vboxcommon.VBoxBundleConfig `mapstructure:",squash"`
|
||||||
vboxcommon.GuestAdditionsConfig `mapstructure:",squash"`
|
vboxcommon.GuestAdditionsConfig `mapstructure:",squash"`
|
||||||
|
// The chipset to be used: PIIX3 or ICH9.
|
||||||
|
// When set to piix3, the firmare is PIIX3. This is the default.
|
||||||
|
// When set to ich9, the firmare is ICH9.
|
||||||
|
Chipset string `mapstructure:"chipset" required:"false"`
|
||||||
|
// The firmware to be used: BIOS or EFI.
|
||||||
|
// When set to bios, the firmare is BIOS. This is the default.
|
||||||
|
// When set to efi, the firmare is EFI.
|
||||||
|
Firmware string `mapstructure:"firmware" required:"false"`
|
||||||
// The size, in megabytes, of the hard disk to create for the VM. By
|
// The size, in megabytes, of the hard disk to create for the VM. By
|
||||||
// default, this is 40000 (about 40 GB).
|
// default, this is 40000 (about 40 GB).
|
||||||
DiskSize uint `mapstructure:"disk_size" required:"false"`
|
DiskSize uint `mapstructure:"disk_size" required:"false"`
|
||||||
|
@ -162,6 +170,28 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
|
||||||
errs = packersdk.MultiErrorAppend(errs, b.config.BootConfig.Prepare(&b.config.ctx)...)
|
errs = packersdk.MultiErrorAppend(errs, b.config.BootConfig.Prepare(&b.config.ctx)...)
|
||||||
errs = packersdk.MultiErrorAppend(errs, b.config.GuestAdditionsConfig.Prepare(b.config.CommConfig.Comm.Type)...)
|
errs = packersdk.MultiErrorAppend(errs, b.config.GuestAdditionsConfig.Prepare(b.config.CommConfig.Comm.Type)...)
|
||||||
|
|
||||||
|
if b.config.Chipset == "" {
|
||||||
|
b.config.Chipset = "piix3"
|
||||||
|
}
|
||||||
|
switch b.config.Chipset {
|
||||||
|
case "piix3", "ich9":
|
||||||
|
// do nothing
|
||||||
|
default:
|
||||||
|
errs = packersdk.MultiErrorAppend(
|
||||||
|
errs, errors.New("chipset can only be piix3 or ich9"))
|
||||||
|
}
|
||||||
|
|
||||||
|
if b.config.Firmware == "" {
|
||||||
|
b.config.Firmware = "bios"
|
||||||
|
}
|
||||||
|
switch b.config.Firmware {
|
||||||
|
case "bios", "efi":
|
||||||
|
// do nothing
|
||||||
|
default:
|
||||||
|
errs = packersdk.MultiErrorAppend(
|
||||||
|
errs, errors.New("firmware can only be bios or efi"))
|
||||||
|
}
|
||||||
|
|
||||||
if b.config.DiskSize == 0 {
|
if b.config.DiskSize == 0 {
|
||||||
b.config.DiskSize = 40000
|
b.config.DiskSize = 40000
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,6 +117,8 @@ type FlatConfig struct {
|
||||||
GuestAdditionsPath *string `mapstructure:"guest_additions_path" cty:"guest_additions_path" hcl:"guest_additions_path"`
|
GuestAdditionsPath *string `mapstructure:"guest_additions_path" cty:"guest_additions_path" hcl:"guest_additions_path"`
|
||||||
GuestAdditionsSHA256 *string `mapstructure:"guest_additions_sha256" cty:"guest_additions_sha256" hcl:"guest_additions_sha256"`
|
GuestAdditionsSHA256 *string `mapstructure:"guest_additions_sha256" cty:"guest_additions_sha256" hcl:"guest_additions_sha256"`
|
||||||
GuestAdditionsURL *string `mapstructure:"guest_additions_url" required:"false" cty:"guest_additions_url" hcl:"guest_additions_url"`
|
GuestAdditionsURL *string `mapstructure:"guest_additions_url" required:"false" cty:"guest_additions_url" hcl:"guest_additions_url"`
|
||||||
|
Chipset *string `mapstructure:"chipset" required:"false" cty:"chipset" hcl:"chipset"`
|
||||||
|
Firmware *string `mapstructure:"firmware" required:"false" cty:"firmware" hcl:"firmware"`
|
||||||
DiskSize *uint `mapstructure:"disk_size" required:"false" cty:"disk_size" hcl:"disk_size"`
|
DiskSize *uint `mapstructure:"disk_size" required:"false" cty:"disk_size" hcl:"disk_size"`
|
||||||
GuestOSType *string `mapstructure:"guest_os_type" required:"false" cty:"guest_os_type" hcl:"guest_os_type"`
|
GuestOSType *string `mapstructure:"guest_os_type" required:"false" cty:"guest_os_type" hcl:"guest_os_type"`
|
||||||
HardDriveDiscard *bool `mapstructure:"hard_drive_discard" required:"false" cty:"hard_drive_discard" hcl:"hard_drive_discard"`
|
HardDriveDiscard *bool `mapstructure:"hard_drive_discard" required:"false" cty:"hard_drive_discard" hcl:"hard_drive_discard"`
|
||||||
|
@ -249,6 +251,8 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
|
||||||
"guest_additions_path": &hcldec.AttrSpec{Name: "guest_additions_path", Type: cty.String, Required: false},
|
"guest_additions_path": &hcldec.AttrSpec{Name: "guest_additions_path", Type: cty.String, Required: false},
|
||||||
"guest_additions_sha256": &hcldec.AttrSpec{Name: "guest_additions_sha256", Type: cty.String, Required: false},
|
"guest_additions_sha256": &hcldec.AttrSpec{Name: "guest_additions_sha256", Type: cty.String, Required: false},
|
||||||
"guest_additions_url": &hcldec.AttrSpec{Name: "guest_additions_url", Type: cty.String, Required: false},
|
"guest_additions_url": &hcldec.AttrSpec{Name: "guest_additions_url", Type: cty.String, Required: false},
|
||||||
|
"chipset": &hcldec.AttrSpec{Name: "chipset", Type: cty.String, Required: false},
|
||||||
|
"firmware": &hcldec.AttrSpec{Name: "firmware", Type: cty.String, Required: false},
|
||||||
"disk_size": &hcldec.AttrSpec{Name: "disk_size", Type: cty.Number, Required: false},
|
"disk_size": &hcldec.AttrSpec{Name: "disk_size", Type: cty.Number, Required: false},
|
||||||
"guest_os_type": &hcldec.AttrSpec{Name: "guest_os_type", Type: cty.String, Required: false},
|
"guest_os_type": &hcldec.AttrSpec{Name: "guest_os_type", Type: cty.String, Required: false},
|
||||||
"hard_drive_discard": &hcldec.AttrSpec{Name: "hard_drive_discard", Type: cty.Bool, Required: false},
|
"hard_drive_discard": &hcldec.AttrSpec{Name: "hard_drive_discard", Type: cty.Bool, Required: false},
|
||||||
|
|
|
@ -26,7 +26,7 @@ func (s *stepCreateVM) Run(ctx context.Context, state multistep.StateBag) multis
|
||||||
|
|
||||||
name := config.VMName
|
name := config.VMName
|
||||||
|
|
||||||
commands := make([][]string, 6)
|
commands := make([][]string, 8)
|
||||||
commands[0] = []string{
|
commands[0] = []string{
|
||||||
"createvm", "--name", name,
|
"createvm", "--name", name,
|
||||||
"--ostype", config.GuestOSType, "--register",
|
"--ostype", config.GuestOSType, "--register",
|
||||||
|
@ -45,6 +45,9 @@ func (s *stepCreateVM) Run(ctx context.Context, state multistep.StateBag) multis
|
||||||
commands[5] = []string{"modifyvm", name, "--audio", config.HWConfig.Sound, "--audioin", "on", "--audioout", "on"}
|
commands[5] = []string{"modifyvm", name, "--audio", config.HWConfig.Sound, "--audioin", "on", "--audioout", "on"}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
commands[6] = []string{"modifyvm", name, "--chipset", config.Chipset}
|
||||||
|
commands[7] = []string{"modifyvm", name, "--firmware", config.Firmware}
|
||||||
|
|
||||||
ui.Say("Creating virtual machine...")
|
ui.Say("Creating virtual machine...")
|
||||||
for _, command := range commands {
|
for _, command := range commands {
|
||||||
err := driver.VBoxManage(command...)
|
err := driver.VBoxManage(command...)
|
||||||
|
|
Loading…
Reference in New Issue