1

I am working on a set of Python scripts that are supposed to manipulate ESX virtual machines vApp properties. I've found pySphere and I was able to add/edit the key/label/value properties, however, I cant seem to find a way to retrieve those in any way - there's no documentation on pySphere project about that, and the classess/methods are lacking docstrings, so iPython wasnt very helpul.

Would anyone know a way to list those attributes, or could point me to the source that talks about using pySphere to do so?

S.

SpankMe
  • 836
  • 1
  • 8
  • 23

2 Answers2

0

I get vApp properties with this script:

s = VIServer()
s.connect('vcenter.example.com', 'username', 'password')
vm = s.get_vm_by_name('vm01')
props = s._retrieve_properties_traversal(property_names=['config.vAppConfig.property'], obj_type="VirtualMachine", from_node=vm._mor)
for prop_set in props:
    for prop in prop_set.PropSet:
        for i in prop.Val.get_element_VAppPropertyInfo():
            print i.get_element_label() + ' = ' + i.get_element_value()

Not very nice, but works.

Martin B.
  • 23
  • 5
  • I am trying to do something very similar here. I need to pull the name of guest, host or datastore. How would I retrieve the name of the object (host, guest or datastore) and assign it to a variable (called Name:). Here is what I have: for item in results: name=item.Name for p in item.PropSet: if p.Name=="summary.capacity": Metric="Total_Capacity" data_host=(d,Name,Metric,p.Val) print data_host – user1471980 Nov 11 '14 at 18:23
-1

Edit: The question is about retrieving properties. The following doesn't answer, but if you happen into this thread (as I did) looking to add/edit/remove properties, you might find this answer useful.


Googling pysphere vApp properties yields this relevant discussion as first result: Access to, and modify, a VMs vApp Properties.

To quote the gist of the recipe:

# ... import, connect to server etc. ...

request = VI.ReconfigVM_TaskRequestMsg()
_this = request.new__this(vm._mor)
_this.set_attribute_type(vm._mor.get_attribute_type())
request.set_element__this(_this)

spec = request.new_spec()
vappconfig = spec.new_vAppConfig()

# e.g.
prop = vappconfig.new_property()
prop.set_element_operation('add')
info = prop.new_info()
info.set_element_key(10)
info.set_element_id("10")
info.set_element_value("test")
info.set_element_category("testCat")

vappconfig.set_element_property([prop])
spec.set_element_vAppConfig(vappconfig)

request.set_element_spec(spec)
task = viserver._proxy.ReconfigVM_Task(request)._returnval
vi_task = VITask(task, viserver)

status = vi_task.wait_for_state([vi_task.STATE_SUCCESS,
                                 vi_task.STATE_ERROR])

The link itself gives out a nicer wrapper for making multiple add/edit/remove modifications defined by a dictionary. Check it out.

Yonatan
  • 1,187
  • 15
  • 33
  • This is exactly what I can do - add, edit and remove existing properties, and it is not an answer to the quesion how to retrieve/check current existing ones... – SpankMe Dec 30 '13 at 11:26
  • You're absolutely right! Teaches you a lesson on answering questions at 4 AM. Brain must have been offline at the time... Good luck with the real question! – Yonatan Dec 30 '13 at 13:57