diff options
author | Matt Riedemann <mriedem.os@gmail.com> | 2019-05-17 18:07:38 -0400 |
---|---|---|
committer | Matt Riedemann <mriedem.os@gmail.com> | 2019-05-18 14:47:11 -0400 |
commit | 0dc6b96ec83703a0607c4df16e43856632aecb61 (patch) | |
tree | 6484b96440d2f99f9bb4a3fa8db66003b93e2f5b /novaclient/v2 | |
parent | dfb84228a2748bed82f9b83c1209d5e2e0557bfa (diff) | |
download | python-novaclient-0dc6b96ec83703a0607c4df16e43856632aecb61.tar.gz |
Allow searching for hypervisors and getting back details
The 2.53 microversion allows listing hypervisors with
details and filtering on a hypervisor_hostname substring
pattern match.
This makes the python API binding HypervisorManager.search
method allow that as well by adding a new 'detailed' boolean
kwarg which defaults to False for backward compatibility for
the /search and /servers routes before 2.53, but allows
searching and getting detailed results back as well.
Change-Id: I81fa4520af3cc7f1298c262f4fdc4e15fbc6d7ba
Diffstat (limited to 'novaclient/v2')
-rw-r--r-- | novaclient/v2/hypervisors.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/novaclient/v2/hypervisors.py b/novaclient/v2/hypervisors.py index 4b26bfc5..e6f5038c 100644 --- a/novaclient/v2/hypervisors.py +++ b/novaclient/v2/hypervisors.py @@ -23,6 +23,8 @@ from six.moves.urllib import parse from novaclient import api_versions from novaclient import base +from novaclient import exceptions +from novaclient.i18n import _ from novaclient import utils @@ -76,7 +78,7 @@ class HypervisorManager(base.ManagerWithFind): """ return self._list_base(detailed=detailed, marker=marker, limit=limit) - def search(self, hypervisor_match, servers=False): + def search(self, hypervisor_match, servers=False, detailed=False): """ Get a list of matching hypervisors. @@ -84,6 +86,8 @@ class HypervisorManager(base.ManagerWithFind): The hypervisor hosts are selected with the host name matching this pattern. :param servers: If True, server information is also retrieved. + :param detailed: If True, detailed hypervisor information is returned. + This requires API version 2.53 or greater. """ # Starting with microversion 2.53, the /servers and /search routes are # deprecated and we get the same results using GET /os-hypervisors @@ -91,11 +95,16 @@ class HypervisorManager(base.ManagerWithFind): if six.PY2: hypervisor_match = encodeutils.safe_encode(hypervisor_match) if self.api_version >= api_versions.APIVersion('2.53'): - url = ('/os-hypervisors?hypervisor_hostname_pattern=%s' % - parse.quote(hypervisor_match, safe='')) + url = ('/os-hypervisors%s?hypervisor_hostname_pattern=%s' % + ('/detail' if detailed else '', + parse.quote(hypervisor_match, safe=''))) if servers: url += '&with_servers=True' else: + if detailed: + raise exceptions.UnsupportedVersion( + _('Parameter "detailed" requires API version 2.53 or ' + 'greater.')) target = 'servers' if servers else 'search' url = ('/os-hypervisors/%s/%s' % (parse.quote(hypervisor_match, safe=''), target)) |