get_view() and MORs

60 views
Skip to first unread message

Leo Godin

unread,
Aug 26, 2013, 7:58:25 PM8/26/13
to psp...@googlegroups.com
I'm trying to script license usage with psphere. I can use the managed entities that have get() and all(), but I can't figure out how to use get_view on MORs. Is the MOR a reference to an instance of a managed object? If so, can someone give me an example of an instantiation? Here's one example of what I tried. I also tried initializing empty variables to use as the MOR.  



>>> license_manager = LicenseManager(LicenseManager, client)
>>> client.get_view(license_manager)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\Users\lggodin\Documents\projects\ESXLicenseReporter\UsedLicenses\py27env\lib\site-packages\psphere\client.py"
, line 322, in get_view
    kls = classmapper(mo_ref._type)
  File "c:\Users\lggodin\Documents\projects\ESXLicenseReporter\UsedLicenses\py27env\lib\site-packages\psphere\__init__.p
y", line 348, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'LicenseManager' object has no attribute '_type'
>>>

Jonathan Kinred

unread,
Aug 26, 2013, 8:51:33 PM8/26/13
to psp...@googlegroups.com
Hi Leo,

Generally when you want a Managed Object you are retrieving it as a property of another Managed Object or Data Object.

In the case of the <foo>Manager variety of Managed Objects they are typically found in the ServiceContent which is available as the 'sc' attribute of the Client object.

If you want to find out where something is, you can look at the "Property of" section in the API documentation:
http://pubs.vmware.com/vsphere-51/index.jsp#com.vmware.wssdk.apiref.doc/vim.LicenseManager.html

Here is an example of using the licenseManager.

>>> from psphere.client import Client
>>> client = Client("your.esxserver.com", "Administrator", "strongpass")
>>> license_manager = client.sc.licenseManager
>>> type(license_manager)
<class 'psphere.managedobjects.LicenseManager'>
>>> lm_info = license_manager.QuerySupportedFeatures()
>>> for feature in lm_info:
...     print('%s: %s' % (feature.featureName, feature.state))
...
vSphere HA
: optional
VMware DRS: optional
VMware DRS Power Management: optional
vCenter agent
for VMware host: optional
vCenter agent
for vCenter Server: optional
Storage vMotion: optional
vCenter
Management Server: optional
vCenter
Foundation Management Server: optional
vMotion
: optional
>>> client.logout()

I've also added an example to the code base:
https://github.com/jkinred/psphere/blob/master/examples/query_supported_features.py

Jonathan

Leo Godin

unread,
Aug 27, 2013, 2:28:36 PM8/27/13
to psp...@googlegroups.com
Thank you so much! 
Reply all
Reply to author
Forward
0 new messages