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:35:10 +0000
commit4b7e777c0ce19aa67a9a33cbeb3b4ee2b052383f (patch)
tree9ed5333a0d29bab74c8ba552021cd9b1ad1595d9 /openstackclient/compute
parentcb621f22d4547c20f5722058be8d99de936a48c6 (diff)
downloadpython-openstackclient-4b7e777c0ce19aa67a9a33cbeb3b4ee2b052383f.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) (cherry picked from commit 0873e7580eceab07c3be0824d2ea4163491f8d6e)
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 26764084..ff10b57e 100644
--- a/openstackclient/compute/v2/server.py
+++ b/openstackclient/compute/v2/server.py
@@ -2300,21 +2300,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 += (
@@ -2438,18 +2445,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,