-
Notifications
You must be signed in to change notification settings - Fork 450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add usb controller #2280
base: main
Are you sure you want to change the base?
feat: add usb controller #2280
Conversation
1420065
to
2ca7685
Compare
2ca7685
to
647a6a0
Compare
Add the ability to add usb controller on build and modification of virtual machine. Signed-off-by: Jared Burns <jared.burns@broadcom.com>
647a6a0
to
6feba9c
Compare
@@ -283,6 +283,23 @@ func resourceVSphereVirtualMachine() *schema.Resource { | |||
Computed: true, | |||
Description: "The power state of the virtual machine.", | |||
}, | |||
"usb_controller": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the vSphere configuration maximums for v7 and v8m USB 1.x, 2.x, and 3.x is supported; however, only one USB host controller of each version 1.x, 2.x, or 3.x can be added at the same time.
Optional: true, | ||
Default: "2.0", | ||
Description: "The version of the USB controller.", | ||
ValidateFunc: validation.StringInSlice([]string{"2.0", "3.1"}, false), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like
var usbControllerVersions = []string{"2.0", "3.1"}
But account for the 1.x (more than one 1.x version?)
And then:
ValidateFunc: validation.StringInSlice(usbControllerVersions, false),
}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe:
},
},
ValidateFunc: validateUSBControllerVersions,
And add a function to ensure only one of each can be added. FOr example
func validateUSBControllerVersions(val interface{}, key string) (warns []string, errs []error) {
usbControllers := val.([]interface{})
versionCount := make(map[string]int)
for _, version := range usbControllerVersions {
versionCount[version] = 0
}
for _, controller := range usbControllers {
controllerMap := controller.(map[string]interface{})
version := controllerMap["usb_version"].(string)
if _, exists := versionCount[version]; exists {
versionCount[version]++
if versionCount[version] > 1 {
errs = append(errs, fmt.Errorf("%q cannot have more than one USB controller of version %s", key, version))
}
}
}
return
}
// Get USB Controller information | ||
var isUSBPresent bool | ||
for _, dev := range vprops.Config.Hardware.Device { | ||
if _, ok := dev.(*types.VirtualUSBController); ok { | ||
isUSBPresent = true | ||
break | ||
} | ||
} | ||
_ = d.Set("usb_controller", isUSBPresent) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something that would return more like this since more than one controller can be present but only one per version.
[
{
"usb_controller": true,
"usb_version": "2.0"
},
{
"usb_controller": false,
"usb_version": "3.1"
}
]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like this?
usbPresence := make(map[string]bool)
for _, version := range usbControllerVersions {
usbPresence[version] = false
}
for _, dev := range vprops.Config.Hardware.Device {
switch dev.(type) {
case *types.VirtualUSBController:
usbPresence["2.0"] = true
case *types.VirtualUSBXHCIController:
usbPresence["3.1"] = true
}
}
var usbControllers []map[string]interface{}
for version, present := range usbPresence {
usbControllers = append(usbControllers, map[string]interface{}{
"usb_controller": present,
"usb_version": version,
})
}
_ = d.Set("usb_controller", usbControllers)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if i can get a lab up i can test this, just not sure i want to chage it until i can test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some thoughts on supporting only a single USB controller for each supported version based on the configuration maximums in v7 and v8.
Description
Add the ability to add usb controller on build and modification of virtual machine.
Acceptance tests
Output from acceptance testing:
Release Note
Release note for CHANGELOG:
References
Closes #620