Added option for NIC type.

This commit is contained in:
Thomas Dreibholz 2021-02-20 19:59:39 +01:00
parent fa844543ec
commit eb4a6f30a0
No known key found for this signature in database
GPG Key ID: 5CD5D12AA0877B49
2 changed files with 31 additions and 1 deletions

View File

@ -55,6 +55,15 @@ type Config struct {
// The size, in megabytes, of the hard disk to create for the VM. By
// default, this is 40000 (about 40 GB).
DiskSize uint `mapstructure:"disk_size" required:"false"`
// The NIC type to be used for the network interfaces.
// When set to 82540EM, the NICs are Intel PRO/1000 MT Desktop (82540EM). This is the default.
// When set to 82543GC, the NICs are Intel PRO/1000 T Server (82543GC).
// When set to 82545EM, the NICs are Intel PRO/1000 MT Server (82545EM).
// When set to Am79C970A, the NICs are AMD PCNet-PCI II network card (Am79C970A).
// When set to Am79C973, the NICs are AMD PCNet-FAST III network card (Am79C973).
// When set to Am79C960, the NICs are AMD PCnet-ISA/NE2100 (Am79C960).
// When set to virtio, the NICs are VirtIO.
NICType string `mapstructure:"nic_type" required:"false"`
// The guest OS type being installed. By default this is other, but you can
// get dramatic performance improvements by setting this to the proper
// value. To view all available values for this run VBoxManage list
@ -200,6 +209,17 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
b.config.HardDriveInterface = "ide"
}
if b.config.NICType == "" {
b.config.NICType = "82540EM"
}
switch b.config.NICType {
case "82540EM", "82543GC", "82545EM", "Am79C970A", "Am79C973", "Am79C960", "virtio":
// do nothing
default:
errs = packersdk.MultiErrorAppend(
errs, errors.New("NIC type can only be 82540EM, 82543GC, 82545EM, Am79C970A, Am79C973, Am79C960 or virtio"))
}
if b.config.GuestOSType == "" {
b.config.GuestOSType = "Other"
}

View File

@ -26,7 +26,7 @@ func (s *stepCreateVM) Run(ctx context.Context, state multistep.StateBag) multis
name := config.VMName
commands := make([][]string, 8)
commands := make([][]string, 9)
commands[0] = []string{
"createvm", "--name", name,
"--ostype", config.GuestOSType, "--register",
@ -47,6 +47,16 @@ func (s *stepCreateVM) Run(ctx context.Context, state multistep.StateBag) multis
commands[6] = []string{"modifyvm", name, "--chipset", config.Chipset}
commands[7] = []string{"modifyvm", name, "--firmware", config.Firmware}
// Set the configured NIC type for all 8 possible NICs
commands[8] = []string{"modifyvm", name,
"--nictype1", config.NICType,
"--nictype2", config.NICType,
"--nictype3", config.NICType,
"--nictype4", config.NICType,
"--nictype5", config.NICType,
"--nictype6", config.NICType,
"--nictype7", config.NICType,
"--nictype8", config.NICType}
ui.Say("Creating virtual machine...")
for _, command := range commands {