From 40ec9efdfd96273115cff2f369c1bf416d03ebe4 Mon Sep 17 00:00:00 2001 From: Sean Malloy Date: Tue, 20 Mar 2018 04:09:36 -0500 Subject: [PATCH] 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 --- driver/vm.go | 4 ++++ iso/step_create.go | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/driver/vm.go b/driver/vm.go index 6f60bab67..cda16a314 100644 --- a/driver/vm.go +++ b/driver/vm.go @@ -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 } diff --git a/iso/step_create.go b/iso/step_create.go index 849779d77..0d0bbcf3a 100644 --- a/iso/step_create.go +++ b/iso/step_create.go @@ -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 {