From 3c40b5c0933627df2f210635c242c010df308494 Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Sat, 14 Mar 2020 22:20:06 +0000 Subject: [PATCH] Add support for requested host Depends-On: https://review.opendev.org/#/c/711864/ Change-Id: Ie370f352c9f996c4f1953787b1d5b24bd723c6cc --- zunclient/api_versions.py | 2 +- zunclient/osc/v1/containers.py | 14 ++++++++++++++ zunclient/v1/containers.py | 3 ++- zunclient/v1/containers_shell.py | 10 ++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/zunclient/api_versions.py b/zunclient/api_versions.py index 0b01487b..f9f85d0b 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.38' +MAX_API_VERSION = '1.39' DEFAULT_API_VERSION = '1.latest' _SUBSTITUTIONS = {} diff --git a/zunclient/osc/v1/containers.py b/zunclient/osc/v1/containers.py index ba073c26..96694c41 100644 --- a/zunclient/osc/v1/containers.py +++ b/zunclient/osc/v1/containers.py @@ -214,6 +214,12 @@ class CreateContainer(command.ShowOne): '--registry', metavar='', help='The container image registry ID or name.') + parser.add_argument( + '--host', + metavar='', + help='Requested host to create containers. Admin only by ' + 'default. (supported by --os-container-api-version 1.39 ' + 'or above') return parser def take_action(self, parsed_args): @@ -231,6 +237,7 @@ class CreateContainer(command.ShowOne): opts['auto_remove'] = parsed_args.auto_remove opts['command'] = parsed_args.command opts['registry'] = parsed_args.registry + opts['host'] = parsed_args.host if parsed_args.security_group: opts['security_groups'] = parsed_args.security_group if parsed_args.expose_port: @@ -904,6 +911,12 @@ class RunContainer(command.ShowOne): '--registry', metavar='', help='The container image registry ID or name.') + parser.add_argument( + '--host', + metavar='', + help='Requested host to run containers. Admin only by ' + 'default. (supported by --os-container-api-version 1.39 ' + 'or above') return parser def take_action(self, parsed_args): @@ -921,6 +934,7 @@ class RunContainer(command.ShowOne): opts['auto_remove'] = parsed_args.auto_remove opts['command'] = parsed_args.command opts['registry'] = parsed_args.registry + opts['host'] = parsed_args.host if parsed_args.security_group: opts['security_groups'] = parsed_args.security_group if parsed_args.expose_port: diff --git a/zunclient/v1/containers.py b/zunclient/v1/containers.py index 14ed1f2b..04c0f86e 100644 --- a/zunclient/v1/containers.py +++ b/zunclient/v1/containers.py @@ -26,7 +26,8 @@ CREATION_ATTRIBUTES = ['name', 'image', 'command', 'cpu', 'memory', 'security_groups', 'hints', 'nets', 'auto_remove', 'runtime', 'hostname', 'mounts', 'disk', 'availability_zone', 'auto_heal', 'privileged', - 'exposed_ports', 'healthcheck', 'registry', 'tty'] + 'exposed_ports', 'healthcheck', 'registry', 'tty', + 'host'] class Container(base.Resource): diff --git a/zunclient/v1/containers_shell.py b/zunclient/v1/containers_shell.py index 340fcef4..2380a8f0 100644 --- a/zunclient/v1/containers_shell.py +++ b/zunclient/v1/containers_shell.py @@ -184,6 +184,10 @@ def _show_container(container): @utils.arg('--registry', metavar='', help='The container image registry ID or name') +@utils.arg('--host', + metavar='', + help='Requested host to create containers. Admin only by default.' + '(Supported by API versions 1.39 or above)') def do_create(cs, args): """Create a container.""" opts = {} @@ -206,6 +210,7 @@ def do_create(cs, args): opts['availability_zone'] = args.availability_zone opts['command'] = args.command opts['registry'] = args.registry + opts['host'] = args.host if args.healthcheck: opts['healthcheck'] = zun_utils.parse_health(args.healthcheck) @@ -708,6 +713,10 @@ def do_kill(cs, args): @utils.arg('--registry', metavar='', help='The container image registry ID or name') +@utils.arg('--host', + metavar='', + help='Requested host to run containers. Admin only by default.' + '(Supported by API versions 1.39 or above)') def do_run(cs, args): """Run a command in a new container.""" opts = {} @@ -730,6 +739,7 @@ def do_run(cs, args): opts['availability_zone'] = args.availability_zone opts['command'] = args.command opts['registry'] = args.registry + opts['host'] = args.host if args.healthcheck: opts['healthcheck'] = zun_utils.parse_health(args.healthcheck)