diff options
| author | Stephen Finucane <sfinucan@redhat.com> | 2020-11-17 12:33:40 +0000 |
|---|---|---|
| committer | Stephen Finucane <sfinucan@redhat.com> | 2021-01-06 12:02:25 +0000 |
| commit | bf834f6d7582009672fc65aa983f314684dc4380 (patch) | |
| tree | 13928f1e94e35652b031d98e63eed61e0179b727 /openstackclient/compute/v2 | |
| parent | e2a9a9607cc84c0afc2fc5524681a3adebdc68ec (diff) | |
| download | python-openstackclient-bf834f6d7582009672fc65aa983f314684dc4380.tar.gz | |
compute: Fix 'hypervisor show -f yaml' output
The 'cpu_info' field returned by the 'os-hypervisors' API is an object
and should be formatted as such. However, this is complicated by the
fact that the object in this field is stringified until microversion
2.28 and is only returned as an actual object on later microversions.
Handle the conversion from the string for older microversions and
display things correctly for all releases.
Change-Id: Ide31466cbb9e89c96d6bd542fe039ab5ed1fac1f
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Diffstat (limited to 'openstackclient/compute/v2')
| -rw-r--r-- | openstackclient/compute/v2/hypervisor.py | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/openstackclient/compute/v2/hypervisor.py b/openstackclient/compute/v2/hypervisor.py index 7f110028..8fdb6698 100644 --- a/openstackclient/compute/v2/hypervisor.py +++ b/openstackclient/compute/v2/hypervisor.py @@ -15,9 +15,12 @@ """Hypervisor action implementations""" +import json import re +from novaclient import api_versions from novaclient import exceptions as nova_exceptions +from osc_lib.cli import format_columns from osc_lib.command import command from osc_lib import utils @@ -86,8 +89,8 @@ class ShowHypervisor(command.ShowOne): if aggregates: # Hypervisors in nova cells are prefixed by "<cell>@" if "@" in hypervisor['service']['host']: - cell, service_host = hypervisor['service']['host'].split('@', - 1) + cell, service_host = hypervisor['service']['host'].split( + '@', 1) else: cell = None service_host = hypervisor['service']['host'] @@ -125,4 +128,19 @@ class ShowHypervisor(command.ShowOne): hypervisor["service_host"] = hypervisor["service"]["host"] del hypervisor["service"] - return zip(*sorted(hypervisor.items())) + if compute_client.api_version < api_versions.APIVersion('2.28'): + # microversion 2.28 transformed this to a JSON blob rather than a + # string; on earlier fields, do this manually + if hypervisor['cpu_info']: + hypervisor['cpu_info'] = json.loads(hypervisor['cpu_info']) + else: + hypervisor['cpu_info'] = {} + + columns = tuple(sorted(hypervisor)) + data = utils.get_dict_properties( + hypervisor, columns, + formatters={ + 'cpu_info': format_columns.DictColumn, + }) + + return (columns, data) |
