Add support for entrypoint

This adds entrypoint parameter when creating/running container
which overwrites the default ENTRYPOINT of the docker image.

Change-Id: Ia397176c18be5eb6c246dd4e54ac8054ecf09031
This commit is contained in:
Zhenguo Niu 2020-04-01 02:35:03 +00:00 committed by Hongbin Lu
parent 1bf684948f
commit c49246582a
6 changed files with 30 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.39'
MAX_API_VERSION = '1.40'
DEFAULT_API_VERSION = '1.latest'
_SUBSTITUTIONS = {}

View File

@ -18,6 +18,7 @@ import base64
import binascii
import os
import re
import shlex
from oslo_serialization import jsonutils
from oslo_utils import netutils
@ -211,6 +212,10 @@ def parse_command(command):
return " ".join(output)
def parse_entrypoint(entrypoint):
return shlex.split(entrypoint)
def parse_mounts(mounts):
err_msg = ("Invalid mounts argument '%s'. mounts arguments must be of "
"the form --mount source=<volume>,destination=<path>, "

View File

@ -220,6 +220,11 @@ class CreateContainer(command.ShowOne):
help='Requested host to create containers. Admin only by '
'default. (supported by --os-container-api-version 1.39 '
'or above')
parser.add_argument(
'--entrypoint',
metavar='<entrypoint>',
help='The entrypoint which overwrites the default ENTRYPOINT '
'of the image.')
return parser
def take_action(self, parsed_args):
@ -238,6 +243,7 @@ class CreateContainer(command.ShowOne):
opts['command'] = parsed_args.command
opts['registry'] = parsed_args.registry
opts['host'] = parsed_args.host
opts['entrypoint'] = zun_utils.parse_entrypoint(parsed_args.entrypoint)
if parsed_args.security_group:
opts['security_groups'] = parsed_args.security_group
if parsed_args.expose_port:
@ -917,6 +923,11 @@ class RunContainer(command.ShowOne):
help='Requested host to run containers. Admin only by '
'default. (supported by --os-container-api-version 1.39 '
'or above')
parser.add_argument(
'--entrypoint',
metavar='<entrypoint>',
help='The entrypoint which overwrites the default ENTRYPOINT '
'of the image.')
return parser
def take_action(self, parsed_args):
@ -935,6 +946,7 @@ class RunContainer(command.ShowOne):
opts['command'] = parsed_args.command
opts['registry'] = parsed_args.registry
opts['host'] = parsed_args.host
opts['entrypoint'] = zun_utils.parse_entrypoint(parsed_args.entrypoint)
if parsed_args.security_group:
opts['security_groups'] = parsed_args.security_group
if parsed_args.expose_port:

View File

@ -28,6 +28,7 @@ def _get_container_args(**kwargs):
'mounts': [],
'nets': [],
'command': [],
'entrypoint': [],
}
default_args.update(kwargs)
return default_args

View File

@ -27,7 +27,7 @@ CREATION_ATTRIBUTES = ['name', 'image', 'command', 'cpu', 'memory',
'runtime', 'hostname', 'mounts', 'disk',
'availability_zone', 'auto_heal', 'privileged',
'exposed_ports', 'healthcheck', 'registry', 'tty',
'host']
'host', 'entrypoint']
class Container(base.Resource):

View File

@ -188,6 +188,10 @@ def _show_container(container):
metavar='<host>',
help='Requested host to create containers. Admin only by default.'
'(Supported by API versions 1.39 or above)')
@utils.arg('--entrypoint',
metavar='<entrypoint>',
help='The entrypoint which overwrites the default ENTRYPOINT '
'of the image. (Supported by API versions 1.40 or above)')
def do_create(cs, args):
"""Create a container."""
opts = {}
@ -211,6 +215,7 @@ def do_create(cs, args):
opts['command'] = args.command
opts['registry'] = args.registry
opts['host'] = args.host
opts['entrypoint'] = zun_utils.parse_entrypoint(args.entrypoint)
if args.healthcheck:
opts['healthcheck'] = zun_utils.parse_health(args.healthcheck)
@ -717,6 +722,10 @@ def do_kill(cs, args):
metavar='<host>',
help='Requested host to run containers. Admin only by default.'
'(Supported by API versions 1.39 or above)')
@utils.arg('--entrypoint',
metavar='<entrypoint>',
help='The entrypoint which overwrites the default ENTRYPOINT '
'of the image. (Supported by API versions 1.40 or above)')
def do_run(cs, args):
"""Run a command in a new container."""
opts = {}
@ -740,6 +749,7 @@ def do_run(cs, args):
opts['command'] = args.command
opts['registry'] = args.registry
opts['host'] = args.host
opts['entrypoint'] = zun_utils.parse_entrypoint(args.entrypoint)
if args.healthcheck:
opts['healthcheck'] = zun_utils.parse_health(args.healthcheck)