I'm using WMI to (attempt to) add a sythetic ethernet port to a Hyper-V VM. I'm getting the following error when I do so:
'testvm' failed to add device 'Microsoft Synthetic Ethernet Port'. (Virtual machine ID B4A091C9-D1AD-4AA9-960D-64E64F620959) The job has an error code of 32785, but I can find no mention of that error in the docs. I'm using the following code to add the NIC: <code> # open the connection to the hyper-v server wmiConn = wmi.WMI('hyperv_server', namespace='virtualization') # get the switch objects switchSvcs = wmiConn.Msvm_VirtualSwitchManagementService()[0] externalSwitch = wmiConn.query("SELECT * from Msvm_VirtualSwitch WHERE ElementName like 'my_switch'")[0] # create a new switch port nicUUID = str(uuid.uuid4()) (newPort, retVal) = switchSvcs.CreateSwitchPort(nicUUID, nicUUID, "", externalSwitch.path_()) # find the default switch syntheticNICs = wmiConn.Msvm_SyntheticEthernetPortSettingData() defaultNIC = [n for n in syntheticNICs if n.InstanceID.rfind('Default') > 0] # clone the default switch into a new object clazz = wmiConn.__getattr__('Msvm_SyntheticEthernetPortSettingData') newNIC = class.new() for prop in defaultNIC._properties: newNIC.Properties_.Item(prop).Value = defaultNIC.Properties_.Item(prop).Value # set data on the new NIC newNIC.Connection = [newPort] newNIC.ElementName = 'Fancy New VM NIC' newNIC.VirtualSystemIdentifiers = [str(uuid.uuid4())] # get the VM to which to add the NIC vm = wmiConn.Msvm_ComputerSystem(ElementName='My Cool VM')[0] # add the nic to the VM mgtSvcs = wmiConn.Msvm_VirtualSystemManagementService()[0] (jobPath, newResources, retVal) = mgtSvcs.AddVirtualSystemResources([newNIC.GetText_(1)], vm.path_()) # check to see if we've started the job... if retVal == 4096: # check the job status instanceID = jobPath.split('=')[1].strip('"') job = wmiConn.Msvm_ConcreteJob(InstanceID=instanceID)[0] while job.JobState == 4: time.sleep(0.1) job = wmiConn.Msvm_ConcreteJob(InstanceID=instanceID)[0] if job.JobState == 10: print '%d, %s', (job.ErrorCode, mgtSvcs.FormatError([job.GetError()[0]])) </code> _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32