Pyvmomi supported types

2.1k views Asked by At

Background

I am trying to extract all of the information from vmware that I can via its API and pyvmomi.

I noticed from pyvmomi examples that this is how to get all of the vms on a vsphere instance:

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)

Now, I am hoping to loop through a list of all the extractable resources types (like vim.VirtualMachine, vim.ResourcePool, etc)

But, I cannot find this list.

Question: What is this list?

Is there some way to find this list from the pyvmomi module?

More info

I have used this link: https://vdc-download.vmware.com/vmwb-repository/dcr-public/6b586ed2-655c-49d9-9029-bc416323cb22/fa0b429a-a695-4c11-b7d2-2cbc284049dc/doc/index.html to find a list of all the managed objects on vmware, but many do not seem to be supported. And, I do not kn ow if this list contains every supported pyVmomi type. Only these resources:

ResourcePool
VirtualApp
Datacenter
VirtualMachine
Datastore
Network
ClusterComputeResource
OpaqueNetwork
HostSystem
DistributedVirtualPortgroup
ManagedEntity
ComputeResource
VmwareDistributedVirtualSwitch
StoragePod
Folder
DistributedVirtualSwitch

Do not error out on the container = code. For instance vim.Alarm is not supported in the RetrieveContent call but it does exist as part of vim.

The error is:

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

EDIT 1

from pyVmomi import vim
vim.Alarm
dir(vim) 
vim.VirtualMachine
dir(vim)

returns

['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) will not list any resource type unless I first know it and type vim.resourceTypeNameHere

But, even if it does show up in the list, the RetrieveContent() line still errors on some of the resourceTypes. For instance Alarm errors as can be seen above.

1

There are 1 answers

0
wangjin On

vim.VirtualMachine only a list ['vm01','vm02',...]

try this

def get_obj(content, vimtype, name=None):
    '''
    return list 
    '''
    container = content.viewManager.CreateContainerView(content.rootFolder, vimtype, True)
    obj = [ view for view in container.view]
    return obj

vm_objs = get_obj(content, [vim.VirtualMachine])
for vm in vm_objs:
    print(dir(vm))