VMware Cloud Community
ttierno2
Contributor
Contributor

vMotion Support

Hey everyone. Just wanted to first say that this forum has been invaluable in answering so many questions (Looking specifically at you LucD...), but I've run into one issue that despite all searching and reviewing here and through Google-Fu, I can't find an answer to....

I have utilized the instructions and snippets I've found here to successfully mount and passthrough a USB device to a VM....but there's an option in the vCenter GUI "Support vMotion while device is connected"....that I can't seem to select during the addition of it to the VM.

Here's my code snippet:

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

$spec.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec[] (1)

$spec.deviceChange[0] = New-Object VMware.Vim.VirtualDeviceConfigSpec

$spec.deviceChange[0].operation = "add"

$spec.deviceChange[0].device = New-Object VMware.Vim.VirtualUSB

$spec.deviceChange[0].device.key = -100

$spec.deviceChange[0].device.backing = New-Object VMware.Vim.VirtualUSBUSBBackingInfo

$spec.deviceChange[0].device.backing.deviceName = "pid:$devicePid vid:$deviceVid"

$spec.deviceChange[0].device.connectable = New-Object VMware.Vim.VirtualDeviceConnectInfo

$spec.deviceChange[0].device.connectable.startConnected = $true

$spec.deviceChange[0].device.connectable.allowGuestControl = $false

$spec.deviceChange[0].device.connectable.connected = $true

$spec.deviceChange[0].device.connected = $false

$vm = Get-View -Id "$vmid"

$result = $vm.ReconfigVM($spec)

I imagine it looks very similar/familiar to code found here, so I definitely don't take credit or claim to be an expert. I'm just looking for a little help with the vMotion option. It's obviously missing some variables and I add a USB controller before hand, but this is where I add the device.

I found this property while searching: VirtualUSBRemoteHostBackingOption which says "data objects contains options for remote host USB configuration. This backing options indicates support for persistent USB connections when vMotion operations migrate virtual machines to different hosts"

That SEEMS like exactly what I'm looking for, but I don't entirely know how to apply/use it in the scripting above.

Is there some upstanding individual that wants to help me out?? Smiley Happy

Thank you in advance!

Reply
0 Kudos
1 Reply
LucD
Leadership
Leadership

What backing object to use is described in the VirtualUSB object.

"To configure vMotion support for a virtual machine with a USB connection, use remote host backing for the USB connection (VirtualUSBRemoteHostBackingInfo)."

Instead of the VMware.Vim.VirtualUSBUSBBackingInfo object, use the VMware.Vim.VirtualUSBRemoteHostBackingInfo object.

This requires one extra property to define, the hostname.

Which, according to the API Reference should contain "... hostname must identify the local host on which the virtual machine is running."

Your code could look like this

$vm = Get-View -Id "$vmid"

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

$spec.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec[] (1)

$spec.deviceChange[0] = New-Object VMware.Vim.VirtualDeviceConfigSpec

$spec.deviceChange[0].operation = "add"

$spec.deviceChange[0].device = New-Object VMware.Vim.VirtualUSB

$spec.deviceChange[0].device.key = -100

$spec.deviceChange[0].device.backing = New-Object VMware.Vim.VirtualUSBRemoteClientBackingInfo

$spec.deviceChange[0].device.backing.deviceName = "pid:$devicePid vid:$deviceVid"

$spec.deviceChange[0].device.backing.hostname = (Get-View -Id $vm.Runtime.Host -Property Name).Name

$spec.deviceChange[0].device.connectable = New-Object VMware.Vim.VirtualDeviceConnectInfo

$spec.deviceChange[0].device.connectable.startConnected = $true

$spec.deviceChange[0].device.connectable.allowGuestControl = $false

$spec.deviceChange[0].device.connectable.connected = $true

$spec.deviceChange[0].device.connected = $false

$result = $vm.ReconfigVM($spec)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos