Hi Everyone
I have been trying to add a vGPU using pyVmomi. I found a way of doing it in powershell from a blog which is as follows:
Param ($VM, $vGPUProfile)
$VM = Get-VM $VM
$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.VirtualPCIPassthrough
$spec.deviceChange[0].device.deviceInfo = New-Object VMware.Vim.Description
$spec.deviceChange[0].device.deviceInfo.summary = ''
$spec.deviceChange[0].device.deviceInfo.label = 'New PCI device'
$spec.deviceChange[0].device.backing = New-Object VMware.Vim.VirtualPCIPassthroughVmiopBackingInfo
$spec.deviceChange[0].device.backing.vgpu = "$vGPUProfile"
$vmobj = $VM | Get-View
$reconfig = $vmobj.ReconfigVM_Task($spec)
if ($reconfig) {
$ChangedVM = Get-VM $VM
$vGPUDevice = $ChangedVM.ExtensionData.Config.hardware.Device | Where { $_.backing.vgpu}
$vGPUDevice | Select Key, ControllerKey, Unitnumber, @{Name="Device";Expression={$_.DeviceInfo.Label}}, @{Name="Summary";Expression={$_.DeviceInfo.Summary}}
However, I need a pyVmomi equivalent. The problem I am facing it is pyVmomi is not recognizing VirtualPCIPassthroughVmiopBackingInfo class.
Any ideas?
FINALLY!! The answer. I had to use
from pyVim.connect import SmartConnect
instead of the legacy way by importing module 'Connect'
from pyVim.connect import Connect
Use SmartConnect and the code below should work
The powershell way I was referring to is available in the blog here:
http://www.virtu-al.net/2015/10/26/adding-a-vgpu-for-a-vsphere-6-0-vm-via-powercli/
I am able to model removing a vGPU in a python function that uses pyVmomi and it works just fine. However, adding a vGPU results in an error saying:
Incompatible device backing specified for device '0'
Here is my python implementation for adding a vGPU.
spec = vim.vm.ConfigSpec()
spec.deviceChange = [vim.VirtualDeviceConfigSpec()]
spec.deviceChange[0].operation = 'add'
spec.deviceChange[0].device = vim.VirtualPCIPassthrough()
spec.deviceChange[0].device.deviceInfo = vim.Description()
spec.deviceChange[0].device.deviceInfo.summary = 'NVIDIA GRID vGPU '+vgpuProfile
spec.deviceChange[0].device.deviceInfo.label = 'New PCI device'
# spec.deviceChange[0].device.backing = vim.vm.device.VirtualPCIPassthrough.VmiopBackingInfo()
spec.deviceChange[0].device.backing = vim.VirtualPCIPassthroughVmiopBackingInfo()
spec.deviceChange[0].device.backing.vgpu = str(vgpuProfile)
vmMor.ReconfigVM_Task(spec)
I supply vmMor(managed object reference for virtual machine) and vgpuProfile (string indicating profile name such as 'grid_m60-8q')
What am I missing?
FINALLY!! The answer. I had to use
from pyVim.connect import SmartConnect
instead of the legacy way by importing module 'Connect'
from pyVim.connect import Connect
Use SmartConnect and the code below should work