Quantcast
Channel: VMware Communities : Discussion List - VMware {code}
Viewing all articles
Browse latest Browse all 2738

Cannot use VmomiSupport.VmomiJSONEncoder on ComputeResource or ClusterComputeResource

$
0
0

Trying to use the VmomiJSONEncoder on ComputeResource or ClusterComputeResource objects. I have tried it two different ways but keep getting an InvalidProperty error from pyvmomi. Could you please point me in the right direction?

 

Code:

import atexit

import json

 

 

from pyVmomi import vim, VmomiSupport

from pyVim.connect import SmartConnectNoSSL, Disconnect

 

 

host = 'somehost'

user = 'someuser'

password = 'somepassword'

port = 443

 

 

v_session = SmartConnectNoSSL(host=host,user=user,pwd=password,port=port)

atexit.register(Disconnect, v_session)

 

 

content = v_session.RetrieveContent()

 

 

#1st WAY

container = content.rootFolder

viewType = [vim.ComputeResource] #this also does not work with vim.ClusterComputeResource

recursive = True

 

 

container_view = content.viewManager.CreateContainerView(container, viewType, recursive)

clusters = container_view.view

 

 

for cluster in clusters:

    #print(cluster)

    cluster_template = VmomiSupport.templateOf('ComputeResource')(cluster._moId, v_session._stub)

    obj_json = json.dumps(cluster_template, cls=VmomiSupport.VmomiJSONEncoder)

    print(obj_json)

 

 

container_view.Destroy()

 

 

 

 

#2ND WAY, this also does not work.

'''

children = content.rootFolder.childEntity

data = {}

for child in children:  # Iterate though DataCenters

    dc = child

    data[dc.name] = {}  # Add data Centers to data dict

    clusters = dc.hostFolder.childEntity

    for cluster in clusters:  # Iterate through the clusters

        #print(cluster)

        #print(vars(cluster))

        #cluster_template = VmomiSupport.templateOf('ClusterComputeResource')(cluster._moId, v_session._stub)

        cluster_template = VmomiSupport.templateOf('ComputeResource')(cluster._moId, v_session._stub)

        obj_json = json.dumps(cluster_template, cls=VmomiSupport.VmomiJSONEncoder)

        print(obj_json)

'''

 

 

 

Error:

Traceback (most recent call last):

  File ".\test-get-cluster-info.py", line 30, in <module>

    obj_json = json.dumps(cluster_template, cls=VmomiSupport.VmomiJSONEncoder)

  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1008.0_x64__qbz5n2kfra8p0\lib\json\__init__.py", line 234, in dumps

    return cls(

  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1008.0_x64__qbz5n2kfra8p0\lib\json\encoder.py", line 199, in encode

    chunks = self.iterencode(o, _one_shot=True)

  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1008.0_x64__qbz5n2kfra8p0\lib\json\encoder.py", line 257, in iterencode

    return _iterencode(o, 0)

  File "C:\Users\someuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pyVmomi\VmomiSupport.py", line 357, in default

    result[prop.name] = getattr(obj, prop.name)

  File "C:\Users\someuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pyVmomi\VmomiSupport.py", line 700, in __call__

    return self.f(*args, **kwargs)

  File "C:\Users\someuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pyVmomi\VmomiSupport.py", line 520, in _InvokeAccessor

    return self._stub.InvokeAccessor(self, info)

  File "C:\Users\someuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pyVmomi\StubAdapterAccessorImpl.py", line 41, in InvokeAccessor

    result = self._pc.RetrievePropertiesEx(specSet=[filterSpec],

  File "C:\Users\someuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pyVmomi\VmomiSupport.py", line 706, in <lambda>

    self.f(*(self.args + (obj,) + args), **kwargs)

  File "C:\Users\someuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pyVmomi\VmomiSupport.py", line 512, in _InvokeMethod

    return self._stub.InvokeMethod(self, info, args)

  File "C:\Users\someuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pyVmomi\SoapAdapter.py", line 1397, in InvokeMethod

    raise obj # pylint: disable-msg=E0702

pyVmomi.VmomiSupport.InvalidProperty: (vmodl.query.InvalidProperty) {

   dynamicType = <unset>,

   dynamicProperty = (vmodl.DynamicProperty) [],

   msg = '',

   faultCause = <unset>,

   faultMessage = (vmodl.LocalizableMessage) [],

   name = 'lifecycleManaged'

}

 

 

Thanks


Viewing all articles
Browse latest Browse all 2738

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>