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
This commit is contained in:
Adam Harwell 2020-03-04 10:03:48 -08:00
parent cc3e82d5de
commit 1037a06b6c
5 changed files with 42 additions and 1 deletions

View File

@ -62,10 +62,19 @@ class ListAmphora(lister.Lister):
help="Filter by amphora provisioning status." help="Filter by amphora provisioning status."
) )
parser.add_argument(
'--long',
action='store_true',
help='Show additional fields.',
)
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
columns = const.AMPHORA_COLUMNS columns = const.AMPHORA_COLUMNS
if parsed_args.long:
columns = const.AMPHORA_COLUMNS_LONG
attrs = v2_utils.get_amphora_attrs(self.app.client_manager, attrs = v2_utils.get_amphora_attrs(self.app.client_manager,
parsed_args) parsed_args)

View File

@ -277,6 +277,18 @@ AMPHORA_COLUMNS = (
'ha_ip', 'ha_ip',
) )
AMPHORA_COLUMNS_LONG = (
'id',
'loadbalancer_id',
'status',
'role',
'lb_network_ip',
'ha_ip',
'compute_id',
'cached_zone',
'image_id',
)
PROVIDER_COLUMNS = ( PROVIDER_COLUMNS = (
'name', 'name',
'description', 'description',

View File

@ -30,6 +30,7 @@ AMPHORA_ATTRS = {
"vrrp_id": 1, "vrrp_id": 1,
"vrrp_priority": 200, "vrrp_priority": 200,
"cached_zone": "zone2", "cached_zone": "zone2",
"image_id": uuidutils.generate_uuid(dashed=True),
} }
HM_ATTRS = { HM_ATTRS = {

View File

@ -30,11 +30,12 @@ class TestAmphora(fakes.TestOctaviaClient):
self._amp = fakes.createFakeResource('amphora') self._amp = fakes.createFakeResource('amphora')
self.amp_info = copy.deepcopy(attr_consts.AMPHORA_ATTRS) self.amp_info = copy.deepcopy(attr_consts.AMPHORA_ATTRS)
self.columns = copy.deepcopy(constants.AMPHORA_COLUMNS) self.columns = copy.deepcopy(constants.AMPHORA_COLUMNS)
self.columns_long = copy.deepcopy(constants.AMPHORA_COLUMNS_LONG)
self.rows = copy.deepcopy(constants.AMPHORA_ROWS) self.rows = copy.deepcopy(constants.AMPHORA_ROWS)
info_list = {'amphorae': [ info_list = {'amphorae': [
{k: v for k, v in attr_consts.AMPHORA_ATTRS.items() if ( {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 = mock.Mock()
self.api_mock.amphora_list.return_value = info_list self.api_mock.amphora_list.return_value = info_list
@ -50,6 +51,8 @@ class TestAmphoraList(TestAmphora):
super(TestAmphoraList, self).setUp() super(TestAmphoraList, self).setUp()
self.data_list = (tuple( self.data_list = (tuple(
attr_consts.AMPHORA_ATTRS[k] for k in self.columns),) 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) self.cmd = amphora.ListAmphora(self.app, None)
def test_amphora_list_no_options(self): def test_amphora_list_no_options(self):
@ -63,6 +66,17 @@ class TestAmphoraList(TestAmphora):
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
self.assertEqual(self.data_list, tuple(data)) 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') @mock.patch('octaviaclient.osc.v2.utils.get_amphora_attrs')
def test_amphora_list_with_loadbalancer(self, mock_client): def test_amphora_list_with_loadbalancer(self, mock_client):
mock_client.return_value = { mock_client.return_value = {

View File

@ -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).