Search code examples
pythonvimpyvmomi

Understand vim in pyvmomi


I would like to understand vim in pyvmomi.
I understand that vim is imported like this: from pyvmomi import vim
I tried to find where vim is defined in pyvmomi, but I have not found it yet.

I tried the following steps:

>>> inspect.getfile(vim)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/inspect.py", line 420, in getfile
    'function, traceback, frame, or code object'.format(object
TypeError: <pyVmomi.VmomiSupport.LazyModule object at 0xb50690> is not a     module, class, method, function, traceback, frame, or code object
>>> globals()['vim']
<pyVmomi.VmomiSupport.LazyModule object at 0xb50690>
>>> locals()['vim']
<pyVmomi.VmomiSupport.LazyModule object at 0xb50690>
>>> vim

However, I did not get how vim is defined in LazyModule

I'd like to understand where the data objects listed in
https://github.com/vmware/pyvmomi/tree/master/docs/vim are defined initially in pyVmomi.


Solution

  • For the most part those objects are found here: https://github.com/vmware/pyvmomi/blob/master/pyVmomi/ServerObjects.py and https://github.com/vmware/pyvmomi/blob/master/pyVmomi/QueryTypes.py and https://github.com/vmware/pyvmomi/blob/master/pyVmomi/CoreTypes.py

    Recently SMS support was added and those SMS objects are here: https://github.com/vmware/pyvmomi/blob/master/pyVmomi/SmsObjects.py

    And SPBM objects are here: https://github.com/vmware/pyvmomi/blob/master/pyVmomi/PbmObjects.py

    These objects are dynamically created and the contents of this file should not be edited because it is auto-generated by VMWare with their internal build system. The objects are created using tools in VmomiSupport which is here: https://github.com/vmware/pyvmomi/blob/master/pyVmomi/VmomiSupport.py

    To expand further about where and how vim is defined lets look in ServerObjects.py:

    CreateDataType("vim.AboutInfo", "AboutInfo", "vmodl.DynamicData", "vim.version.version1", [("name", "string", "vim.version.version1", 0), ("fullName", "string", "vim.version.version1", 0), ("vendor", "string", "vim.version.version1", 0), ("version", "string", "vim.version.version1", 0), ("build", "string", "vim.version.version1", 0), ("localeVersion", "string", "vim.version.version1", F_OPTIONAL), ("localeBuild", "string", "vim.version.version1", F_OPTIONAL), ("osType", "string", "vim.version.version1", 0), ("productLineId", "string", "vim.version.version1", 0), ("apiType", "string", "vim.version.version1", 0), ("apiVersion", "string", "vim.version.version1", 0), ("instanceUuid", "string", "vim.version.version5", F_OPTIONAL), ("licenseProductName", "string", "vim.version.version5", F_OPTIONAL), ("licenseProductVersion", "string", "vim.version.version5", F_OPTIONAL)])
    

    Here the CreateDataType method is used which is imported from VmomiSupport. This method takes a few parameters:

    1. vmodlName (VMware Managed Object Design Language Name)
    2. wsdlName (the WSDL name of the type)
    3. parent (the VMODL name of the parent type. ie does it extend some other class)
    4. version (the version of the type. this is not the vSphere version more the API version. these versions are found in the WSDL)
    5. props (properties of the type)

    So far for our example we have vim.AboutInfo for the vmodlName. The vim part of this is just the namespace of the AboutInfo object.

    Next we have AboutInfo for the WSDL name. This is just the name of the object.

    Next is the vmodl.DynamicData. This is the class that AboutInfo extends. See the SOAP documentation here: http://www.yavijava.com/docs/vim.AboutInfo.html

    Next up is the vim.version.version1 for the version of the API supported.

    Finally is the props section. This is a list of tuples that describe the various properties of the object with their types and if they are optional or not. These can also but seen in the documentation link above where properties are defined for the object.

    The parser uses all of this information to dynamically build objects for you and to build your XML payloads that go to the server.

    So to answer what is vim and how is it defined: vim is just a namespace for the server side objects that vSphere knows about, and its defined in pyVmomi using the vmodlName which corresponds to the SOAP WSDL/Documentation (see in that link the vim.AboutInfo.html)