Skip to content

Commit

Permalink
Add 'vm.discover' method for discovering VirtualMachine managed objects
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaeon committed Mar 29, 2014
1 parent bca0e46 commit fdd5bff
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/vpoller/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,35 @@ def host_discover(self, msg):

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

def vm_discover(self, msg):
"""
Discover all pyVmomi.vim.VirtualMachine managed objects
Example client message would be:
{
"method": "vm.discover",
"hostname": "vc01.example.org",
}
Example client message which also requests additional properties:
{
"method": "vm.discover",
"hostname": "vc01.example.org",
"properties": [
"name",
"runtime.powerState"
]
}
Returns:
The discovered objects in JSON format
"""
# Property names to be collected
properties = ['name']
if msg.has_key('properties') and msg['properties']:
properties.extend(msg['properties'])

return self._discover_objects(properties=properties, obj_type=pyVmomi.vim.VirtualMachine)
4 changes: 4 additions & 0 deletions src/vpoller/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ def process_client_msg(self, msg):
'method': self.agents[vsphere_host].host_discover,
'msg_attr': ('method', 'hostname'),
},
'vm.discover': {
'method': self.agents[vsphere_host].vm_discover,
'msg_attr': ('method', 'hostname'),
},
}

if msg['method'] not in methods:
Expand Down

0 comments on commit fdd5bff

Please sign in to comment.