Understand vim in pyvmomi
<p>I would like to understand vim in pyvmomi.<br>
I understand that vim is imported like this: <code>from pyvmomi import vim</code><br>
I tried to find where vim is defined in pyvmomi, but I have not found it yet.   </p>

<p>I tried the following steps:</p>

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

<p></p>

<p>However, I did not get how vim is defined in LazyModule</p>

<p>I'd like to understand where the data objects listed in<br>
<a href="https://github.com/vmware/pyvmomi/tree/master/docs/vim" rel="nofollow">https://github.com/vmware/pyvmomi/tree/master/docs/vim</a>
are defined initially in pyVmomi. </p>

<p>For the most part those objects are found here: <a href="https://github.com/vmware/pyvmomi/blob/master/pyVmomi/ServerObjects.py" rel="nofollow">https://github.com/vmware/pyvmomi/blob/master/pyVmomi/ServerObjects.py</a> and 
<a href="https://github.com/vmware/pyvmomi/blob/master/pyVmomi/QueryTypes.py" rel="nofollow">https://github.com/vmware/pyvmomi/blob/master/pyVmomi/QueryTypes.py</a> and
<a href="https://github.com/vmware/pyvmomi/blob/master/pyVmomi/CoreTypes.py" rel="nofollow">https://github.com/vmware/pyvmomi/blob/master/pyVmomi/CoreTypes.py</a></p>

<p>Recently SMS support was added and those SMS objects are here: <a href="https://github.com/vmware/pyvmomi/blob/master/pyVmomi/SmsObjects.py" rel="nofollow">https://github.com/vmware/pyvmomi/blob/master/pyVmomi/SmsObjects.py</a></p>

<p>And SPBM objects are here: <a href="https://github.com/vmware/pyvmomi/blob/master/pyVmomi/PbmObjects.py" rel="nofollow">https://github.com/vmware/pyvmomi/blob/master/pyVmomi/PbmObjects.py</a></p>

<p>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: <a href="https://github.com/vmware/pyvmomi/blob/master/pyVmomi/VmomiSupport.py" rel="nofollow">https://github.com/vmware/pyvmomi/blob/master/pyVmomi/VmomiSupport.py</a></p>

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

<pre><code>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)])
</code></pre>

<p>Here the <code>CreateDataType</code> method is used which is imported from VmomiSupport. This method takes a few parameters: </p>

<ol>
<li>vmodlName (VMware Managed Object Design Language Name)</li>
<li>wsdlName (the WSDL name of the type)</li>
<li>parent (the VMODL name of the parent type. ie does it extend some other class)</li>
<li>version (the version of the type. this is not the vSphere version more the API version. these versions are found in the WSDL) </li>
<li>props (properties of the type)</li>
</ol>

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

<p>Next we have <code>AboutInfo</code> for the WSDL name. This is just the name of the object.</p>

<p>Next is the <code>vmodl.DynamicData</code>. This is the class that <code>AboutInfo</code> extends. See the SOAP documentation here: <a href="http://www.yavijava.com/docs/vim.AboutInfo.html" rel="nofollow">http://www.yavijava.com/docs/vim.AboutInfo.html</a> </p>

<p>Next up is the <code>vim.version.version1</code> for the version of the API supported. </p>

<p>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.</p>

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

<p>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 <code>vmodlName</code> which corresponds to the SOAP WSDL/Documentation (see in that link the <code>vim.AboutInfo.html</code>)</p>

python vim pyvmomi