Merge "Enhance network-list to allow --fields"

This commit is contained in:
Jenkins 2014-09-10 12:09:06 +00:00 committed by Gerrit Code Review
commit 4dbf1323cc
3 changed files with 24 additions and 2 deletions

View File

@ -1758,7 +1758,7 @@ class FakeHTTPClient(base_client.HTTPClient):
def get_os_networks(self, **kw):
return (200, {}, {'networks': [{"label": "1", "cidr": "10.0.0.0/24",
'project_id': '4ffc664c198e435e9853f2538fbcd7a7',
'id': '1'}]})
'id': '1', 'vlan': '1234'}]})
def delete_os_networks_1(self, **kw):
return (202, {}, None)

View File

@ -1699,6 +1699,13 @@ class ShellTest(utils.TestCase):
self.run_command('network-list')
self.assert_called('GET', '/os-networks')
def test_network_list_fields(self):
output = self.run_command('network-list --fields '
'vlan,project_id')
self.assert_called('GET', '/os-networks')
self.assertIn('1234', output)
self.assertIn('4ffc664c198e435e9853f2538fbcd7a7', output)
def test_network_show(self):
self.run_command('network-show 1')
self.assert_called('GET', '/os-networks/1')

View File

@ -784,10 +784,25 @@ def do_scrub(cs, args):
cs.security_groups.delete(group)
def do_network_list(cs, _args):
@utils.arg('--fields',
default=None,
metavar='<fields>',
help='Comma-separated list of fields to display. '
'Use the show command to see which fields are available.')
def do_network_list(cs, args):
"""Print a list of available networks."""
network_list = cs.networks.list()
columns = ['ID', 'Label', 'Cidr']
formatters = {}
field_titles = []
if args.fields:
for field in args.fields.split(','):
field_title, formatter = utils._make_field_formatter(field, {})
field_titles.append(field_title)
formatters[field_title] = formatter
columns = columns + field_titles
utils.print_list(network_list, columns)