Skip to content

Commit

Permalink
Add 'net.host.get' vPoller method
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaeon committed Apr 2, 2014
1 parent aa6a394 commit 54e3fd6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
54 changes: 53 additions & 1 deletion src/vpoller/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,63 @@ def net_get(self, msg):

return self._get_object_properties(
properties=properties,
obj_type=pyVmomi.vim.Nework,
obj_type=pyVmomi.vim.Network,
obj_property_name='name',
obj_property_value=msg['name']
)

def net_host_get(self, msg):
"""
Get all Host Systems using this pyVmomi.vim.Network managed object
Example client message would be:
{
"method": "net.host.get",
"hostname": "vc01.example.org",
"name": "VM Network",
}
Returns:
The managed object properties in JSON format
"""
logging.debug('[%s] Getting Host Systems using %s pyVmomi.vim.Network managed object', self.host, msg['name'])

# Find the Network managed object and get the 'host' property
data = self._get_object_properties(
properties=['name', 'host'],
obj_type=pyVmomi.vim.Network,
obj_property_name='name',
obj_property_value=msg['name']
)

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

props = data['result'][0]
network_name, network_hosts = props['name'], props['host']

# Create a list view for the HostSystem managed objects
view_ref = self.get_list_view(obj=network_hosts)
result = {}
result['name'] = network_name
result['host'] = self.collect_properties(
view_ref=view_ref,
obj_type=pyVmomi.vim.HostSystem,
path_set=['name']
)

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

logging.debug('[%s] Returning result from operation: %s', self.host, r)

return r

def datacenter_discover(self, msg):
"""
Discover all pyVmomi.vim.Datacenter 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 @@ -314,6 +314,10 @@ def process_client_msg(self, msg):
'method': self.agents[vsphere_host].net_get,
'msg_attr': ('method', 'hostname', 'name'),
},
'net.host.get': {
'method': self.agents[vsphere_host].net_host_get,
'msg_attr': ('method', 'hostname', 'name'),
},
'datacenter.discover': {
'method': self.agents[vsphere_host].datacenter_discover,
'msg_attr': ('method', 'hostname'),
Expand Down

0 comments on commit 54e3fd6

Please sign in to comment.