Skip to content

Commit

Permalink
Add 'vm.net.get' vPoller method
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaeon committed Apr 2, 2014
1 parent c4eb938 commit bcd8ada
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 @@ -783,7 +783,7 @@ def host_net_get(self, msg):
"""
logging.debug('[%s] Getting Network list available for %s host', self.host, msg['name'])

# Find the HostSystem managed object and get the 'net' property
# Find the HostSystem managed object and get the 'network' property
data = self._get_object_properties(
properties=['name', 'network'],
obj_type=pyVmomi.vim.HostSystem,
Expand Down Expand Up @@ -1010,6 +1010,58 @@ def vm_guest_net_get(self, msg):

return r

def vm_net_get(self, msg):
"""
Get all Networks used in this pyVmomi.vim.VirtualMachine managed object
Example client message would be:
{
"method": "vm.net.get",
"hostname": "vc01.example.org",
"name": "vm01.example.org",
}
Returns:
The managed object properties in JSON format
"""
logging.debug('[%s] Getting Network list available for %s VirtualMachine', self.host, msg['name'])

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

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

props = data['result'][0]
vm_name, vm_networks = props['name'], props['network']

# Create a list view for the Network managed objects
view_ref = self.get_list_view(obj=vm_networks)
result = {}
result['name'] = vm_name
result['network'] = self.collect_properties(
view_ref=view_ref,
obj_type=pyVmomi.vim.Network,
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 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 @@ -394,6 +394,10 @@ def process_client_msg(self, msg):
'method': self.agents[vsphere_host].vm_guest_net_get,
'msg_attr': ('method', 'hostname', 'name'),
},
'vm.net.get': {
'method': self.agents[vsphere_host].vm_net_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 bcd8ada

Please sign in to comment.