From a1f7bd28e67e27ffb2b845c01d210b709fa94023 Mon Sep 17 00:00:00 2001 From: Rajesh Tailor Date: Tue, 2 Jan 2024 18:13:36 +0530 Subject: [PATCH] Add support for showing requested az in output This change adds support for showing the availability zone requested during instance create in server show and server list --long output. Depends-On: https://review.opendev.org/c/openstack/nova/+/904568 Depends-On: https://review.opendev.org/c/openstack/openstacksdk/+/904490 Change-Id: I1772e06b4f043ef3118f036f3908ec70515144bd --- openstackclient/compute/v2/server.py | 9 +++++++++ openstackclient/tests/unit/compute/v2/test_server.py | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index bab303ebd9..be1beb1ff9 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -180,6 +180,7 @@ def _prep_server_detail(compute_client, image_client, server, refresh=True): 'updated_at': 'updated', 'user_data': 'OS-EXT-SRV-ATTR:user_data', 'vm_state': 'OS-EXT-STS:vm_state', + 'pinned_availability_zone': 'pinned_availability_zone', } # Some columns returned by openstacksdk should not be shown because they're # either irrelevant or duplicates @@ -2753,11 +2754,13 @@ class ListServer(command.Lister): if parsed_args.long: columns += ( 'availability_zone', + 'pinned_availability_zone', 'hypervisor_hostname', 'metadata', ) column_headers += ( 'Availability Zone', + 'Pinned Availability Zone', 'Host', 'Properties', ) @@ -2792,6 +2795,12 @@ class ListServer(command.Lister): if c in ('Availability Zone', "availability_zone"): columns += ('availability_zone',) column_headers += ('Availability Zone',) + if c in ( + 'pinned_availability_zone', + "Pinned Availability Zone", + ): + columns += ('Pinned Availability Zone',) + column_headers += ('Pinned Availability Zone',) if c in ('Host', "host"): columns += ('hypervisor_hostname',) column_headers += ('Host',) diff --git a/openstackclient/tests/unit/compute/v2/test_server.py b/openstackclient/tests/unit/compute/v2/test_server.py index ea944f9b33..e6d3a1da6c 100644 --- a/openstackclient/tests/unit/compute/v2/test_server.py +++ b/openstackclient/tests/unit/compute/v2/test_server.py @@ -4644,6 +4644,7 @@ class _TestServerList(TestServer): 'Flavor Name', 'Flavor ID', 'Availability Zone', + 'Pinned Availability Zone', 'Host', 'Properties', ) @@ -4785,6 +4786,7 @@ class TestServerList(_TestServerList): self.flavor.name, s.flavor['id'], getattr(s, 'availability_zone'), + getattr(s, 'pinned_availability_zone', ''), server.HostColumn(getattr(s, 'hypervisor_hostname')), format_columns.DictColumn(s.metadata), ) @@ -4830,6 +4832,8 @@ class TestServerList(_TestServerList): '-c', 'Availability Zone', '-c', + 'Pinned Availability Zone', + '-c', 'Host', '-c', 'Properties', @@ -4852,6 +4856,7 @@ class TestServerList(_TestServerList): self.assertIn('Image ID', columns) self.assertIn('Flavor ID', columns) self.assertIn('Availability Zone', columns) + self.assertIn('Pinned Availability Zone', columns) self.assertIn('Host', columns) self.assertIn('Properties', columns) self.assertCountEqual(columns, set(columns)) @@ -5264,6 +5269,7 @@ class TestServerList(_TestServerList): self.flavor.name, s.flavor['id'], getattr(s, 'availability_zone'), + getattr(s, 'pinned_availability_zone', ''), server.HostColumn(getattr(s, 'hypervisor_hostname')), format_columns.DictColumn(s.metadata), ) @@ -5318,6 +5324,7 @@ class TestServerList(_TestServerList): self.flavor.name, s.flavor['id'], getattr(s, 'availability_zone'), + getattr(s, 'pinned_availability_zone', ''), server.HostColumn(getattr(s, 'hypervisor_hostname')), format_columns.DictColumn(s.metadata), s.host_status, @@ -5354,6 +5361,7 @@ class TestServerListV273(_TestServerList): 'Image ID', 'Flavor', 'Availability Zone', + 'Pinned Availability Zone', 'Host', 'Properties', )