summaryrefslogtreecommitdiff
path: root/novaclient/v2
diff options
context:
space:
mode:
authorStephen Finucane <stephenfin@redhat.com>2021-01-12 17:18:56 +0000
committerStephen Finucane <stephenfin@redhat.com>2021-03-02 12:14:12 +0000
commit54d4da112a6e84db5bda497364a49b9debfc2904 (patch)
tree5f6624791c0c6fab0dbdf64e0727fbfb937ccd02 /novaclient/v2
parente45953927898b639de9dbcba8edb6d07bcb4cba3 (diff)
downloadpython-novaclient-54d4da112a6e84db5bda497364a49b9debfc2904.tar.gz
Add support for microversion v2.8817.4.0
The key change here is that the 'GET /os-hypervisors/{id}/uptime' API will now returns a HTTP 404 starting in 2.88. The 'GET /os-hypervisors/{id}' will instead now include an 'uptime' value. The 'novaclient.v2.hypervisors.HypervisorManager.uptime' method is updated to handle this. Change-Id: Ib99fbd820a586c14527ff64b319df0b7a44e1b8b Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Diffstat (limited to 'novaclient/v2')
-rw-r--r--novaclient/v2/hypervisors.py28
-rw-r--r--novaclient/v2/shell.py10
2 files changed, 36 insertions, 2 deletions
diff --git a/novaclient/v2/hypervisors.py b/novaclient/v2/hypervisors.py
index c705dc65..f0cc5863 100644
--- a/novaclient/v2/hypervisors.py
+++ b/novaclient/v2/hypervisors.py
@@ -123,8 +123,25 @@ class HypervisorManager(base.ManagerWithFind):
:param hypervisor: Either a Hypervisor object or an ID. Starting with
microversion 2.53 the ID must be a UUID value.
"""
- return self._get("/os-hypervisors/%s/uptime" % base.getid(hypervisor),
- "hypervisor")
+ # Starting with microversion 2.88, the '/os-hypervisors/{id}/uptime'
+ # route is removed in favour of returning 'uptime' in the response of
+ # the '/os-hypervisors/{id}' route. This behaves slightly differently,
+ # in that it won't error out if a virt driver doesn't support reporting
+ # uptime or if the hypervisor is down, but it's a good enough
+ # approximation
+ if self.api_version < api_versions.APIVersion("2.88"):
+ return self._get(
+ "/os-hypervisors/%s/uptime" % base.getid(hypervisor),
+ "hypervisor")
+
+ resp, body = self.api.client.get(
+ "/os-hypervisors/%s" % base.getid(hypervisor)
+ )
+ content = {
+ k: v for k, v in body['hypervisor'].items()
+ if k in ('id', 'hypervisor_hostname', 'state', 'status', 'uptime')
+ }
+ return self.resource_class(self, content, loaded=True, resp=resp)
def statistics(self):
"""
@@ -145,8 +162,15 @@ class HypervisorStats(base.Resource):
class HypervisorStatsManager(base.Manager):
resource_class = HypervisorStats
+ @api_versions.wraps("2.0", "2.87")
def statistics(self):
"""
Get hypervisor statistics over all compute nodes.
"""
return self._get("/os-hypervisors/statistics", "hypervisor_statistics")
+
+ @api_versions.wraps("2.88")
+ def statistics(self):
+ raise exceptions.UnsupportedVersion(
+ _("The 'statistics' API is removed in API version 2.88 or later.")
+ )
diff --git a/novaclient/v2/shell.py b/novaclient/v2/shell.py
index 23f5486f..eb0315fd 100644
--- a/novaclient/v2/shell.py
+++ b/novaclient/v2/shell.py
@@ -4049,12 +4049,22 @@ def do_hypervisor_uptime(cs, args):
utils.print_dict(hyper.to_dict())
+@api_versions.wraps('2.0', '2.87')
def do_hypervisor_stats(cs, args):
"""Get hypervisor statistics over all compute nodes."""
stats = cs.hypervisor_stats.statistics()
utils.print_dict(stats.to_dict())
+@api_versions.wraps('2.88')
+def do_hypervisor_stats(cs, args):
+ msg = _(
+ "The hypervisor-stats command is not supported in API version 2.88 "
+ "or later."
+ )
+ raise exceptions.CommandError(msg)
+
+
@utils.arg('server', metavar='<server>', help=_('Name or ID of server.'))
@utils.arg(
'--port',