diff --git a/zunclient/api_versions.py b/zunclient/api_versions.py index 32687654..d699254e 100644 --- a/zunclient/api_versions.py +++ b/zunclient/api_versions.py @@ -31,7 +31,7 @@ if not LOG.handlers: HEADER_NAME = "OpenStack-API-Version" SERVICE_TYPE = "container" MIN_API_VERSION = '1.1' -MAX_API_VERSION = '1.17' +MAX_API_VERSION = '1.18' DEFAULT_API_VERSION = MAX_API_VERSION _SUBSTITUTIONS = {} diff --git a/zunclient/common/utils.py b/zunclient/common/utils.py index fb79636e..5585b6dd 100644 --- a/zunclient/common/utils.py +++ b/zunclient/common/utils.py @@ -295,3 +295,21 @@ def list_capsules(capsules): utils.print_list(capsules, columns, {'versions': print_list_field('versions')}, sortby_index=None) + + +def format_fixed_ips(fixed_ips): + if fixed_ips is None: + return None + + return ",".join([fip['ip_address'] for fip in fixed_ips]) + + +def format_network_fixed_ips(network): + return format_fixed_ips(network.fixed_ips) + + +def list_container_networks(networks): + columns = ('net_id', 'port_id', 'fixed_ips') + utils.print_list(networks, columns, + {'fixed_ips': format_network_fixed_ips}, + sortby_index=None) diff --git a/zunclient/osc/v1/containers.py b/zunclient/osc/v1/containers.py index 8687f39f..49d27330 100644 --- a/zunclient/osc/v1/containers.py +++ b/zunclient/osc/v1/containers.py @@ -1245,6 +1245,8 @@ class NetworkList(command.Lister): opts['container'] = parsed_args.container opts = zun_utils.remove_null_parms(**opts) networks = client.containers.network_list(**opts) - columns = ('net_id', 'subnet_id', 'port_id', 'version', 'ip_address') - return (columns, (utils.get_item_properties(network, columns) - for network in networks)) + columns = ('net_id', 'port_id', 'fixed_ips') + return (columns, (utils.get_item_properties( + network, columns, formatters={ + 'fixed_ips': zun_utils.format_fixed_ips}) + for network in networks)) diff --git a/zunclient/tests/unit/test_shell.py b/zunclient/tests/unit/test_shell.py index 9be64319..bec78a80 100644 --- a/zunclient/tests/unit/test_shell.py +++ b/zunclient/tests/unit/test_shell.py @@ -246,7 +246,7 @@ class ShellTest(utils.TestCase): project_domain_id='', project_domain_name='', user_domain_id='', user_domain_name='', profile=None, endpoint_override=None, insecure=False, - version=api_versions.APIVersion('1.17')) + version=api_versions.APIVersion('1.18')) def test_main_option_region(self): self.make_env() @@ -274,7 +274,7 @@ class ShellTest(utils.TestCase): project_domain_id='', project_domain_name='', user_domain_id='', user_domain_name='', profile=None, endpoint_override=None, insecure=False, - version=api_versions.APIVersion('1.17')) + version=api_versions.APIVersion('1.18')) @mock.patch('zunclient.client.Client') def test_main_endpoint_internal(self, mock_client): @@ -288,7 +288,7 @@ class ShellTest(utils.TestCase): project_domain_id='', project_domain_name='', user_domain_id='', user_domain_name='', profile=None, endpoint_override=None, insecure=False, - version=api_versions.APIVersion('1.17')) + version=api_versions.APIVersion('1.18')) class ShellTestKeystoneV3(ShellTest): @@ -319,4 +319,4 @@ class ShellTestKeystoneV3(ShellTest): project_domain_id='', project_domain_name='Default', user_domain_id='', user_domain_name='Default', endpoint_override=None, insecure=False, profile=None, - version=api_versions.APIVersion('1.17')) + version=api_versions.APIVersion('1.18')) diff --git a/zunclient/tests/unit/v1/test_containers.py b/zunclient/tests/unit/v1/test_containers.py index 20ca29f4..facd605f 100644 --- a/zunclient/tests/unit/v1/test_containers.py +++ b/zunclient/tests/unit/v1/test_containers.py @@ -59,6 +59,14 @@ CONTAINER2 = {'id': '1235', 'auto_heal': False } +NETWORK1 = {'net_id': '99e90853-e1fd-4c57-a116-9e335deaa592', + 'port_id': '83f39a10-45c8-4463-a274-5a7cda3e6c97', + 'fixed_ips': [{ + 'ip_address': '10.0.0.7', 'version': 4, + 'subnet_id': '5899aa85-c98f-4d1d-bc8f-99fed7bde5b9'}] + } + + CREATE_CONTAINER1 = copy.deepcopy(CONTAINER1) del CREATE_CONTAINER1['id'] del CREATE_CONTAINER1['uuid'] @@ -330,6 +338,14 @@ fake_responses = { None, ), }, + '/v1/containers/%s/network_list' + % (CONTAINER1['id']): + { + 'GET': ( + {}, + {'networks': NETWORK1}, + ), + }, '/v1/containers/%s/remove_security_group?%s' % (CONTAINER1['id'], parse.urlencode({'name': security_group})): { @@ -700,6 +716,15 @@ class ContainerManagerTest(testtools.TestCase): self.assertEqual(expect, self.api.calls) self.assertTrue(containers) + def test_containers_network_list(self): + networks = self.mgr.network_list(CONTAINER1['id']) + expect = [ + ('GET', '/v1/containers/%s/network_list' + % (CONTAINER1['id']), {}, None) + ] + self.assertEqual(expect, self.api.calls) + self.assertTrue(networks) + def test_containers_remove_security_group(self): containers = self.mgr.remove_security_group( CONTAINER1['id'], security_group) diff --git a/zunclient/v1/containers_shell.py b/zunclient/v1/containers_shell.py index ce12241b..1e1cd216 100644 --- a/zunclient/v1/containers_shell.py +++ b/zunclient/v1/containers_shell.py @@ -913,10 +913,7 @@ def do_network_list(cs, args): opts['container'] = args.container opts = zun_utils.remove_null_parms(**opts) networks = cs.containers.network_list(**opts) - columns = ('net_id', 'subnet_id', 'port_id', 'version', 'ip_address') - utils.print_list(networks, columns, - {'versions': zun_utils.print_list_field('versions')}, - sortby_index=None) + zun_utils.list_container_networks(networks) @utils.arg('container',