From ba06b00e70d1c705835ea4894ec101e19f18b11b Mon Sep 17 00:00:00 2001 From: Michael Kuzmin Date: Tue, 27 Feb 2018 03:22:52 +0300 Subject: [PATCH] Add 'usb_controller' option --- driver/vm.go | 27 ++++++++++++++++++--------- iso/step_create.go | 18 ++++++++++-------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/driver/vm.go b/driver/vm.go index 118bdfb77..9668c1a2b 100644 --- a/driver/vm.go +++ b/driver/vm.go @@ -41,15 +41,16 @@ type CreateConfig struct { DiskThinProvisioned bool DiskControllerType string // example: "scsi", "pvscsi" - Annotation string - Name string - Folder string - Host string - ResourcePool string - Datastore string - GuestOS string // example: otherGuest - Network string // "" for default network - NetworkCard string // example: vmxnet3 + Annotation string + Name string + Folder string + Host string + ResourcePool string + Datastore string + GuestOS string // example: otherGuest + Network string // "" for default network + NetworkCard string // example: vmxnet3 + USBController bool } func (d *Driver) NewVM(ref *types.ManagedObjectReference) *VirtualMachine { @@ -108,6 +109,14 @@ func (d *Driver) CreateVM(config *CreateConfig) (*VirtualMachine, error) { return nil, err } + if config.USBController { + t := true + usb := &types.VirtualUSBController{ + EhciEnabled: &t, + } + devices = append(devices, usb) + } + createSpec.DeviceChange, err = devices.ConfigSpec(types.VirtualDeviceConfigSpecOperationAdd) if err != nil { return nil, err diff --git a/iso/step_create.go b/iso/step_create.go index 91c7a5b26..1bbd3b6f1 100644 --- a/iso/step_create.go +++ b/iso/step_create.go @@ -14,14 +14,15 @@ type CreateConfig struct { DiskThinProvisioned bool `mapstructure:"disk_thin_provisioned"` DiskControllerType string `mapstructure:"disk_controller_type"` - VMName string `mapstructure:"vm_name"` - Folder string `mapstructure:"folder"` - Host string `mapstructure:"host"` - ResourcePool string `mapstructure:"resource_pool"` - Datastore string `mapstructure:"datastore"` - GuestOSType string `mapstructure:"guest_os_type"` - Network string `mapstructure:"network"` - NetworkCard string `mapstructure:"network_card"` + VMName string `mapstructure:"vm_name"` + Folder string `mapstructure:"folder"` + Host string `mapstructure:"host"` + ResourcePool string `mapstructure:"resource_pool"` + Datastore string `mapstructure:"datastore"` + GuestOSType string `mapstructure:"guest_os_type"` + Network string `mapstructure:"network"` + NetworkCard string `mapstructure:"network_card"` + USBController bool `mapstructure:"usb_controller"` } func (c *CreateConfig) Prepare() []error { @@ -79,6 +80,7 @@ func (s *StepCreateVM) Run(state multistep.StateBag) multistep.StepAction { GuestOS: s.Config.GuestOSType, Network: s.Config.Network, NetworkCard: s.Config.NetworkCard, + USBController: s.Config.USBController, }) if err != nil {