Add network-list to zunclient

This change adds network list support to the python-zunclient project
for the network-list command.

The zun command network-list is now:
    zun network-list <container>

Change-Id: I59f1fc63989796a1623ebc62c0dfae8e2dd33be8
This commit is contained in:
caishan 2018-03-15 03:08:30 -07:00
parent 1ebfddc19d
commit 6dcca2ee42
4 changed files with 24 additions and 5 deletions

View File

@ -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.12'
MAX_API_VERSION = '1.13'
DEFAULT_API_VERSION = MAX_API_VERSION
_SUBSTITUTIONS = {}

View File

@ -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.12'))
version=api_versions.APIVersion('1.13'))
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.12'))
version=api_versions.APIVersion('1.13'))
@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.12'))
version=api_versions.APIVersion('1.13'))
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.12'))
version=api_versions.APIVersion('1.13'))

View File

@ -216,6 +216,10 @@ class ContainerManager(base.Manager):
return self._action(container, '/network_attach',
qparams={'network': network})
def network_list(self, container):
return self._list(self._path(container) + '/network_list',
"networks")
def remove_security_group(self, id, security_group):
return self._action(id, '/remove_security_group',
qparams={'name': security_group})

View File

@ -783,6 +783,21 @@ def do_network_attach(cs, args):
"failed: %(e)s" % {'container': args.container, 'e': e})
@utils.arg('container',
metavar='<container>',
help='ID or name of the container to display network info.')
def do_network_list(cs, args):
"""List networks on a container"""
opts = {}
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)
@utils.arg('container',
metavar='<container>',
help='ID or name of the container to remove security group.')