Add a few selectable fields to the "openstack server list" output
Added ``-c project_id | user_id | created_at`` to ``openstack server list`` command to get these columns as an output. Change-Id: I18991adf899c7b72c98bb89871bf0715d35943f0 Story: 2007925
This commit is contained in:
parent
82ebddca00
commit
311f4130d2
@ -1446,6 +1446,27 @@ class ListServer(command.Lister):
|
||||
|
||||
marker_id = None
|
||||
|
||||
# support for additional columns
|
||||
if parsed_args.columns:
|
||||
# convert tuple to list to edit them
|
||||
column_headers = list(column_headers)
|
||||
columns = list(columns)
|
||||
|
||||
for c in parsed_args.columns:
|
||||
if c in ('Project ID', 'project_id'):
|
||||
columns.append('tenant_id')
|
||||
column_headers.append('Project ID')
|
||||
if c in ('User ID', 'user_id'):
|
||||
columns.append('user_id')
|
||||
column_headers.append('User ID')
|
||||
if c in ('Created At', 'created_at'):
|
||||
columns.append('created_at')
|
||||
column_headers.append('Created At')
|
||||
|
||||
# convert back to tuple
|
||||
column_headers = tuple(column_headers)
|
||||
columns = tuple(columns)
|
||||
|
||||
if parsed_args.marker:
|
||||
# Check if both "--marker" and "--deleted" are used.
|
||||
# In that scenario a lookup is not needed as the marker
|
||||
|
@ -2696,6 +2696,25 @@ class TestServerList(TestServer):
|
||||
self.assertEqual(self.columns_long, columns)
|
||||
self.assertEqual(tuple(self.data_long), tuple(data))
|
||||
|
||||
def test_server_list_column_option(self):
|
||||
arglist = [
|
||||
'-c', 'Project ID',
|
||||
'-c', 'User ID',
|
||||
'-c', 'Created At',
|
||||
'--long'
|
||||
]
|
||||
verifylist = [
|
||||
('long', True),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.servers_mock.list.assert_called_with(**self.kwargs)
|
||||
self.assertIn('Project ID', columns)
|
||||
self.assertIn('User ID', columns)
|
||||
self.assertIn('Created At', columns)
|
||||
|
||||
def test_server_list_no_name_lookup_option(self):
|
||||
arglist = [
|
||||
'--no-name-lookup',
|
||||
|
@ -0,0 +1,4 @@
|
||||
---
|
||||
features:
|
||||
- Add ``--c project_id | user_id | created_at`` to ``openstack server list``
|
||||
command to get these columns as an output.
|
Loading…
Reference in New Issue
Block a user