Merge "Autoremove container added to zun run client"
This commit is contained in:
commit
bfe14b8000
@ -30,6 +30,7 @@ if not LOG.handlers:
|
||||
|
||||
HEADER_NAME = "OpenStack-API-Version"
|
||||
SERVICE_TYPE = "container"
|
||||
DEFAULT_API_VERSION = '1.3'
|
||||
|
||||
_SUBSTITUTIONS = {}
|
||||
|
||||
|
@ -17,13 +17,12 @@ from osc_lib import utils
|
||||
|
||||
from zunclient import api_versions
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
DEFAULT_CONTAINER_API_VERSION = "1.2"
|
||||
DEFAULT_CONTAINER_API_VERSION = api_versions.DEFAULT_API_VERSION
|
||||
API_VERSION_OPTION = "os_container_api_version"
|
||||
API_NAME = "container"
|
||||
LAST_KNOWN_API_VERSION = 2
|
||||
LAST_KNOWN_API_VERSION = 3
|
||||
API_VERSIONS = {
|
||||
'1.%d' % i: 'zunclient.v1.client.Client'
|
||||
for i in range(1, LAST_KNOWN_API_VERSION + 1)
|
||||
@ -40,12 +39,14 @@ def make_client(instance):
|
||||
LOG.debug("Instantiating zun client: {0}".format(
|
||||
zun_client))
|
||||
|
||||
# TODO(hongbin): Instead of hard-coding api-version to 'latest', it is
|
||||
# better to read micro-version from CLI (bug #1701939).
|
||||
api_version = api_versions.get_api_version(instance._api_version[API_NAME])
|
||||
client = zun_client(
|
||||
api_version=api_version,
|
||||
region_name=instance._region_name,
|
||||
session=instance.session,
|
||||
service_type='container',
|
||||
api_version=api_version,
|
||||
)
|
||||
return client
|
||||
|
||||
@ -70,6 +71,7 @@ def build_option_parser(parser):
|
||||
|
||||
class ReplaceLatestVersion(argparse.Action):
|
||||
"""Replaces `latest` keyword by last known version."""
|
||||
|
||||
def __call__(self, parser, namespace, values, option_string=None):
|
||||
latest = values == 'latest'
|
||||
if latest:
|
||||
|
@ -138,6 +138,12 @@ class CreateContainer(command.ShowOne):
|
||||
' port: attach container to the neutron port with this UUID. '
|
||||
'v4-fixed-ip: IPv4 fixed address for container. '
|
||||
'v6-fixed-ip: IPv6 fixed address for container.')
|
||||
parser.add_argument(
|
||||
'--rm',
|
||||
dest='auto_remove',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='Automatically remove the container when it exits')
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
@ -152,6 +158,7 @@ class CreateContainer(command.ShowOne):
|
||||
opts['labels'] = zun_utils.format_args(parsed_args.label)
|
||||
opts['image_pull_policy'] = parsed_args.image_pull_policy
|
||||
opts['image_driver'] = parsed_args.image_driver
|
||||
opts['auto_remove'] = parsed_args.auto_remove
|
||||
if parsed_args.security_group:
|
||||
opts['security_groups'] = parsed_args.security_group
|
||||
if parsed_args.command:
|
||||
@ -661,6 +668,12 @@ class RunContainer(command.ShowOne):
|
||||
' port: attach container to the neutron port with this UUID. '
|
||||
'v4-fixed-ip: IPv4 fixed address for container. '
|
||||
'v6-fixed-ip: IPv6 fixed address for container.')
|
||||
parser.add_argument(
|
||||
'--rm',
|
||||
dest='auto_remove',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='Automatically remove the container when it exits')
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
@ -675,6 +688,7 @@ class RunContainer(command.ShowOne):
|
||||
opts['labels'] = zun_utils.format_args(parsed_args.label)
|
||||
opts['image_pull_policy'] = parsed_args.image_pull_policy
|
||||
opts['image_driver'] = parsed_args.image_driver
|
||||
opts['auto_remove'] = parsed_args.auto_remove
|
||||
if parsed_args.security_group:
|
||||
opts['security_groups'] = parsed_args.security_group
|
||||
if parsed_args.command:
|
||||
|
@ -61,7 +61,7 @@ from zunclient.v1 import client as client_v1
|
||||
from zunclient.v1 import shell as shell_v1
|
||||
from zunclient import version
|
||||
|
||||
DEFAULT_API_VERSION = '1.2'
|
||||
DEFAULT_API_VERSION = api_versions.DEFAULT_API_VERSION
|
||||
DEFAULT_ENDPOINT_TYPE = 'publicURL'
|
||||
DEFAULT_SERVICE_TYPE = 'container'
|
||||
|
||||
|
@ -249,7 +249,7 @@ class ShellTest(utils.TestCase):
|
||||
project_domain_id='', project_domain_name='',
|
||||
user_domain_id='', user_domain_name='', profile=None,
|
||||
zun_url=None, insecure=False,
|
||||
api_version=api_versions.APIVersion('1.2'))
|
||||
api_version=api_versions.APIVersion('1.3'))
|
||||
|
||||
def test_main_option_region(self):
|
||||
self.make_env()
|
||||
@ -277,7 +277,7 @@ class ShellTest(utils.TestCase):
|
||||
project_domain_id='', project_domain_name='',
|
||||
user_domain_id='', user_domain_name='', profile=None,
|
||||
zun_url=None, insecure=False,
|
||||
api_version=api_versions.APIVersion('1.2'))
|
||||
api_version=api_versions.APIVersion('1.3'))
|
||||
|
||||
@mock.patch('zunclient.v1.client.Client')
|
||||
def test_main_endpoint_internal(self, mock_client):
|
||||
@ -291,7 +291,7 @@ class ShellTest(utils.TestCase):
|
||||
project_domain_id='', project_domain_name='',
|
||||
user_domain_id='', user_domain_name='', profile=None,
|
||||
zun_url=None, insecure=False,
|
||||
api_version=api_versions.APIVersion('1.2'))
|
||||
api_version=api_versions.APIVersion('1.3'))
|
||||
|
||||
|
||||
class ShellTestKeystoneV3(ShellTest):
|
||||
@ -322,4 +322,4 @@ class ShellTestKeystoneV3(ShellTest):
|
||||
project_domain_id='', project_domain_name='Default',
|
||||
user_domain_id='', user_domain_name='Default',
|
||||
zun_url=None, insecure=False, profile=None,
|
||||
api_version=api_versions.APIVersion('1.2'))
|
||||
api_version=api_versions.APIVersion('1.3'))
|
||||
|
@ -32,6 +32,7 @@ CONTAINER1 = {'id': '1234',
|
||||
'hints': {'hint1': 'bar'},
|
||||
'restart_policy': 'no',
|
||||
'security_groups': ['test'],
|
||||
'auto_remove': True,
|
||||
}
|
||||
|
||||
CONTAINER2 = {'id': '1235',
|
||||
@ -48,6 +49,7 @@ CONTAINER2 = {'id': '1235',
|
||||
'hints': {'hint2': 'bar'},
|
||||
'restart_policy': 'on-failure:5',
|
||||
'security_groups': ['test'],
|
||||
'auto_remove': False,
|
||||
}
|
||||
|
||||
CREATE_CONTAINER1 = copy.deepcopy(CONTAINER1)
|
||||
|
@ -22,7 +22,7 @@ from zunclient import exceptions
|
||||
CREATION_ATTRIBUTES = ['name', 'image', 'command', 'cpu', 'memory',
|
||||
'environment', 'workdir', 'labels', 'image_pull_policy',
|
||||
'restart_policy', 'interactive', 'image_driver',
|
||||
'security_groups', 'hints', 'nets']
|
||||
'security_groups', 'hints', 'nets', 'auto_remove']
|
||||
|
||||
|
||||
class Container(base.Resource):
|
||||
|
@ -49,6 +49,9 @@ def _show_container(container):
|
||||
@utils.arg('--workdir',
|
||||
metavar='<workdir>',
|
||||
help='The working directory for commands to run in')
|
||||
@utils.arg('--rm',
|
||||
action='store_true',
|
||||
help='Automatically remove the container when it exits')
|
||||
@utils.arg('--label',
|
||||
metavar='<KEY=VALUE>',
|
||||
action='append', default=[],
|
||||
@ -117,6 +120,7 @@ def do_create(cs, args):
|
||||
opts['memory'] = args.memory
|
||||
opts['cpu'] = args.cpu
|
||||
opts['environment'] = zun_utils.format_args(args.environment)
|
||||
opts['auto_remove'] = args.rm
|
||||
opts['workdir'] = args.workdir
|
||||
opts['labels'] = zun_utils.format_args(args.label)
|
||||
opts['image_pull_policy'] = args.image_pull_policy
|
||||
@ -425,6 +429,9 @@ def do_kill(cs, args):
|
||||
@utils.arg('--workdir',
|
||||
metavar='<workdir>',
|
||||
help='The working directory for commands to run in')
|
||||
@utils.arg('--rm',
|
||||
action='store_true',
|
||||
help='Automatically remove the container when it exits')
|
||||
@utils.arg('--label',
|
||||
metavar='<KEY=VALUE>',
|
||||
action='append', default=[],
|
||||
@ -494,6 +501,7 @@ def do_run(cs, args):
|
||||
opts['cpu'] = args.cpu
|
||||
opts['environment'] = zun_utils.format_args(args.environment)
|
||||
opts['workdir'] = args.workdir
|
||||
opts['auto_remove'] = args.rm
|
||||
opts['labels'] = zun_utils.format_args(args.label)
|
||||
opts['image_pull_policy'] = args.image_pull_policy
|
||||
opts['image_driver'] = args.image_driver
|
||||
|
Loading…
x
Reference in New Issue
Block a user