Introduce an option to expose container ports
This is the client side implementation of exposed container's ports. In particular, it adds an option '-p' or '--expose-port' to the container create/run command. For example: zun run -p 80/tcp nginx Depends-On: Id713ce602dca8e74089d4a5eea8df41ea8784db4 Change-Id: Iafb1f446e203bdcb5f103d4a73f4124db57868e4 Partial-Implements: blueprint support-port-bindings
This commit is contained in:
parent
a2cdcb9097
commit
e9d12ab488
@ -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 = {}
|
||||
|
@ -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
|
||||
|
@ -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='<security_group>',
|
||||
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='<port>',
|
||||
help='Expose container port(s) to outside (format: '
|
||||
'<port>[/<protocol>]).')
|
||||
parser.add_argument(
|
||||
'command',
|
||||
metavar='<command>',
|
||||
@ -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)
|
||||
@ -758,12 +769,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='<security_group>',
|
||||
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='<port>',
|
||||
help='Expose container port(s) to outside (format: '
|
||||
'<port>[/<protocol>]).')
|
||||
parser.add_argument(
|
||||
'command',
|
||||
metavar='<command>',
|
||||
@ -858,6 +877,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)
|
||||
|
@ -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'))
|
||||
|
@ -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):
|
||||
|
@ -50,6 +50,20 @@ def _show_container(container):
|
||||
required=False, metavar='<restart>',
|
||||
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='<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',
|
||||
metavar='<name>',
|
||||
help='name of the container')
|
||||
@ -95,11 +109,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='<security-group>',
|
||||
action='append', default=[],
|
||||
help='The name of security group for the container. '
|
||||
'May be used multiple times.')
|
||||
@utils.arg('command',
|
||||
metavar='<command>',
|
||||
nargs=argparse.REMAINDER,
|
||||
@ -192,6 +201,8 @@ def do_create(cs, args):
|
||||
|
||||
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:
|
||||
@ -559,6 +570,20 @@ def do_kill(cs, args):
|
||||
required=False, metavar='<restart>',
|
||||
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='<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',
|
||||
metavar='<name>',
|
||||
help='name of the container')
|
||||
@ -603,11 +628,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='<security-group>',
|
||||
action='append', default=[],
|
||||
help='The name of security group for the container. '
|
||||
'May be used multiple times.')
|
||||
@utils.arg('command',
|
||||
metavar='<command>',
|
||||
nargs=argparse.REMAINDER,
|
||||
@ -700,6 +720,8 @@ def do_run(cs, args):
|
||||
|
||||
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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user