Add new config option to allow setting virtual machine hardware version (#65)

* Add new config option to allow setting virtual machine hardware version

The vsphere-iso builder gets a new configuration option named
vm_version. It allows setting the VMWare virtual machine hardware
version to a non-default value.

The default behavior remains unchanged. Use the latest supported
hardware version that ESXi/vCenter allows.

VMWare KB for supported virtual machine hardware versions.

https://kb.vmware.com/s/article/1003746

* Change vm_version from string to int
This commit is contained in:
Sean Malloy 2018-03-20 04:09:36 -05:00 committed by Michael Kuzmin
parent 9612ec5b5e
commit 40ec9efdfd
2 changed files with 10 additions and 0 deletions

View File

@ -53,6 +53,7 @@ type CreateConfig struct {
Network string // "" for default network
NetworkCard string // example: vmxnet3
USBController bool
Version int // example: 10
}
func (d *Driver) NewVM(ref *types.ManagedObjectReference) *VirtualMachine {
@ -396,6 +397,9 @@ func (config CreateConfig) toConfigSpec() types.VirtualMachineConfigSpec {
confSpec.Name = config.Name
confSpec.Annotation = config.Annotation
confSpec.GuestId = config.GuestOS
if config.Version != 0 {
confSpec.Version = fmt.Sprintf("%s%d", "vmx-", config.Version)
}
return confSpec
}

View File

@ -19,6 +19,7 @@ type CreateConfig struct {
Network string `mapstructure:"network"`
NetworkCard string `mapstructure:"network_card"`
USBController bool `mapstructure:"usb_controller"`
Version int `mapstructure:"vm_version"`
}
func (c *CreateConfig) Prepare() []error {
@ -31,6 +32,10 @@ func (c *CreateConfig) Prepare() []error {
errs = append(errs, tmp.VMConfig.Prepare()...)
errs = append(errs, tmp.HardwareConfig.Prepare()...)
if tmp.Version < 0 {
errs = append(errs, fmt.Errorf("'vm_version' cannot be a negative number"))
}
if len(errs) > 0 {
return errs
}
@ -71,6 +76,7 @@ func (s *StepCreateVM) Run(state multistep.StateBag) multistep.StepAction {
Network: s.Config.Network,
NetworkCard: s.Config.NetworkCard,
USBController: s.Config.USBController,
Version: s.Config.Version,
})
if err != nil {