Skip to content

Commit

Permalink
Add 'vm.guest.disk.discover' method for discovering disks on all
Browse files Browse the repository at this point in the history
VirtualMachine managed objects
  • Loading branch information
dnaeon committed Mar 31, 2014
1 parent 0092581 commit 533409f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
64 changes: 63 additions & 1 deletion src/vpoller/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def vm_datastore_discover(self, msg):
obj_type=pyVmomi.vim.VirtualMachine
)

# Get the VM objects and extract datastore information for each
# Get the VM objects and collect datastore information for each VM
result = []
for each_obj in data['result']:
properties = {}
Expand Down Expand Up @@ -495,6 +495,68 @@ def vm_datastore_discover(self, msg):

return r

def vm_guest_disk_discover(self, msg):
"""
Discover all disks used by each pyVmomi.vim.VirtualMachine managed object
Note, that this request requires you to have VMware Tools installed in order
get information about the guest disks.
Example client message would be:
{
"method": "vm.guest.disk.discover",
"hostname": "vc01.example.org",
}
Example client message requesting additional properties to be collected:
{
"method": "vm.guest.disk.discover",
"hostname": "vc01.example.org",
"properties": [
"capacity",
"diskPath",
"freeSpace"
]
}
Returns:
The discovered objects in JSON format
"""
# Properties to be collected for the guest disks
disk_properties = ['diskPath']
if msg.has_key('properties') and msg['properties']:
disk_properties.extend(msg['properties'])

# Discover all VMs and collect their disk properties
data = self._discover_objects(
properties=['name', 'guest.disk'],
obj_type=pyVmomi.vim.VirtualMachine
)

# Get the VM objects and collect disk information for each VM
result = []
for each_obj in data['result']:
vm_name, vm_disks = each_obj['name'], each_obj['guest.disk']

properties = {}
properties['name'] = vm_name
properties['disk'] = []

d = [{prop:getattr(disk, prop, None) for prop in disk_properties} for disk in vm_disks]
properties['disk'].append(d)
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 @@ -330,6 +330,10 @@ def process_client_msg(self, msg):
'method': self.agents[vsphere_host].vm_datastore_discover,
'msg_attr': ('method', 'hostname'),
},
'vm.guest.disk.discover': {
'method': self.agents[vsphere_host].vm_guest_disk_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 533409f

Please sign in to comment.