pyvmomi icon indicating copy to clipboard operation
pyvmomi copied to clipboard

PbmQueryAssociatedProfiles() fails if pbm.version.version11 is used

Open rmilkowski opened this issue 4 years ago • 0 comments

The following code:

    self._pbm_connect()
    profileManager = self.pbmSI.RetrieveContent().profileManager
    for vm in VMs:
        VMs_by_key[vm._moId]=vm
        pbmRef = pbm.ServerObjectRef(key=vm._moId,
                                     objectType=pbm.ServerObjectRef.ObjectType('virtualMachine'))
        pbmRefs.append(pbmRef)

    results = profileManager.PbmQueryAssociatedProfiles(entities=pbmRefs)
    print(results)

def _pbm_connect(self):
    if self.pbmSI is not None:
        return

    self._pyvmomi_connect()
    VmomiSupport.GetRequestContext()["vcSessionCookie"] = self.si._stub.cookie.split('"')[1]
    hostname = self.si._stub.host.split(":")[0]
    pbmStub = SoapStubAdapter(
        host=hostname,
        version="pbm.version.version11",
        path="/pbm/sdk",
        poolSize=0,
        sslContext=ssl._create_unverified_context())
    pbmServiceInstance = pbm.ServiceInstance("ServiceInstance", pbmStub)

    self.pbmSI = pbmServiceInstance

It fails with:

... results = profileManager.PbmQueryAssociatedProfiles(entities=pbmRefs) File "/var/tmp/hdb-tool_venv/lib64/python3.7/site-packages/pyVmomi/VmomiSupport.py", line 706, in self.f(*(self.args + (obj,) + args), **kwargs) File "/var/tmp/hdb-tool_venv/lib64/python3.7/site-packages/pyVmomi/VmomiSupport.py", line 512, in _InvokeMethod return self._stub.InvokeMethod(self, info, args) File "/var/tmp/hdb-tool_venv/lib64/python3.7/site-packages/pyVmomi/SoapAdapter.py", line 1388, in InvokeMethod raise exc File "/var/tmp/hdb-tool_venv/lib64/python3.7/site-packages/pyVmomi/SoapAdapter.py", line 1378, in InvokeMethod obj = deserializer.Deserialize(fd, info.result) File "/var/tmp/hdb-tool_venv/lib64/python3.7/site-packages/pyVmomi/SoapAdapter.py", line 845, in Deserialize ParseData(self.parser, response) File "/var/tmp/hdb-tool_venv/lib64/python3.7/site-packages/pyVmomi/SoapAdapter.py", line 525, in ParseData reraise(ParserError, pe, tb) File "/var/tmp/hdb-tool_venv/lib64/python3.7/site-packages/six.py", line 702, in reraise raise value.with_traceback(tb) File "/var/tmp/hdb-tool_venv/lib64/python3.7/site-packages/pyVmomi/SoapAdapter.py", line 514, in ParseData parser.ParseFile(data) File "/builddir/build/BUILD/Python-3.7.5/Modules/pyexpat.c", line 417, in StartElement File "/var/tmp/hdb-tool_venv/lib64/python3.7/site-packages/pyVmomi/SoapAdapter.py", line 692, in StartElementHandler dynType = self.LookupWsdlType(ns, name, allowManagedObjectReference=True) File "/var/tmp/hdb-tool_venv/lib64/python3.7/site-packages/pyVmomi/SoapAdapter.py", line 657, in LookupWsdlType return GuessWsdlType(name) File "/var/tmp/hdb-tool_venv/lib64/python3.7/site-packages/pyVmomi/VmomiSupport.py", line 1192, in GuessWsdlType raise UnknownWsdlTypeError(name) pyVmomi.SoapAdapter.ParserError: 'xml document: <http.client.HTTPResponse object at 0x7ff02fc73710> parse error at: line:1, col:420'

However, if in _pbm_connect() I change the version string to "pbm.version.version11" then it works and returns a result:

(pbm.profile.QueryProfileResult) { dynamicType = , dynamicProperty = (vmodl.DynamicProperty) [], object = (pbm.ServerObjectRef) { dynamicType = , dynamicProperty = (vmodl.DynamicProperty) [], objectType = 'virtualMachine', key = 'vm-1009', serverUuid = 'ae90771a-6504-4090-b241-0c1d7543cad3' }, profileId = (pbm.profile.ProfileId) [ (pbm.profile.ProfileId) { dynamicType = , dynamicProperty = (vmodl.DynamicProperty) [], uniqueId = '7c530cad-bf0c-4187-b77c-0f81b0b8f22c' } ], fault = }

But then version1 breaks some other calls which require version11. Do I need to obtain and use different pbm handle with different version used for different call? Or should the PbmQueryAssociatedProfiles() call work with version11?

rmilkowski avatar Jan 20 '21 10:01 rmilkowski