<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://performiq.com/kb/index.php?action=history&amp;feed=atom&amp;title=ZSI_-_VMware_Interface</id>
	<title>ZSI - VMware Interface - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://performiq.com/kb/index.php?action=history&amp;feed=atom&amp;title=ZSI_-_VMware_Interface"/>
	<link rel="alternate" type="text/html" href="https://performiq.com/kb/index.php?title=ZSI_-_VMware_Interface&amp;action=history"/>
	<updated>2026-05-18T12:45:31Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.37.1</generator>
	<entry>
		<id>https://performiq.com/kb/index.php?title=ZSI_-_VMware_Interface&amp;diff=1734&amp;oldid=prev</id>
		<title>PeterHarding: ZSI - VMWare Interface moved to ZSI - VMware Interface: More conventional naming</title>
		<link rel="alternate" type="text/html" href="https://performiq.com/kb/index.php?title=ZSI_-_VMware_Interface&amp;diff=1734&amp;oldid=prev"/>
		<updated>2008-03-17T03:05:55Z</updated>

		<summary type="html">&lt;p&gt;&lt;a href=&quot;/kb/index.php/ZSI_-_VMWare_Interface&quot; class=&quot;mw-redirect&quot; title=&quot;ZSI - VMWare Interface&quot;&gt;ZSI - VMWare Interface&lt;/a&gt; moved to &lt;a href=&quot;/kb/index.php/ZSI_-_VMware_Interface&quot; title=&quot;ZSI - VMware Interface&quot;&gt;ZSI - VMware Interface&lt;/a&gt;: More conventional naming&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 13:05, 17 March 2008&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>PeterHarding</name></author>
	</entry>
	<entry>
		<id>https://performiq.com/kb/index.php?title=ZSI_-_VMware_Interface&amp;diff=1733&amp;oldid=prev</id>
		<title>PeterHarding at 03:05, 17 March 2008</title>
		<link rel="alternate" type="text/html" href="https://performiq.com/kb/index.php?title=ZSI_-_VMware_Interface&amp;diff=1733&amp;oldid=prev"/>
		<updated>2008-03-17T03:05:15Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 13:05, 17 March 2008&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l367&quot;&gt;Line 367:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 367:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Python]][[Category:ZSI]][[Category:&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;VMWare&lt;/del&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Python]][[Category:ZSI]][[Category:&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;VMware&lt;/ins&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>PeterHarding</name></author>
	</entry>
	<entry>
		<id>https://performiq.com/kb/index.php?title=ZSI_-_VMware_Interface&amp;diff=1714&amp;oldid=prev</id>
		<title>PeterHarding: New page: =Class for handling the SOAP interface for VMware Virtual Infrastructure 3=  &lt;pre&gt; &quot;&quot;&quot; File: VMwareVI-RetrieveProperty-Example.py Author: Werner Still  Class for handling the SOAP interfac...</title>
		<link rel="alternate" type="text/html" href="https://performiq.com/kb/index.php?title=ZSI_-_VMware_Interface&amp;diff=1714&amp;oldid=prev"/>
		<updated>2008-03-17T02:27:22Z</updated>

		<summary type="html">&lt;p&gt;New page: =Class for handling the SOAP interface for VMware Virtual Infrastructure 3=  &amp;lt;pre&amp;gt; &amp;quot;&amp;quot;&amp;quot; File: VMwareVI-RetrieveProperty-Example.py Author: Werner Still  Class for handling the SOAP interfac...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;=Class for handling the SOAP interface for VMware Virtual Infrastructure 3=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
File: VMwareVI-RetrieveProperty-Example.py&lt;br /&gt;
Author: Werner Still&lt;br /&gt;
&lt;br /&gt;
Class for handling the SOAP interface for VMware Virtual Infrastructure 3&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
__svnid__ = &amp;#039;$Id: $&amp;#039;&lt;br /&gt;
__copy__ = \&lt;br /&gt;
  &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  Copyright (c) 2007 Hitachi Data Systems GmbH.&lt;br /&gt;
  All rights reserved.&lt;br /&gt;
  &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
# Produce the VimServices_services.py and VimServices_services_types.py with&lt;br /&gt;
#     wsdl2py.exe -b -f vimService.wsdl&lt;br /&gt;
#     substitute in VimService_services_types.py&lt;br /&gt;
#       GTD(&amp;quot;urn:vim2&amp;quot;,&amp;quot;HostSystemResourceInfo&amp;quot;,lazy=False)(pname=(ns,&amp;quot;child&amp;quot;),&lt;br /&gt;
#     with&lt;br /&gt;
#       GTD(&amp;quot;urn:vim2&amp;quot;,&amp;quot;HostSystemResourceInfo&amp;quot;,lazy=True)(pname=(ns,&amp;quot;child&amp;quot;),&lt;br /&gt;
#   or&lt;br /&gt;
#     wsdl2py.exe -l -b -f vimService.wsdl&lt;br /&gt;
&lt;br /&gt;
# If it is necessary to run a second RetrieveProperties there shows a bug in the ZSI 2.0 implmentation.&lt;br /&gt;
# With the second run the following Error Message appears:&lt;br /&gt;
#   Error retrieving Properties&lt;br /&gt;
#   Error content VMwareVI NonVI Error in VMwareVI.RetrieveProperties &amp;#039;list&amp;#039; object has no attribute &amp;#039;__dict__&amp;#039;&lt;br /&gt;
# This comes due to the fact that the sequencer in ZSI has a special handling for derived wsdl Messages.&lt;br /&gt;
# Here we use ns0.TraversalSpec_Def().pyclass() which is a derived Message from ns0.SelectionSpec_Def().pyclass()&lt;br /&gt;
# If this happens the minOccurs and maxOccures is set to 1. Badly enougth this runs on the orginal classes. Out&lt;br /&gt;
# of this a further creation of an class instance gets the modified values for minOccurs and maxOccurs. With this&lt;br /&gt;
# values other parts of the sequencer code will be called and this leads to the error message.&lt;br /&gt;
#&lt;br /&gt;
# A special hook within ZSI 2.0 is necessary to run with this package:&lt;br /&gt;
#  in TCcompound.py:_get_type_or_substitute the setting of&lt;br /&gt;
#     sub.minOccurs=1&lt;br /&gt;
#     sub.maxOccurs=1&lt;br /&gt;
#  has to be modified to be at least only&lt;br /&gt;
#     sub.minOccurs = typecode.minOccurs&lt;br /&gt;
#     sub.maxOccurs = typecode.maxOccurs&lt;br /&gt;
#&lt;br /&gt;
#  Within ZSI 2.1_a1 there is a small change within TCcompound.py to copy the sub before&lt;br /&gt;
#  modifying the Elements. The code is modified:&lt;br /&gt;
#    from copy import copy as _copy&lt;br /&gt;
#&lt;br /&gt;
#    sub = _copy(sub)&lt;br /&gt;
#    sub.nspname = typecode.nspname&lt;br /&gt;
#    sub.pname = typecode.pname&lt;br /&gt;
#    sub.aname = typecode.aname&lt;br /&gt;
#    sub.minOccurs = sub.maxOccurs = 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
import sys&lt;br /&gt;
import logging&lt;br /&gt;
from VimService_services import *&lt;br /&gt;
from optparse import OptionParser&lt;br /&gt;
&lt;br /&gt;
class VMwareVI_Error(Exception):&lt;br /&gt;
  &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  Exception VMwareVI_Error&lt;br /&gt;
&lt;br /&gt;
  This exception is used in VMwareVI Errors&lt;br /&gt;
  &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  def __init__(self, methodName):&lt;br /&gt;
    Exception.__init__(self)&lt;br /&gt;
    self.__methodName = methodName&lt;br /&gt;
&lt;br /&gt;
  def __str__(self):&lt;br /&gt;
    return &amp;quot;VMwareVI Error in &amp;quot; + str(self.__methodName)&lt;br /&gt;
class VMwareVI_NonViError(Exception):&lt;br /&gt;
  &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  Exception VMwareVI Error not issued by Vi&lt;br /&gt;
  &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  def __init__(self, methodName):&lt;br /&gt;
    Exception.__init__(self)&lt;br /&gt;
    self.__methodName = methodName&lt;br /&gt;
&lt;br /&gt;
  def __str__(self):&lt;br /&gt;
    return &amp;quot;VMwareVI NonVI Error in &amp;quot; + str(self.__methodName)&lt;br /&gt;
&lt;br /&gt;
class VMwareVI:&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    This class is the main entry point into VMware VI SOAP&lt;br /&gt;
    The creator connects to the VMware ESX or Virtual Center&lt;br /&gt;
    All other Members use this connection&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    ServiceContent = None&lt;br /&gt;
    PropertyCollector = None&lt;br /&gt;
    rootFolder = None&lt;br /&gt;
    proxy = None&lt;br /&gt;
    indent = 0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def __init__(self, Host=None, UserName=None, Password=None, Trace=None):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        Create the necessary Communication interfaces, get the ServiceInstance and log on&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        Location = &amp;quot;en&amp;quot;&lt;br /&gt;
        try:&lt;br /&gt;
            loc = VimServiceLocator()&lt;br /&gt;
             # Check if the Host Variable starts with the protocol. If not add https&lt;br /&gt;
            if Host == None:&lt;br /&gt;
                ConnectString = Host&lt;br /&gt;
            elif Host.startswith(&amp;#039;https://&amp;#039;) or Host.startswith(&amp;#039;http://&amp;#039;):&lt;br /&gt;
                ConnectString = Host&lt;br /&gt;
            else:&lt;br /&gt;
                ConnectString = &amp;quot;https://%s/sdk&amp;quot; % (Host)&lt;br /&gt;
            if Trace == None:&lt;br /&gt;
                self.proxy = loc.getVimPortType(url = ConnectString)&lt;br /&gt;
            else:&lt;br /&gt;
                self.proxy = loc.getVimPortType(url = ConnectString, tracefile = Trace)&lt;br /&gt;
&lt;br /&gt;
            # RetrieveServiceContent&lt;br /&gt;
            RetrieveServiceContentRequest = RetrieveServiceContentRequestMsg()&lt;br /&gt;
            # Now create the content of the RetreiveServiceContent Request. This is a ManagedObjectReference&lt;br /&gt;
            # The Parameter is the Instance that is needed. In this case a ServiceInstance&lt;br /&gt;
            Element = RetrieveServiceContentRequest.new__this(&amp;quot;ServiceInstance&amp;quot;)&lt;br /&gt;
            # The ManagedObjectReference needs to tell the VMware VI what type it requests. This works with&lt;br /&gt;
            # the attribute type. Here for RetreiveServiceContent it is a type ServiceInstance.&lt;br /&gt;
            Element.set_attribute_type(&amp;quot;ServiceInstance&amp;quot;)&lt;br /&gt;
            RetrieveServiceContentRequest.set_element__this(Element)&lt;br /&gt;
            self.ServiceContent = self.proxy.RetrieveServiceContent(RetrieveServiceContentRequest)._returnval&lt;br /&gt;
            logging.debug(&amp;quot;RetrieveServiceContent: response.About.FullName = %s&amp;quot; % (self.ServiceContent.About.FullName))&lt;br /&gt;
            logging.debug(&amp;quot;RetrieveServiceContent: response.SessionManager = %s&amp;quot; % (self.ServiceContent.SessionManager))&lt;br /&gt;
            sessionManager = str(self.ServiceContent.SessionManager)&lt;br /&gt;
            self.PropertyCollector = str(self.ServiceContent.PropertyCollector)&lt;br /&gt;
            self.rootFolder = self.ServiceContent.RootFolder&lt;br /&gt;
            RetrieveServiceContentRequest = None&lt;br /&gt;
        except (ns0.RuntimeFault_Def), e:&lt;br /&gt;
            #raise(VMwareVI_Error(&amp;quot;VMwareVI.__init__ %s: %s&amp;quot; % (e, e.value)))&lt;br /&gt;
            raise(VMwareVI_Error(&amp;quot;VMwareVI.__init__ %s&amp;quot; % (e)))&lt;br /&gt;
        except Exception, e:&lt;br /&gt;
            raise(VMwareVI_NonViError(&amp;quot;VMwareVI.__init__ %s&amp;quot; % (e)))&lt;br /&gt;
&lt;br /&gt;
        try:&lt;br /&gt;
            # Login&lt;br /&gt;
            LoginRequest = LoginRequestMsg()&lt;br /&gt;
            #LoginRequest._this = LoginRequest.new__this(sessionManager)&lt;br /&gt;
            #LoginRequest._this.set_attribute_type(&amp;quot;SessionManager&amp;quot;)&lt;br /&gt;
            This = LoginRequest.new__this(sessionManager)&lt;br /&gt;
            This.set_attribute_type(&amp;quot;SessionManager&amp;quot;)&lt;br /&gt;
            LoginRequest.set_element__this(This)&lt;br /&gt;
            LoginRequest.set_element_userName(UserName)&lt;br /&gt;
            LoginRequest.set_element_password(Password)&lt;br /&gt;
            LoginRequest.set_element_locale(Location)&lt;br /&gt;
            LoginResponse = self.proxy.Login(LoginRequest)._returnval&lt;br /&gt;
            LoginRequest = None&lt;br /&gt;
            logging.debug(&amp;quot;Login: response.FullName = %s&amp;quot; % (LoginResponse.FullName))&lt;br /&gt;
            logging.debug(&amp;quot;Login: response.Key = %s&amp;quot; % (LoginResponse.Key))&lt;br /&gt;
            logging.debug(&amp;quot;Login: response.UserName = %s&amp;quot; % (LoginResponse.UserName))&lt;br /&gt;
            LoginResponse = None&lt;br /&gt;
        except (InvalidLoginFault, InvalidLocaleFault, RuntimeFault), e:&lt;br /&gt;
            raise(VMwareVI_Error(&amp;quot;VMwareVI.__init__ %s&amp;quot; % (e)))&lt;br /&gt;
        except Exception, e:&lt;br /&gt;
            raise(VMwareVI_NonViError(&amp;quot;VMwareVI.__init__ %s&amp;quot; % (e)))&lt;br /&gt;
&lt;br /&gt;
    def CurrentTime(self):&lt;br /&gt;
        # CurrentTime&lt;br /&gt;
        CurrentTimeRequest = CurrentTimeRequestMsg()&lt;br /&gt;
        This = CurrentTimeRequest.new__this(&amp;quot;ServiceInstance&amp;quot;)&lt;br /&gt;
        This.set_attribute_type(&amp;quot;ServiceInstance&amp;quot;)&lt;br /&gt;
        CurrentTimeRequest.set_element__this(This)&lt;br /&gt;
        CurrentTimeResponse = self.proxy.CurrentTime(CurrentTimeRequest)._returnval&lt;br /&gt;
        CurrentTimeResponseString = str(CurrentTimeResponse)&lt;br /&gt;
        logging.debug(&amp;quot;CurrentTime: %s&amp;quot; % (CurrentTimeResponseString))&lt;br /&gt;
        CurrentTimeRequest = None&lt;br /&gt;
        CurrentTimeResponse = None&lt;br /&gt;
        return CurrentTimeResponseString&lt;br /&gt;
&lt;br /&gt;
    # RetreiveProperties&lt;br /&gt;
    def RetrieveProperties(self, propSetType=None, objectSetObj=None, AllElements=False):&lt;br /&gt;
        try:&lt;br /&gt;
            PropertiesRequest = RetrievePropertiesRequestMsg()&lt;br /&gt;
            Element = PropertiesRequest.new__this(self.PropertyCollector)&lt;br /&gt;
            Element.set_attribute_type(&amp;quot;PropertyCollector&amp;quot;)&lt;br /&gt;
            PropertiesRequest.set_element__this(Element)&lt;br /&gt;
&lt;br /&gt;
            # We need the SpecSet Element here to get the other new() Functions&lt;br /&gt;
            SpecSet_PropertyFilterSpec = PropertiesRequest.new_specSet()&lt;br /&gt;
&lt;br /&gt;
            if (propSetType == None):&lt;br /&gt;
                propSetType = &amp;quot;ManagedEntity&amp;quot;&lt;br /&gt;
            PropSetArray = []&lt;br /&gt;
            PropSet = SpecSet_PropertyFilterSpec.new_propSet()&lt;br /&gt;
            PropSet.set_element_type(propSetType)&lt;br /&gt;
            PropSet.set_element_all(AllElements)&lt;br /&gt;
            PropSet.set_element_pathSet([&amp;quot;name&amp;quot;])&lt;br /&gt;
            PropSetArray.append(PropSet)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
            if objectSetObj == None:&lt;br /&gt;
                objectSetObj = self.rootFolder&lt;br /&gt;
            ObjectSetArray = []&lt;br /&gt;
            ObjectSet = SpecSet_PropertyFilterSpec.new_objectSet()&lt;br /&gt;
            ObjectSet.set_element_obj(objectSetObj)&lt;br /&gt;
            ObjectSet.set_element_skip(False)&lt;br /&gt;
            # Add the Traversal Part of the RetrieveProperties&lt;br /&gt;
            resourcePoolTraversal = ns0.TraversalSpec_Def(&amp;quot;resourcePoolTraversalSpec&amp;quot;).pyclass()&lt;br /&gt;
            resourcePoolTraversal.set_element_name(&amp;quot;resourcePoolTraversalSpec&amp;quot;)&lt;br /&gt;
            resourcePoolTraversal.set_element_type(&amp;quot;ResourcePool&amp;quot;)&lt;br /&gt;
            resourcePoolTraversal.set_element_path(&amp;quot;resourcePool&amp;quot;)&lt;br /&gt;
            resourcePoolTraversal.set_element_skip(False)&lt;br /&gt;
            SPCAresourcePool = []&lt;br /&gt;
            SPCAresourcePool.append(ObjectSet.new_selectSet())&lt;br /&gt;
            SPCAresourcePool[0].set_element_name(&amp;quot;resourcePoolTraversalSpec&amp;quot;)&lt;br /&gt;
            resourcePoolTraversal.set_element_selectSet(SPCAresourcePool)&lt;br /&gt;
&lt;br /&gt;
            computeResourceRpTraversal = ns0.TraversalSpec_Def(&amp;quot;computeResourceRpTraversalSpec&amp;quot;).pyclass()&lt;br /&gt;
            computeResourceRpTraversal.set_element_name(&amp;quot;computeResourceRpTraversalSpec&amp;quot;)&lt;br /&gt;
            computeResourceRpTraversal.set_element_type(&amp;quot;ComputeResource&amp;quot;)&lt;br /&gt;
            computeResourceRpTraversal.set_element_path(&amp;quot;resourcePool&amp;quot;)&lt;br /&gt;
            computeResourceRpTraversal.set_element_skip(False)&lt;br /&gt;
            SPCAcomputeResourceRp = []&lt;br /&gt;
            SPCAcomputeResourceRp.append(ObjectSet.new_selectSet())&lt;br /&gt;
            SPCAcomputeResourceRp[0].set_element_name(&amp;quot;computeResourceRpTraversalSpec&amp;quot;)&lt;br /&gt;
            computeResourceRpTraversal.set_element_selectSet(SPCAcomputeResourceRp)&lt;br /&gt;
&lt;br /&gt;
            computeResourceHostTraversal = ns0.TraversalSpec_Def(&amp;quot;computeResourceHostTraversalSpec&amp;quot;).pyclass()&lt;br /&gt;
            computeResourceHostTraversal.set_element_name(&amp;quot;computeResourceHostTraversalSpec&amp;quot;)&lt;br /&gt;
            computeResourceHostTraversal.set_element_type(&amp;quot;ComputeResource&amp;quot;)&lt;br /&gt;
            computeResourceHostTraversal.set_element_path(&amp;quot;host&amp;quot;)&lt;br /&gt;
            computeResourceHostTraversal.set_element_skip(False)&lt;br /&gt;
&lt;br /&gt;
            datacenterHostTraversal = ns0.TraversalSpec_Def(&amp;quot;datacenterHostTraversalSpec&amp;quot;).pyclass()&lt;br /&gt;
            datacenterHostTraversal.set_element_name(&amp;quot;datacenterHostTraversalSpec&amp;quot;)&lt;br /&gt;
            datacenterHostTraversal.set_element_type(&amp;quot;Datacenter&amp;quot;)&lt;br /&gt;
            datacenterHostTraversal.set_element_path(&amp;quot;hostFolder&amp;quot;)&lt;br /&gt;
            datacenterHostTraversal.set_element_skip(False)&lt;br /&gt;
            SPCAdatacenterHost = []&lt;br /&gt;
            SPCAdatacenterHost.append(ObjectSet.new_selectSet())&lt;br /&gt;
            SPCAdatacenterHost[0].set_element_name(&amp;quot;folderTraversalSpec&amp;quot;)&lt;br /&gt;
            datacenterHostTraversal.set_element_selectSet(SPCAdatacenterHost)&lt;br /&gt;
&lt;br /&gt;
            datacenterVmTraversal = ns0.TraversalSpec_Def(&amp;quot;datacenterVmTraversalSpec&amp;quot;).pyclass()&lt;br /&gt;
            datacenterVmTraversal.set_element_name(&amp;quot;datacenterVmTraversalSpec&amp;quot;)&lt;br /&gt;
            datacenterVmTraversal.set_element_type(&amp;quot;Datacenter&amp;quot;)&lt;br /&gt;
            datacenterVmTraversal.set_element_path(&amp;quot;hostFolder&amp;quot;)&lt;br /&gt;
            datacenterVmTraversal.set_element_skip(False)&lt;br /&gt;
            SPCAdatacenterVm = []&lt;br /&gt;
            SPCAdatacenterVm.append(ObjectSet.new_selectSet())&lt;br /&gt;
            SPCAdatacenterVm[0].set_element_name(&amp;quot;folderTraversalSpec&amp;quot;)&lt;br /&gt;
            datacenterVmTraversal.set_element_selectSet(SPCAdatacenterVm)&lt;br /&gt;
&lt;br /&gt;
            folderTraversal = ns0.TraversalSpec_Def(&amp;quot;resourcePoolTraversalSpec&amp;quot;).pyclass()&lt;br /&gt;
            folderTraversal.set_element_name(&amp;quot;folderTraversalSpec&amp;quot;)&lt;br /&gt;
            folderTraversal.set_element_type(&amp;quot;Folder&amp;quot;)&lt;br /&gt;
            folderTraversal.set_element_path(&amp;quot;childEntity&amp;quot;)&lt;br /&gt;
            folderTraversal.set_element_skip(False)&lt;br /&gt;
            SPCAfolder = []&lt;br /&gt;
            SPCAfolder.append(ObjectSet.new_selectSet())&lt;br /&gt;
            SPCAfolder[0].set_element_name(&amp;quot;folderTraversalSpec&amp;quot;)&lt;br /&gt;
            # Add here all the other elements&lt;br /&gt;
            SPCAfolder.append(datacenterHostTraversal)&lt;br /&gt;
            SPCAfolder.append(datacenterVmTraversal)&lt;br /&gt;
            SPCAfolder.append(computeResourceRpTraversal)&lt;br /&gt;
            SPCAfolder.append(computeResourceHostTraversal)&lt;br /&gt;
            SPCAfolder.append(resourcePoolTraversal)&lt;br /&gt;
            folderTraversal.set_element_selectSet(SPCAfolder)&lt;br /&gt;
&lt;br /&gt;
            SelectionSpecArray = []&lt;br /&gt;
            SelectionSpecArray.append(folderTraversal)&lt;br /&gt;
            ObjectSet.set_element_selectSet(SelectionSpecArray)&lt;br /&gt;
            ObjectSetArray.append(ObjectSet)&lt;br /&gt;
&lt;br /&gt;
            SpecSetArray = []&lt;br /&gt;
            SpecSet_PropertyFilterSpec.set_element_propSet(PropSetArray)&lt;br /&gt;
            SpecSet_PropertyFilterSpec.set_element_objectSet(ObjectSetArray)&lt;br /&gt;
            SpecSetArray.append(SpecSet_PropertyFilterSpec)&lt;br /&gt;
            PropertiesRequest.set_element_specSet(SpecSetArray)&lt;br /&gt;
&lt;br /&gt;
            PropertiesResponse = self.proxy.RetrieveProperties(PropertiesRequest)&lt;br /&gt;
            return PropertiesResponse.Returnval&lt;br /&gt;
        except (ns0.InvalidPropertyFault_Dec, ns0.RuntimeFault_Def), e:&lt;br /&gt;
            raise(VMwareVI_Error(&amp;quot;VMwareVI.RetrieveProperties %s&amp;quot; % (e)))&lt;br /&gt;
        except Exception, e:&lt;br /&gt;
            raise(VMwareVI_NonViError(&amp;quot;VMwareVI.RetrieveProperties %s&amp;quot; % (e)))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def Logout(self):&lt;br /&gt;
        # Logout&lt;br /&gt;
        try:&lt;br /&gt;
            LogoutRequest = LogoutRequestMsg()&lt;br /&gt;
            sessionManager = str(self.ServiceContent.SessionManager)&lt;br /&gt;
            This = LogoutRequest.new__this(sessionManager)&lt;br /&gt;
            This.set_attribute_type(&amp;quot;SessionManager&amp;quot;)&lt;br /&gt;
            LogoutRequest.set_element__this(This)&lt;br /&gt;
            LogoutResponse = self.proxy.Logout(LogoutRequest)&lt;br /&gt;
        except (RuntimeFault), e:&lt;br /&gt;
            raise(VMwareVI_Error(&amp;quot;VMwareVI.Logout %s&amp;quot; % (e)))&lt;br /&gt;
        except Exception, e:&lt;br /&gt;
            raise(VMwareVI_NonViError(&amp;quot;VMwareVI.Logout %s&amp;quot; % (e)))&lt;br /&gt;
&lt;br /&gt;
    def printInventory(self, ObjectContentArray):&lt;br /&gt;
        if ObjectContentArray == None:&lt;br /&gt;
            print(&amp;quot;No Managed Entities retrieved!&amp;quot;)&lt;br /&gt;
        else:&lt;br /&gt;
            for ObjectContent in ObjectContentArray:&lt;br /&gt;
                ManagedObjectReference = ObjectContent.get_element_obj()&lt;br /&gt;
                DynamicPropertyArray = ObjectContent.get_element_propSet()&lt;br /&gt;
                print(&amp;quot;Object Type: &amp;quot; + ManagedObjectReference.get_attribute_type())&lt;br /&gt;
                print(&amp;quot;Reference Value: &amp;quot; + ManagedObjectReference )&lt;br /&gt;
&lt;br /&gt;
                if DynamicPropertyArray != None:&lt;br /&gt;
                    for DynamicProperty in DynamicPropertyArray:&lt;br /&gt;
                        if (DynamicProperty != None):&lt;br /&gt;
                            print(&amp;quot;  Property Name: &amp;quot; + DynamicProperty.get_element_name())&lt;br /&gt;
                            if (type(DynamicProperty) == []): # We have here an array&lt;br /&gt;
                                ObjectArray = DynamicProperty.get_element_val()&lt;br /&gt;
                                for Object in ObjectArray:&lt;br /&gt;
                                    print(&amp;quot;Object: &amp;quot; + Object)&lt;br /&gt;
                            else:&lt;br /&gt;
                                print(&amp;quot;  Property Value: &amp;quot; + DynamicProperty.get_element_val())&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;#039;__main__&amp;#039;:&lt;br /&gt;
    parser = OptionParser()&lt;br /&gt;
    parser.add_option(&amp;quot;-c&amp;quot;, &amp;quot;--HostName&amp;quot;, dest=&amp;quot;Host&amp;quot;,&lt;br /&gt;
                      help=&amp;quot;Hostname to connect&amp;quot;, default=&amp;quot;localhost&amp;quot;)&lt;br /&gt;
    parser.add_option(&amp;quot;-u&amp;quot;, &amp;quot;--UserName&amp;quot;, dest=&amp;quot;UserName&amp;quot;,&lt;br /&gt;
                      help=&amp;quot;Username to Login&amp;quot;, default=&amp;quot;adm&amp;quot;)&lt;br /&gt;
    parser.add_option(&amp;quot;-p&amp;quot;, &amp;quot;--Password&amp;quot;, dest=&amp;quot;Password&amp;quot;,&lt;br /&gt;
                      help=&amp;quot;Password to Login&amp;quot;, default=&amp;quot;vmware&amp;quot;)&lt;br /&gt;
    parser.add_option(&amp;quot;-d&amp;quot;, &amp;quot;--Debug&amp;quot;, dest=&amp;quot;Debug&amp;quot;, action=&amp;quot;store_true&amp;quot;,&lt;br /&gt;
                      help=&amp;quot;Enable Debug&amp;quot;, default=False)&lt;br /&gt;
    parser.add_option(&amp;quot;-f&amp;quot;, &amp;quot;--DebugFile&amp;quot;, dest=&amp;quot;DebugFile&amp;quot;,&lt;br /&gt;
                      help=&amp;quot;File for Debug&amp;quot;, metavar=&amp;quot;FILE&amp;quot;, default=&amp;quot;stderr&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    (options, args) = parser.parse_args()&lt;br /&gt;
&lt;br /&gt;
    Trace=None&lt;br /&gt;
    if (options.Debug):&lt;br /&gt;
        if options.DebugFile == &amp;#039;stderr&amp;#039;:&lt;br /&gt;
            Trace=sys.stderr&lt;br /&gt;
        else:&lt;br /&gt;
            Trace=open(options.DebugFile, &amp;#039;w&amp;#039;)&lt;br /&gt;
    try:&lt;br /&gt;
        vi = VMwareVI(options.Host, options.UserName, options.Password, Trace=Trace)&lt;br /&gt;
    except Exception, e:&lt;br /&gt;
        print(&amp;quot;Error initializing connection to %s %s:%s&amp;quot; % (options.Host,&lt;br /&gt;
                                                             options.UserName,&lt;br /&gt;
                                                             options.Password))&lt;br /&gt;
        print(&amp;quot;Error content %s&amp;quot; % (str(e)))&lt;br /&gt;
        sys.exit(1)&lt;br /&gt;
    try:&lt;br /&gt;
        CurrentTime = vi.CurrentTime()&lt;br /&gt;
        print(&amp;quot;Current Time = %s&amp;quot; % (CurrentTime))&lt;br /&gt;
    except Exception, e:&lt;br /&gt;
        print(&amp;quot;Error retrieving Current Time&amp;quot;)&lt;br /&gt;
        print(&amp;quot;Error content %s&amp;quot; % (str(e)))&lt;br /&gt;
    try:&lt;br /&gt;
        HS = vi.RetrieveProperties(propSetType=&amp;quot;ManagedEntity&amp;quot;,&lt;br /&gt;
                                   objectSetObj=None, AllElements=False)&lt;br /&gt;
        # to have here the second call to RetrieveProperties will lead to an Error in&lt;br /&gt;
        # ZSI 2.0 described on the top of the file&lt;br /&gt;
        #HS = vi.RetrieveProperties(propSetType=&amp;quot;ManagedEntity&amp;quot;,&lt;br /&gt;
        #                           objectSetObj=None, AllElements=False)&lt;br /&gt;
        vi.printInventory(HS)&lt;br /&gt;
    except Exception, e:&lt;br /&gt;
        print(&amp;quot;Error retrieving Properties&amp;quot;)&lt;br /&gt;
        print(&amp;quot;Error content %s&amp;quot; % (str(e)))&lt;br /&gt;
    try:&lt;br /&gt;
        vi.Logout()&lt;br /&gt;
    except Exception, e:&lt;br /&gt;
        print(&amp;quot;Error Logout&amp;quot;)&lt;br /&gt;
        print(&amp;quot;Error content %s&amp;quot; % (str(e)))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Python]][[Category:ZSI]][[Category:VMWare]]&lt;/div&gt;</summary>
		<author><name>PeterHarding</name></author>
	</entry>
</feed>