Merge "Introduce an option to expose container ports"
This commit is contained in:
@@ -31,7 +31,7 @@ if not LOG.handlers:
|
|||||||
HEADER_NAME = "OpenStack-API-Version"
|
HEADER_NAME = "OpenStack-API-Version"
|
||||||
SERVICE_TYPE = "container"
|
SERVICE_TYPE = "container"
|
||||||
MIN_API_VERSION = '1.1'
|
MIN_API_VERSION = '1.1'
|
||||||
MAX_API_VERSION = '1.22'
|
MAX_API_VERSION = '1.24'
|
||||||
DEFAULT_API_VERSION = MAX_API_VERSION
|
DEFAULT_API_VERSION = MAX_API_VERSION
|
||||||
|
|
||||||
_SUBSTITUTIONS = {}
|
_SUBSTITUTIONS = {}
|
||||||
|
@@ -323,6 +323,10 @@ def _convert_healthcheck_para(time, err_msg):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
def parse_exposed_ports(ports):
|
||||||
|
return {p: {} for p in ports}
|
||||||
|
|
||||||
|
|
||||||
def normalise_file_path_to_url(path):
|
def normalise_file_path_to_url(path):
|
||||||
if parse.urlparse(path).scheme:
|
if parse.urlparse(path).scheme:
|
||||||
return path
|
return path
|
||||||
|
@@ -116,12 +116,20 @@ class CreateContainer(command.ShowOne):
|
|||||||
action='store_true',
|
action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
help='Keep STDIN open even if not attached, allocate a pseudo-TTY')
|
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',
|
'--security-group',
|
||||||
metavar='<security_group>',
|
metavar='<security_group>',
|
||||||
action='append', default=[],
|
action='append', default=[],
|
||||||
help='The name of security group for the container. '
|
help='The name of security group for the container. '
|
||||||
'May be used multiple times.')
|
'May be used multiple times.')
|
||||||
|
secgroup_expose_port_args.add_argument(
|
||||||
|
'--expose-port',
|
||||||
|
action='append',
|
||||||
|
default=[],
|
||||||
|
metavar='<port>',
|
||||||
|
help='Expose container port(s) to outside (format: '
|
||||||
|
'<port>[/<protocol>]).')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'command',
|
'command',
|
||||||
metavar='<command>',
|
metavar='<command>',
|
||||||
@@ -216,6 +224,9 @@ class CreateContainer(command.ShowOne):
|
|||||||
opts['command'] = parsed_args.command
|
opts['command'] = parsed_args.command
|
||||||
if parsed_args.security_group:
|
if parsed_args.security_group:
|
||||||
opts['security_groups'] = 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:
|
if parsed_args.restart:
|
||||||
opts['restart_policy'] = \
|
opts['restart_policy'] = \
|
||||||
zun_utils.check_restart_policy(parsed_args.restart)
|
zun_utils.check_restart_policy(parsed_args.restart)
|
||||||
@@ -759,12 +770,20 @@ class RunContainer(command.ShowOne):
|
|||||||
action='store_true',
|
action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
help='Keep STDIN open even if not attached, allocate a pseudo-TTY')
|
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',
|
'--security-group',
|
||||||
metavar='<security_group>',
|
metavar='<security_group>',
|
||||||
action='append', default=[],
|
action='append', default=[],
|
||||||
help='The name of security group for the container. '
|
help='The name of security group for the container. '
|
||||||
'May be used multiple times.')
|
'May be used multiple times.')
|
||||||
|
secgroup_expose_port_args.add_argument(
|
||||||
|
'--expose-port',
|
||||||
|
action='append',
|
||||||
|
default=[],
|
||||||
|
metavar='<port>',
|
||||||
|
help='Expose container port(s) to outside (format: '
|
||||||
|
'<port>[/<protocol>]).')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'command',
|
'command',
|
||||||
metavar='<command>',
|
metavar='<command>',
|
||||||
@@ -859,6 +878,9 @@ class RunContainer(command.ShowOne):
|
|||||||
opts['command'] = parsed_args.command
|
opts['command'] = parsed_args.command
|
||||||
if parsed_args.security_group:
|
if parsed_args.security_group:
|
||||||
opts['security_groups'] = 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:
|
if parsed_args.restart:
|
||||||
opts['restart_policy'] = \
|
opts['restart_policy'] = \
|
||||||
zun_utils.check_restart_policy(parsed_args.restart)
|
zun_utils.check_restart_policy(parsed_args.restart)
|
||||||
|
@@ -246,7 +246,7 @@ class ShellTest(utils.TestCase):
|
|||||||
project_domain_id='', project_domain_name='',
|
project_domain_id='', project_domain_name='',
|
||||||
user_domain_id='', user_domain_name='', profile=None,
|
user_domain_id='', user_domain_name='', profile=None,
|
||||||
endpoint_override=None, insecure=False, cacert=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):
|
def test_main_option_region(self):
|
||||||
self.make_env()
|
self.make_env()
|
||||||
@@ -274,7 +274,7 @@ class ShellTest(utils.TestCase):
|
|||||||
project_domain_id='', project_domain_name='',
|
project_domain_id='', project_domain_name='',
|
||||||
user_domain_id='', user_domain_name='', profile=None,
|
user_domain_id='', user_domain_name='', profile=None,
|
||||||
endpoint_override=None, insecure=False, cacert=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')
|
@mock.patch('zunclient.client.Client')
|
||||||
def test_main_endpoint_internal(self, mock_client):
|
def test_main_endpoint_internal(self, mock_client):
|
||||||
@@ -288,7 +288,7 @@ class ShellTest(utils.TestCase):
|
|||||||
project_domain_id='', project_domain_name='',
|
project_domain_id='', project_domain_name='',
|
||||||
user_domain_id='', user_domain_name='', profile=None,
|
user_domain_id='', user_domain_name='', profile=None,
|
||||||
endpoint_override=None, insecure=False, cacert=None,
|
endpoint_override=None, insecure=False, cacert=None,
|
||||||
version=api_versions.APIVersion('1.22'))
|
version=api_versions.APIVersion('1.24'))
|
||||||
|
|
||||||
|
|
||||||
class ShellTestKeystoneV3(ShellTest):
|
class ShellTestKeystoneV3(ShellTest):
|
||||||
@@ -320,4 +320,4 @@ class ShellTestKeystoneV3(ShellTest):
|
|||||||
user_domain_id='', user_domain_name='Default',
|
user_domain_id='', user_domain_name='Default',
|
||||||
endpoint_override=None, insecure=False, profile=None,
|
endpoint_override=None, insecure=False, profile=None,
|
||||||
cacert=None,
|
cacert=None,
|
||||||
version=api_versions.APIVersion('1.22'))
|
version=api_versions.APIVersion('1.24'))
|
||||||
|
@@ -26,7 +26,7 @@ CREATION_ATTRIBUTES = ['name', 'image', 'command', 'cpu', 'memory',
|
|||||||
'security_groups', 'hints', 'nets', 'auto_remove',
|
'security_groups', 'hints', 'nets', 'auto_remove',
|
||||||
'runtime', 'hostname', 'mounts', 'disk',
|
'runtime', 'hostname', 'mounts', 'disk',
|
||||||
'availability_zone', 'auto_heal', 'privileged',
|
'availability_zone', 'auto_heal', 'privileged',
|
||||||
'healthcheck']
|
'exposed_ports', 'healthcheck']
|
||||||
|
|
||||||
|
|
||||||
class Container(base.Resource):
|
class Container(base.Resource):
|
||||||
|
@@ -56,6 +56,20 @@ def _show_container(container):
|
|||||||
required=False, metavar='<restart>',
|
required=False, metavar='<restart>',
|
||||||
help='Restart policy to apply when a container exits'
|
help='Restart policy to apply when a container exits'
|
||||||
'(no, on-failure[:max-retry], always, unless-stopped)')
|
'(no, on-failure[:max-retry], always, unless-stopped)')
|
||||||
|
@utils.exclusive_arg(
|
||||||
|
'secgroup_expose_port',
|
||||||
|
'--security-group',
|
||||||
|
metavar='<security-group>',
|
||||||
|
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='<port>',
|
||||||
|
help='Expose container port(s) to outside (format: <port>[/<protocol>])')
|
||||||
@utils.arg('-n', '--name',
|
@utils.arg('-n', '--name',
|
||||||
metavar='<name>',
|
metavar='<name>',
|
||||||
help='name of the container')
|
help='name of the container')
|
||||||
@@ -101,11 +115,6 @@ def _show_container(container):
|
|||||||
'It can have following values: '
|
'It can have following values: '
|
||||||
'"docker": pull the image from Docker Hub. '
|
'"docker": pull the image from Docker Hub. '
|
||||||
'"glance": pull the image from Glance. ')
|
'"glance": pull the image from Glance. ')
|
||||||
@utils.arg('--security-group',
|
|
||||||
metavar='<security-group>',
|
|
||||||
action='append', default=[],
|
|
||||||
help='The name of security group for the container. '
|
|
||||||
'May be used multiple times.')
|
|
||||||
@utils.arg('command',
|
@utils.arg('command',
|
||||||
metavar='<command>',
|
metavar='<command>',
|
||||||
nargs=argparse.REMAINDER,
|
nargs=argparse.REMAINDER,
|
||||||
@@ -199,6 +208,8 @@ def do_create(cs, args):
|
|||||||
opts['auto_heal'] = args.auto_heal
|
opts['auto_heal'] = args.auto_heal
|
||||||
if args.security_group:
|
if args.security_group:
|
||||||
opts['security_groups'] = 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:
|
if args.restart:
|
||||||
opts['restart_policy'] = zun_utils.check_restart_policy(args.restart)
|
opts['restart_policy'] = zun_utils.check_restart_policy(args.restart)
|
||||||
if args.interactive:
|
if args.interactive:
|
||||||
@@ -566,6 +577,20 @@ def do_kill(cs, args):
|
|||||||
required=False, metavar='<restart>',
|
required=False, metavar='<restart>',
|
||||||
help='Restart policy to apply when a container exits'
|
help='Restart policy to apply when a container exits'
|
||||||
'(no, on-failure[:max-retry], always, unless-stopped)')
|
'(no, on-failure[:max-retry], always, unless-stopped)')
|
||||||
|
@utils.exclusive_arg(
|
||||||
|
'secgroup_expose_port',
|
||||||
|
'--security-group',
|
||||||
|
metavar='<security-group>',
|
||||||
|
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='<port>',
|
||||||
|
help='Expose container port(s) to outside (format: <port>[/<protocol>])')
|
||||||
@utils.arg('-n', '--name',
|
@utils.arg('-n', '--name',
|
||||||
metavar='<name>',
|
metavar='<name>',
|
||||||
help='name of the container')
|
help='name of the container')
|
||||||
@@ -610,11 +635,6 @@ def do_kill(cs, args):
|
|||||||
'It can have following values: '
|
'It can have following values: '
|
||||||
'"docker": pull the image from Docker Hub. '
|
'"docker": pull the image from Docker Hub. '
|
||||||
'"glance": pull the image from Glance. ')
|
'"glance": pull the image from Glance. ')
|
||||||
@utils.arg('--security-group',
|
|
||||||
metavar='<security-group>',
|
|
||||||
action='append', default=[],
|
|
||||||
help='The name of security group for the container. '
|
|
||||||
'May be used multiple times.')
|
|
||||||
@utils.arg('command',
|
@utils.arg('command',
|
||||||
metavar='<command>',
|
metavar='<command>',
|
||||||
nargs=argparse.REMAINDER,
|
nargs=argparse.REMAINDER,
|
||||||
@@ -708,6 +728,8 @@ def do_run(cs, args):
|
|||||||
opts['auto_heal'] = args.auto_heal
|
opts['auto_heal'] = args.auto_heal
|
||||||
if args.security_group:
|
if args.security_group:
|
||||||
opts['security_groups'] = 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:
|
if args.restart:
|
||||||
opts['restart_policy'] = zun_utils.check_restart_policy(args.restart)
|
opts['restart_policy'] = zun_utils.check_restart_policy(args.restart)
|
||||||
if args.interactive:
|
if args.interactive:
|
||||||
|
Reference in New Issue
Block a user