背景
我试图通过vmware的API和pyvmomi从vmware中提取所有信息。
我从pyvmomi示例中注意到,这是如何在vSphere实例上获取所有vm的方法:
import yaml
from pyVmomi import vim
from pyVim.connect import SmartConnect, Disconnect, SmartConnectNoSSL
si = SmartConnectNoSSL(host=vserver, user=user, pwd=password, port=port)
container = si.RetrieveContent().viewManager.CreateContainerView(si.RetrieveContent().rootFolder, [vim.VirtualMachine], True)
现在,我希望遍历所有可提取资源类型的列表(例如vim.VirtualMachine,vim.ResourcePool等)
但是,我找不到此列表。
问题:该列表是什么?
是否可以通过pyvmomi模块找到此列表?
更多信息
我使用了以下链接:https://vdc-download.vmware.com/vmwb-repository/dcr-public/6b586ed2-655c-49d9-9029-bc416323cb22/fa0b429a-a695-4c11-b7d2-2cbc284049dc/doc/index.html来查找vmware上所有托管对象的列表,但是似乎不支持其中的许多对象。而且,如果此列表包含所有受支持的pyVmomi类型,我也不知道。只有这些资源:
ResourcePool
VirtualApp
Datacenter
VirtualMachine
Datastore
Network
ClusterComputeResource
OpaqueNetwork
HostSystem
DistributedVirtualPortgroup
ManagedEntity
ComputeResource
VmwareDistributedVirtualSwitch
StoragePod
Folder
DistributedVirtualSwitch
请勿在{{1}}代码上出错。例如container =
调用中不支持vim.Alarm,但它确实是vim的一部分。
错误是:
RetrieveContent
编辑1
container = si.RetrieveContent().viewManager.CreateContainerView(si.RetrieveContent().rootFolder, [vim.Alarm], True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/root/vmware-extract/vmware-extract-0.1.0/env/lib/python2.7/site-packages/pyVmomi/VmomiSupport.py", line 706, in <lambda>
self.f(*(self.args + (obj,) + args), **kwargs)
File "/root/vmware-extract/vmware-extract-0.1.0/env/lib/python2.7/site-packages/pyVmomi/VmomiSupport.py", line 512, in _InvokeMethod
return self._stub.InvokeMethod(self, info, args)
File "/root/vmware-extract/vmware-extract-0.1.0/env/lib/python2.7/site-packages/pyVmomi/SoapAdapter.py", line 1374, in InvokeMethod
raise obj # pylint: disable-msg=E0702
pyVmomi.VmomiSupport.InvalidArgument: (vmodl.fault.InvalidArgument) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
msg = 'A specified parameter was not correct: type',
faultCause = <unset>,
faultMessage = (vmodl.LocalizableMessage) [],
invalidProperty = u'type'
}
返回
from pyVmomi import vim
vim.Alarm
dir(vim)
vim.VirtualMachine
dir(vim)
['Alarm','__call__', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattr__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'fault', 'name']
['Alarm', 'VirtualMachine', '__call__', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattr__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'name']
不会列出任何资源类型,除非我先知道并输入vim.resourceTypeNameHere
但是,即使它确实显示在列表中,dir(vim)
行仍然在某些resourceTypes上出错。例如上面可以看到的警报错误。