Skip to content

Commit

Permalink
Add 'vm.datastore.get' method for getting all datastores used by a
Browse files Browse the repository at this point in the history
specific VirtualMachine managed object
  • Loading branch information
dnaeon committed Mar 31, 2014
1 parent 19d715e commit 0092581
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
52 changes: 49 additions & 3 deletions src/vpoller/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,6 @@ def vm_datastore_discover(self, msg):
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']:
Expand Down Expand Up @@ -530,6 +527,55 @@ def vm_get(self, msg):
obj_property_value=msg['name']
)

def vm_datastore_get(self, msg):
"""
Get all Datastores used by a pyVmomi.vim.VirtualMachine managed object
Example client message would be:
{
"method": "vm.datastore.discover",
"hostname": "vc01.example.org",
"name": "vm01.example.org",
}
Returns:
The discovered objects in JSON format
"""
# Find the VM and get the datastores used by it
data = self._get_object_properties(
properties=['name', 'datastore'],
obj_type=pyVmomi.vim.VirtualMachine,
obj_property_name='name',
obj_property_value=msg['name']
)

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

# Get the VM name and datastore properties from the result
props = data['result'][0]
vm_name, vm_datastores = props['name'], props['datastore']

# Get a list view of the datastores used by this VM and collect properties
result = {}
view_ref = self.get_list_view(obj=vm_datastores)
result['name'] = vm_name
result['datastore'] = self.collect_properties(
view_ref=view_ref,
obj_type=pyVmomi.vim.Datastore,
path_set=['name', 'info.url']
)

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

return r

def datastore_discover(self, msg):
"""
Discover all pyVmomi.vim.Datastore managed objects
Expand Down
4 changes: 4 additions & 0 deletions src/vpoller/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ def process_client_msg(self, msg):
'method': self.agents[vsphere_host].vm_get,
'msg_attr': ('method', 'hostname', 'name', 'properties'),
},
'vm.datastore.get': {
'method': self.agents[vsphere_host].vm_datastore_get,
'msg_attr': ('method', 'hostname', 'name'),
},
'datastore.discover': {
'method': self.agents[vsphere_host].datastore_discover,
'msg_attr': ('method', 'hostname'),
Expand Down

0 comments on commit 0092581

Please sign in to comment.