Skip to content

Commit

Permalink
Add method for getting all VMs running on a specified HostSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaeon committed Mar 31, 2014
1 parent 6a27c25 commit fd0ace6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/vpoller/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,54 @@ def host_get(self, msg):
obj_property_value=msg['name']
)

def host_vm_get(self, msg):
"""
Get all Virtual Machines running on this HostSystem
Example client message would be:
{
"method": "host.vm.get",
"hostname": "vc01.example.org",
"name": "esxi01.example.org",
}
Returns:
The managed object properties in JSON format
"""
# Find the HostSystem managed object and get the 'vm' property
data = self._get_object_properties(
properties=['name', 'vm'],
obj_type=pyVmomi.vim.HostSystem,
obj_property_name='name',
obj_property_value=msg['name']
)

if data['success'] != 0:
return data

props = data['result'][0]
host_name, host_vms = props['name'], props['vm']

# Create a list view for the VirtualMachine managed objects
view_ref = self.get_list_view(obj=host_vms)
result = {}
result['name'] = host_name
result['vm'] = self.collect_properties(
view_ref=view_ref,
obj_type=pyVmomi.vim.VirtualMachine,
path_set=['name']
)

r = {
'success': 0,
'msg': 'Successfully discovered objects',
'result': result,
}

return r

def host_datastore_get(self, msg):
"""
Get all Datastores available for a pyVmomi.vim.HostSystem managed object
Expand Down
4 changes: 4 additions & 0 deletions src/vpoller/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ def process_client_msg(self, msg):
'method': self.agents[vsphere_host].host_get,
'msg_attr': ('method', 'hostname', 'name', 'properties'),
},
'host.vm.get': {
'method': self.agents[vsphere_host].host_vm_get,
'msg_attr': ('method', 'hostname', 'name'),
},
'host.datastore.get': {
'method': self.agents[vsphere_host].host_datastore_get,
'msg_attr': ('method', 'hostname'),
Expand Down

0 comments on commit fd0ace6

Please sign in to comment.