Skip to content

Commit 311f413

Browse files
author
jay
committed
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
1 parent 82ebddc commit 311f413

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

openstackclient/compute/v2/server.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,27 @@ def take_action(self, parsed_args):
14461446

14471447
marker_id = None
14481448

1449+
# support for additional columns
1450+
if parsed_args.columns:
1451+
# convert tuple to list to edit them
1452+
column_headers = list(column_headers)
1453+
columns = list(columns)
1454+
1455+
for c in parsed_args.columns:
1456+
if c in ('Project ID', 'project_id'):
1457+
columns.append('tenant_id')
1458+
column_headers.append('Project ID')
1459+
if c in ('User ID', 'user_id'):
1460+
columns.append('user_id')
1461+
column_headers.append('User ID')
1462+
if c in ('Created At', 'created_at'):
1463+
columns.append('created_at')
1464+
column_headers.append('Created At')
1465+
1466+
# convert back to tuple
1467+
column_headers = tuple(column_headers)
1468+
columns = tuple(columns)
1469+
14491470
if parsed_args.marker:
14501471
# Check if both "--marker" and "--deleted" are used.
14511472
# In that scenario a lookup is not needed as the marker

openstackclient/tests/unit/compute/v2/test_server.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2696,6 +2696,25 @@ def test_server_list_long_option(self):
26962696
self.assertEqual(self.columns_long, columns)
26972697
self.assertEqual(tuple(self.data_long), tuple(data))
26982698

2699+
def test_server_list_column_option(self):
2700+
arglist = [
2701+
'-c', 'Project ID',
2702+
'-c', 'User ID',
2703+
'-c', 'Created At',
2704+
'--long'
2705+
]
2706+
verifylist = [
2707+
('long', True),
2708+
]
2709+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
2710+
2711+
columns, data = self.cmd.take_action(parsed_args)
2712+
2713+
self.servers_mock.list.assert_called_with(**self.kwargs)
2714+
self.assertIn('Project ID', columns)
2715+
self.assertIn('User ID', columns)
2716+
self.assertIn('Created At', columns)
2717+
26992718
def test_server_list_no_name_lookup_option(self):
27002719
arglist = [
27012720
'--no-name-lookup',
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
features:
3+
- Add ``--c project_id | user_id | created_at`` to ``openstack server list``
4+
command to get these columns as an output.

0 commit comments

Comments
 (0)