Pyvmomi支持的类型

2024-04-19 09:57:41 发布

您现在位置:Python中文网/ 问答频道 /正文

背景

Pyomi正在尝试从VMI的API中提取所有信息。在

我从pyvmomi示例中注意到,这是如何在vsphere实例上获取所有虚拟机的方法:

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)

现在,我希望遍历所有可提取资源类型的列表(比如虚拟机, 维姆资源池等)

但是,我找不到这个单子。在

问题:这个列表是什么?在

有什么方法可以从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类型。只有这些资源:

^{pr2}$

不要在container =代码中出错。例如振动警报器在RetrieveContent调用中不支持,但它确实作为vim的一部分存在。在

错误是:

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'
}

编辑1

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']

dir(vim)不会列出任何资源类型,除非我首先知道它和类型这里是vim.resourceTypeName在

但是,即使它确实出现在列表中,RetrieveContent()行仍然在某些resourceType上出错。例如,上面可以看到的警报错误。在


Tags: infromimportselfreduce列表lineextract