Skip to content

Commit 73d56bc

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add a few selectable fields to the "openstack server list" output"
2 parents 7d624cc + 311f413 commit 73d56bc

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
@@ -1715,6 +1715,27 @@ def take_action(self, parsed_args):
17151715

17161716
marker_id = None
17171717

1718+
# support for additional columns
1719+
if parsed_args.columns:
1720+
# convert tuple to list to edit them
1721+
column_headers = list(column_headers)
1722+
columns = list(columns)
1723+
1724+
for c in parsed_args.columns:
1725+
if c in ('Project ID', 'project_id'):
1726+
columns.append('tenant_id')
1727+
column_headers.append('Project ID')
1728+
if c in ('User ID', 'user_id'):
1729+
columns.append('user_id')
1730+
column_headers.append('User ID')
1731+
if c in ('Created At', 'created_at'):
1732+
columns.append('created_at')
1733+
column_headers.append('Created At')
1734+
1735+
# convert back to tuple
1736+
column_headers = tuple(column_headers)
1737+
columns = tuple(columns)
1738+
17181739
if parsed_args.marker:
17191740
# Check if both "--marker" and "--deleted" are used.
17201741
# 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
@@ -3129,6 +3129,25 @@ def test_server_list_long_option(self):
31293129
self.assertEqual(self.columns_long, columns)
31303130
self.assertEqual(tuple(self.data_long), tuple(data))
31313131

3132+
def test_server_list_column_option(self):
3133+
arglist = [
3134+
'-c', 'Project ID',
3135+
'-c', 'User ID',
3136+
'-c', 'Created At',
3137+
'--long'
3138+
]
3139+
verifylist = [
3140+
('long', True),
3141+
]
3142+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
3143+
3144+
columns, data = self.cmd.take_action(parsed_args)
3145+
3146+
self.servers_mock.list.assert_called_with(**self.kwargs)
3147+
self.assertIn('Project ID', columns)
3148+
self.assertIn('User ID', columns)
3149+
self.assertIn('Created At', columns)
3150+
31323151
def test_server_list_no_name_lookup_option(self):
31333152
arglist = [
31343153
'--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)