Cannot use VmomiSupport.VmomiJSONEncoder on ComputeResource or ClusterComputeResource.
Open
Nobody has claimed this yet.
needs verification
- Dominant language
- Python
- Stars
- 2.3k
- Forks
- 763
- PR merge metrics
- No merged PRs in 30d
Description
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?
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied reproducer and read VmomiSupport.VmomiJSONEncoder, templateOf, and the ComputeResource or ClusterComputeResource property access involved in the lifecycleManaged InvalidProperty error. Trace why encoding requests that property, then verify that serializing these objects completes without the reported exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100