From 1037a06b6cdacbd628e8a2aad17f5d88b8edf2b8 Mon Sep 17 00:00:00 2001 From: Adam Harwell Date: Wed, 4 Mar 2020 10:03:48 -0800 Subject: [PATCH] Add --long to amphora-list to show more columns Often when looking at lists of amphorae, I really need to quickly browse them based on image/zone/compute_id, and this makes it much easier and fewer API-roundtrips to get that data. The API already returns it, we can just show it (optionally)! Change-Id: I229392b5b324e92909ea417696a3652492274613 --- octaviaclient/osc/v2/amphora.py | 9 +++++++++ octaviaclient/osc/v2/constants.py | 12 ++++++++++++ octaviaclient/tests/unit/osc/v2/constants.py | 1 + octaviaclient/tests/unit/osc/v2/test_amphora.py | 16 +++++++++++++++- ...mphora-list-long-option-55390b5abef5b82e.yaml | 5 +++++ 5 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/amphora-list-long-option-55390b5abef5b82e.yaml diff --git a/octaviaclient/osc/v2/amphora.py b/octaviaclient/osc/v2/amphora.py index 387162b..149e03b 100644 --- a/octaviaclient/osc/v2/amphora.py +++ b/octaviaclient/osc/v2/amphora.py @@ -62,10 +62,19 @@ class ListAmphora(lister.Lister): help="Filter by amphora provisioning status." ) + parser.add_argument( + '--long', + action='store_true', + help='Show additional fields.', + ) + return parser def take_action(self, parsed_args): columns = const.AMPHORA_COLUMNS + if parsed_args.long: + columns = const.AMPHORA_COLUMNS_LONG + attrs = v2_utils.get_amphora_attrs(self.app.client_manager, parsed_args) diff --git a/octaviaclient/osc/v2/constants.py b/octaviaclient/osc/v2/constants.py index b07551e..f561daa 100644 --- a/octaviaclient/osc/v2/constants.py +++ b/octaviaclient/osc/v2/constants.py @@ -277,6 +277,18 @@ AMPHORA_COLUMNS = ( 'ha_ip', ) +AMPHORA_COLUMNS_LONG = ( + 'id', + 'loadbalancer_id', + 'status', + 'role', + 'lb_network_ip', + 'ha_ip', + 'compute_id', + 'cached_zone', + 'image_id', +) + PROVIDER_COLUMNS = ( 'name', 'description', diff --git a/octaviaclient/tests/unit/osc/v2/constants.py b/octaviaclient/tests/unit/osc/v2/constants.py index 7821c5e..5c7b717 100644 --- a/octaviaclient/tests/unit/osc/v2/constants.py +++ b/octaviaclient/tests/unit/osc/v2/constants.py @@ -30,6 +30,7 @@ AMPHORA_ATTRS = { "vrrp_id": 1, "vrrp_priority": 200, "cached_zone": "zone2", + "image_id": uuidutils.generate_uuid(dashed=True), } HM_ATTRS = { diff --git a/octaviaclient/tests/unit/osc/v2/test_amphora.py b/octaviaclient/tests/unit/osc/v2/test_amphora.py index f6c0d0d..aaf37cf 100644 --- a/octaviaclient/tests/unit/osc/v2/test_amphora.py +++ b/octaviaclient/tests/unit/osc/v2/test_amphora.py @@ -30,11 +30,12 @@ class TestAmphora(fakes.TestOctaviaClient): self._amp = fakes.createFakeResource('amphora') self.amp_info = copy.deepcopy(attr_consts.AMPHORA_ATTRS) self.columns = copy.deepcopy(constants.AMPHORA_COLUMNS) + self.columns_long = copy.deepcopy(constants.AMPHORA_COLUMNS_LONG) self.rows = copy.deepcopy(constants.AMPHORA_ROWS) info_list = {'amphorae': [ {k: v for k, v in attr_consts.AMPHORA_ATTRS.items() if ( - k in self.columns)}, + k in self.columns_long)}, ]} self.api_mock = mock.Mock() self.api_mock.amphora_list.return_value = info_list @@ -50,6 +51,8 @@ class TestAmphoraList(TestAmphora): super(TestAmphoraList, self).setUp() self.data_list = (tuple( attr_consts.AMPHORA_ATTRS[k] for k in self.columns),) + self.data_list_long = (tuple( + attr_consts.AMPHORA_ATTRS[k] for k in self.columns_long),) self.cmd = amphora.ListAmphora(self.app, None) def test_amphora_list_no_options(self): @@ -63,6 +66,17 @@ class TestAmphoraList(TestAmphora): self.assertEqual(self.columns, columns) self.assertEqual(self.data_list, tuple(data)) + def test_amphora_list_long(self): + arglist = ['--long'] + verify_list = [] + + parsed_args = self.check_parser(self.cmd, arglist, verify_list) + columns, data = self.cmd.take_action(parsed_args) + + self.api_mock.amphora_list.assert_called_with() + self.assertEqual(self.columns_long, columns) + self.assertEqual(self.data_list_long, tuple(data)) + @mock.patch('octaviaclient.osc.v2.utils.get_amphora_attrs') def test_amphora_list_with_loadbalancer(self, mock_client): mock_client.return_value = { diff --git a/releasenotes/notes/amphora-list-long-option-55390b5abef5b82e.yaml b/releasenotes/notes/amphora-list-long-option-55390b5abef5b82e.yaml new file mode 100644 index 0000000..183c495 --- /dev/null +++ b/releasenotes/notes/amphora-list-long-option-55390b5abef5b82e.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Amphora list now supports a ``--long`` option, which will include a few + additional columns (compute_id, cached_zone, image_id). \ No newline at end of file