Skip to content

Commit

Permalink
Add 'vm.datastore.discover' method for discovering all datastores used
Browse files Browse the repository at this point in the history
by all Virtual Machines
  • Loading branch information
dnaeon committed Mar 31, 2014
1 parent edb7fcd commit 19d715e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/vpoller/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,58 @@ def vm_discover(self, msg):

return self._discover_objects(properties=properties, obj_type=pyVmomi.vim.VirtualMachine)

def vm_datastore_discover(self, msg):
"""
Discover all Datastores used by each pyVmomi.vim.VirtualMachine managed object
Example client message would be:
{
"method": "vm.datastore.discover",
"hostname": "vc01.example.org",
}
Returns:
The discovered objects in JSON format
"""
# Discover all VMs and collect their datastore properties
data = self._discover_objects(
properties=['name', 'datastore'],
obj_type=pyVmomi.vim.VirtualMachine
)

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

# Get the VM objects and extract datastore information for each
result = []
for each_obj in data['result']:
properties = {}

vm_name, vm_datastores = each_obj['name'], each_obj['datastore']
properties['name'] = vm_name

# Get a list view of the datastores used by the VM
view_ref = self.get_list_view(obj=vm_datastores)

# Collect the name and url properties for each datastore
properties['datastore'] = self.collect_properties(
view_ref=view_ref,
obj_type=pyVmomi.vim.Datastore,
path_set=['name', 'info.url']
)

result.append(properties)

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

return r

def vm_get(self, msg):
"""
Get properties of a single pyVmomi.vim.VirtualMachine 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 @@ -326,6 +326,10 @@ def process_client_msg(self, msg):
'method': self.agents[vsphere_host].vm_discover,
'msg_attr': ('method', 'hostname'),
},
'vm.datastore.discover': {
'method': self.agents[vsphere_host].vm_datastore_discover,
'msg_attr': ('method', 'hostname'),
},
'vm.get': {
'method': self.agents[vsphere_host].vm_get,
'msg_attr': ('method', 'hostname', 'name', 'properties'),
Expand Down

0 comments on commit 19d715e

Please sign in to comment.