Add support for requested host

Depends-On: https://review.opendev.org/#/c/711864/
Change-Id: Ie370f352c9f996c4f1953787b1d5b24bd723c6cc
This commit is contained in:
Hongbin Lu 2020-03-14 22:20:06 +00:00
parent 3afaa59f74
commit 3c40b5c093
4 changed files with 27 additions and 2 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.38'
MAX_API_VERSION = '1.39'
DEFAULT_API_VERSION = '1.latest'
_SUBSTITUTIONS = {}

View File

@ -214,6 +214,12 @@ class CreateContainer(command.ShowOne):
'--registry',
metavar='<registry>',
help='The container image registry ID or name.')
parser.add_argument(
'--host',
metavar='<host>',
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='<registry>',
help='The container image registry ID or name.')
parser.add_argument(
'--host',
metavar='<host>',
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:

View File

@ -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):

View File

@ -184,6 +184,10 @@ def _show_container(container):
@utils.arg('--registry',
metavar='<registry>',
help='The container image registry ID or name')
@utils.arg('--host',
metavar='<host>',
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='<registry>',
help='The container image registry ID or name')
@utils.arg('--host',
metavar='<host>',
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)