summaryrefslogtreecommitdiff
path: root/openstackclient/compute
diff options
context:
space:
mode:
authorKhomesh Thakre <khomeshthakre24@gmail.com>2020-11-06 22:45:03 +0530
committermelanie witt <melwittt@gmail.com>2021-12-01 01:32:52 +0000
commit0873e7580eceab07c3be0824d2ea4163491f8d6e (patch)
tree225a7d9ac178a97b641300993e6ee021aa4df84e /openstackclient/compute
parentf4adbcef7b1b18d9454109a020e5e2c6ad78b5f1 (diff)
downloadpython-openstackclient-0873e7580eceab07c3be0824d2ea4163491f8d6e.tar.gz
compute: Show flavor in 'server list' with API >= 2.47
Fix the issue where the flavor name was empty in server list output. This requires somewhat invasive unit test changes to reflect the changed API response from the server, but this has the upside of meaning we don't need new tests since what we have validates things. Also drop the flavor ID column as it is removed from the compute API. Change-Id: Ica3320242a38901c1180b2b29109c9474366fde0 Signed-off-by: Khomesh Thakre <khomeshthakre24@gmail.com> Story: 2008257 Task: 41113 (cherry picked from commit 8e362402dee07744668bcf7f6774af4fbe9a07e3)
Diffstat (limited to 'openstackclient/compute')
-rw-r--r--openstackclient/compute/v2/server.py42
1 files changed, 22 insertions, 20 deletions
diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py
index 438d43f9..60e2572d 100644
--- a/openstackclient/compute/v2/server.py
+++ b/openstackclient/compute/v2/server.py
@@ -2303,21 +2303,28 @@ class ListServer(command.Lister):
columns += ('image_name',)
column_headers += ('Image',)
- if parsed_args.long:
- columns += (
- 'flavor_name',
- 'flavor_id',
- )
- column_headers += (
- 'Flavor Name',
- 'Flavor ID',
- )
+ # microversion 2.47 puts the embedded flavor into the server response
+ # body but omits the id, so if not present we just expose the original
+ # flavor name in the output
+ if compute_client.api_version >= api_versions.APIVersion('2.47'):
+ columns += ('flavor_name',)
+ column_headers += ('Flavor',)
else:
- if parsed_args.no_name_lookup:
- columns += ('flavor_id',)
+ if parsed_args.long:
+ columns += (
+ 'flavor_name',
+ 'flavor_id',
+ )
+ column_headers += (
+ 'Flavor Name',
+ 'Flavor ID',
+ )
else:
- columns += ('flavor_name',)
- column_headers += ('Flavor',)
+ if parsed_args.no_name_lookup:
+ columns += ('flavor_id',)
+ else:
+ columns += ('flavor_name',)
+ column_headers += ('Flavor',)
if parsed_args.long:
columns += (
@@ -2441,18 +2448,13 @@ class ListServer(command.Lister):
s.image_name = IMAGE_STRING_FOR_BFV
s.image_id = IMAGE_STRING_FOR_BFV
- if 'id' in s.flavor:
+ if compute_client.api_version < api_versions.APIVersion('2.47'):
flavor = flavors.get(s.flavor['id'])
if flavor:
s.flavor_name = flavor.name
s.flavor_id = s.flavor['id']
else:
- # TODO(mriedem): Fix this for microversion >= 2.47 where the
- # flavor is embedded in the server response without the id.
- # We likely need to drop the Flavor ID column in that case if
- # --long is specified.
- s.flavor_name = ''
- s.flavor_id = ''
+ s.flavor_name = s.flavor['original_name']
table = (
column_headers,