From f7ce08953797718fa98b4fcb842579770d7ec18e Mon Sep 17 00:00:00 2001 From: Marin Atanasov Nikolov Date: Wed, 2 Apr 2014 11:11:48 +0300 Subject: [PATCH] Add 'net.vm.get' vPoller method --- src/vpoller/agent.py | 52 +++++++++++++++++++++++++++++++++++++++++++ src/vpoller/worker.py | 4 ++++ 2 files changed, 56 insertions(+) diff --git a/src/vpoller/agent.py b/src/vpoller/agent.py index 857fdbf..dbf4df8 100644 --- a/src/vpoller/agent.py +++ b/src/vpoller/agent.py @@ -399,6 +399,58 @@ def net_host_get(self, msg): return r + def net_vm_get(self, msg): + """ + Get all Virtual Machines using this pyVmomi.vim.Network managed object + + Example client message would be: + + { + "method": "net.vm.get", + "hostname": "vc01.example.org", + "name": "VM Network", + } + + Returns: + The managed object properties in JSON format + + """ + logging.debug('[%s] Getting Virtual Machines using %s pyVmomi.vim.Network managed object', self.host, msg['name']) + + # Find the Network managed object and get the 'vm' property + data = self._get_object_properties( + properties=['name', 'vm'], + 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_vms = props['name'], props['vm'] + + # Create a list view for the VirtualMachine managed objects + view_ref = self.get_list_view(obj=network_vms) + result = {} + result['name'] = network_name + result['vm'] = self.collect_properties( + view_ref=view_ref, + obj_type=pyVmomi.vim.VirtualMachine, + 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 diff --git a/src/vpoller/worker.py b/src/vpoller/worker.py index b0ec0a9..e78e24b 100644 --- a/src/vpoller/worker.py +++ b/src/vpoller/worker.py @@ -318,6 +318,10 @@ def process_client_msg(self, msg): 'method': self.agents[vsphere_host].net_host_get, 'msg_attr': ('method', 'hostname', 'name'), }, + 'net.vm.get': { + 'method': self.agents[vsphere_host].net_vm_get, + 'msg_attr': ('method', 'hostname', 'name'), + }, 'datacenter.discover': { 'method': self.agents[vsphere_host].datacenter_discover, 'msg_attr': ('method', 'hostname'),