diff --git a/zunclient/api_versions.py b/zunclient/api_versions.py index e932037d..87930c3d 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.22' +MAX_API_VERSION = '1.24' DEFAULT_API_VERSION = MAX_API_VERSION _SUBSTITUTIONS = {} diff --git a/zunclient/common/utils.py b/zunclient/common/utils.py index 69b68e25..cfef2f17 100644 --- a/zunclient/common/utils.py +++ b/zunclient/common/utils.py @@ -323,6 +323,10 @@ def _convert_healthcheck_para(time, err_msg): return ret +def parse_exposed_ports(ports): + return {p: {} for p in ports} + + def normalise_file_path_to_url(path): if parse.urlparse(path).scheme: return path diff --git a/zunclient/osc/v1/containers.py b/zunclient/osc/v1/containers.py index 3f4e25d5..95d4075e 100644 --- a/zunclient/osc/v1/containers.py +++ b/zunclient/osc/v1/containers.py @@ -116,12 +116,20 @@ class CreateContainer(command.ShowOne): action='store_true', default=False, help='Keep STDIN open even if not attached, allocate a pseudo-TTY') - parser.add_argument( + secgroup_expose_port_args = parser.add_mutually_exclusive_group() + secgroup_expose_port_args.add_argument( '--security-group', metavar='', action='append', default=[], help='The name of security group for the container. ' 'May be used multiple times.') + secgroup_expose_port_args.add_argument( + '--expose-port', + action='append', + default=[], + metavar='', + help='Expose container port(s) to outside (format: ' + '[/]).') parser.add_argument( 'command', metavar='', @@ -216,6 +224,9 @@ class CreateContainer(command.ShowOne): opts['command'] = parsed_args.command if parsed_args.security_group: opts['security_groups'] = parsed_args.security_group + if parsed_args.expose_port: + opts['exposed_ports'] = zun_utils.parse_exposed_ports( + parsed_args.expose_port) if parsed_args.restart: opts['restart_policy'] = \ zun_utils.check_restart_policy(parsed_args.restart) @@ -759,12 +770,20 @@ class RunContainer(command.ShowOne): action='store_true', default=False, help='Keep STDIN open even if not attached, allocate a pseudo-TTY') - parser.add_argument( + secgroup_expose_port_args = parser.add_mutually_exclusive_group() + secgroup_expose_port_args.add_argument( '--security-group', metavar='', action='append', default=[], help='The name of security group for the container. ' 'May be used multiple times.') + secgroup_expose_port_args.add_argument( + '--expose-port', + action='append', + default=[], + metavar='', + help='Expose container port(s) to outside (format: ' + '[/]).') parser.add_argument( 'command', metavar='', @@ -859,6 +878,9 @@ class RunContainer(command.ShowOne): opts['command'] = parsed_args.command if parsed_args.security_group: opts['security_groups'] = parsed_args.security_group + if parsed_args.expose_port: + opts['exposed_ports'] = zun_utils.parse_exposed_ports( + parsed_args.expose_port) if parsed_args.restart: opts['restart_policy'] = \ zun_utils.check_restart_policy(parsed_args.restart) diff --git a/zunclient/tests/unit/test_shell.py b/zunclient/tests/unit/test_shell.py index cb35d9e1..e0e8ed4f 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, cacert=None, - version=api_versions.APIVersion('1.22')) + version=api_versions.APIVersion('1.24')) 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, cacert=None, - version=api_versions.APIVersion('1.22')) + version=api_versions.APIVersion('1.24')) @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, cacert=None, - version=api_versions.APIVersion('1.22')) + version=api_versions.APIVersion('1.24')) class ShellTestKeystoneV3(ShellTest): @@ -320,4 +320,4 @@ class ShellTestKeystoneV3(ShellTest): user_domain_id='', user_domain_name='Default', endpoint_override=None, insecure=False, profile=None, cacert=None, - version=api_versions.APIVersion('1.22')) + version=api_versions.APIVersion('1.24')) diff --git a/zunclient/v1/containers.py b/zunclient/v1/containers.py index 1640ddf5..14e26409 100644 --- a/zunclient/v1/containers.py +++ b/zunclient/v1/containers.py @@ -26,7 +26,7 @@ CREATION_ATTRIBUTES = ['name', 'image', 'command', 'cpu', 'memory', 'security_groups', 'hints', 'nets', 'auto_remove', 'runtime', 'hostname', 'mounts', 'disk', 'availability_zone', 'auto_heal', 'privileged', - 'healthcheck'] + 'exposed_ports', 'healthcheck'] class Container(base.Resource): diff --git a/zunclient/v1/containers_shell.py b/zunclient/v1/containers_shell.py index a6c1534f..5cf0238f 100644 --- a/zunclient/v1/containers_shell.py +++ b/zunclient/v1/containers_shell.py @@ -56,6 +56,20 @@ def _show_container(container): required=False, metavar='', help='Restart policy to apply when a container exits' '(no, on-failure[:max-retry], always, unless-stopped)') +@utils.exclusive_arg( + 'secgroup_expose_port', + '--security-group', + metavar='', + action='append', default=[], + help='The name of security group for the container. ' + 'May be used multiple times.') +@utils.exclusive_arg( + 'secgroup_expose_port', + '-p', '--expose-port', + action='append', + default=[], + metavar='', + help='Expose container port(s) to outside (format: [/])') @utils.arg('-n', '--name', metavar='', help='name of the container') @@ -101,11 +115,6 @@ def _show_container(container): 'It can have following values: ' '"docker": pull the image from Docker Hub. ' '"glance": pull the image from Glance. ') -@utils.arg('--security-group', - metavar='', - action='append', default=[], - help='The name of security group for the container. ' - 'May be used multiple times.') @utils.arg('command', metavar='', nargs=argparse.REMAINDER, @@ -199,6 +208,8 @@ def do_create(cs, args): opts['auto_heal'] = args.auto_heal if args.security_group: opts['security_groups'] = args.security_group + if args.expose_port: + opts['exposed_ports'] = zun_utils.parse_exposed_ports(args.expose_port) if args.restart: opts['restart_policy'] = zun_utils.check_restart_policy(args.restart) if args.interactive: @@ -566,6 +577,20 @@ def do_kill(cs, args): required=False, metavar='', help='Restart policy to apply when a container exits' '(no, on-failure[:max-retry], always, unless-stopped)') +@utils.exclusive_arg( + 'secgroup_expose_port', + '--security-group', + metavar='', + action='append', default=[], + help='The name of security group for the container. ' + 'May be used multiple times.') +@utils.exclusive_arg( + 'secgroup_expose_port', + '-p', '--expose-port', + action='append', + default=[], + metavar='', + help='Expose container port(s) to outside (format: [/])') @utils.arg('-n', '--name', metavar='', help='name of the container') @@ -610,11 +635,6 @@ def do_kill(cs, args): 'It can have following values: ' '"docker": pull the image from Docker Hub. ' '"glance": pull the image from Glance. ') -@utils.arg('--security-group', - metavar='', - action='append', default=[], - help='The name of security group for the container. ' - 'May be used multiple times.') @utils.arg('command', metavar='', nargs=argparse.REMAINDER, @@ -708,6 +728,8 @@ def do_run(cs, args): opts['auto_heal'] = args.auto_heal if args.security_group: opts['security_groups'] = args.security_group + if args.expose_port: + opts['exposed_ports'] = zun_utils.parse_exposed_ports(args.expose_port) if args.restart: opts['restart_policy'] = zun_utils.check_restart_policy(args.restart) if args.interactive: