Skip to content

Commit

Permalink
Add 'host.cluster.get' vPoller method for getting the cluster name fo…
Browse files Browse the repository at this point in the history
…r a HostSystem
  • Loading branch information
dnaeon committed Apr 6, 2014
1 parent 25e9fce commit c0e4ef9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ The table below summarizes the list of currently supported methods by `vPoller`
| resource.pool.get | Get properties for a vim.ResourcePool managed object |
| host.discover | Discover all vim.HostSystem managed objects |
| host.get | Get properties for a vim.HostSystem managed object |
| host.cluster.get | Get the cluster name for a vim.HostSystem managed object |
| host.vm.get | Get all Virtual Machines running on a specified vim.HostSystem |
| host.net.get | Get all Networks available for a specified vim.HostSystem |
| host.datastore.get | Get all datastores available to a vim.HostSystem |
Expand Down
2 changes: 2 additions & 0 deletions src/misc-tools/vcli.source
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ _vcli_resource_pool_get() { vpoller-client -m resource.pool.get "$@" | jq '.' ;}

_vcli_host_discover() { vpoller-client -m host.discover "$@" | jq '.' ;}
_vcli_host_get() { vpoller-client -m host.get "$@" | jq '.' ;}
_vcli_host_cluster_get() { vpoller-client -m host.cluster.get "$@" | jq '.' ;}
_vcli_host_vm_get() { vpoller-client -m host.vm.get "$@" | jq '.' ;}
_vcli_host_datastore_get() { vpoller-client -m host.datastore.get "$@" | jq '.' ;}
_vcli_host_net_get() { vpoller-client -m host.net.get "$@" | jq '.' ;}
Expand Down Expand Up @@ -58,6 +59,7 @@ alias 'vcli-resource-pool-discover=_vcli_resource_pool_discover'
alias 'vcli-resource-pool-get=_vcli_resource_pool_get'
alias 'vcli-host-discover=_vcli_host_discover'
alias 'vcli-host-get=_vcli_host_get'
alias 'vcli-host-cluster-get=_vcli_host_cluster_get'
alias 'vcli-host-vm-get=_vcli_host_vm_get'
alias 'vcli-host-datastore-get=_vcli_host_datastore_get'
alias 'vcli-host-net-get=_vcli_host_net_get'
Expand Down
45 changes: 45 additions & 0 deletions src/vpoller/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,51 @@ def host_get(self, msg):
obj_property_value=msg['name']
)

def host_cluster_get(self, msg):
"""
Get the cluster name for a HostSystem
Example client message would be:
{
"method": "host.cluster.get",
"hostname": "vc01.example.org",
"name": "esxi01.example.org",
}
Returns:
The managed object properties in JSON format
"""
logging.debug('[%s] Getting cluster name for %s host', self.host, msg['name'])

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

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

props = data['result'][0]
host_name, host_cluster = props['name'], props['parent']

result['name'] = host_name
result['cluster'] = host_cluster.name

r = {
'success': 0,
'msg': 'Successfully retrieved properties',
'result': [ result ],
}

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

return r

def host_vm_get(self, msg):
"""
Get all Virtual Machines running on this HostSystem
Expand Down
4 changes: 4 additions & 0 deletions src/vpoller/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ def process_client_msg(self, msg):
'method': self.agents[vsphere_host].host_get,
'msg_attr': ('method', 'hostname', 'name', 'properties'),
},
'host.cluster.get': {
'method': self.agents[vsphere_host].host_cluster_get,
'msg_attr': ('method', 'hostname', 'name'),
},
'host.vm.get': {
'method': self.agents[vsphere_host].host_vm_get,
'msg_attr': ('method', 'hostname', 'name'),
Expand Down

0 comments on commit c0e4ef9

Please sign in to comment.