Enhance zun update command
Right now, for renaming the container we need to use zun rename but we can move this into PATCH /containers/<container> https://github.com/openstack/zun/blob/master/zun/api/controllers/v1/containers.py#L570) because this is the convention of API design in OpenStack (e.g. nova implements server rename at PUT /servers/<server>). This PS adds support for rename container using update command as well: zun update [--cpu <cpu>] [-m <memory>] [--name <name>] <container> Change-Id: I237a849dec549f53efe560a04fc0ca64929c14e7 Related-Bug: #1759459
This commit is contained in:

committed by
Deepak Mourya

parent
8a1cd5f808
commit
8424d04cf9
@@ -48,7 +48,6 @@ openstack.container.v1 =
|
||||
appcontainer_kill = zunclient.osc.v1.containers:KillContainer
|
||||
appcontainer_stop = zunclient.osc.v1.containers:StopContainer
|
||||
appcontainer_run = zunclient.osc.v1.containers:RunContainer
|
||||
appcontainer_rename = zunclient.osc.v1.containers:RenameContainer
|
||||
appcontainer_top = zunclient.osc.v1.containers:TopContainer
|
||||
appcontainer_update = zunclient.osc.v1.containers:UpdateContainer
|
||||
appcontainer_attach = zunclient.osc.v1.containers:AttachContainer
|
||||
|
2
tox.ini
2
tox.ini
@@ -1,6 +1,6 @@
|
||||
[tox]
|
||||
minversion = 1.6
|
||||
envlist = py35,py27,pypy,pep8
|
||||
envlist = py35,py27,pep8
|
||||
skipsdist = True
|
||||
|
||||
[testenv]
|
||||
|
@@ -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.13'
|
||||
MAX_API_VERSION = '1.14'
|
||||
DEFAULT_API_VERSION = MAX_API_VERSION
|
||||
|
||||
_SUBSTITUTIONS = {}
|
||||
|
@@ -24,6 +24,7 @@ import os
|
||||
import sys
|
||||
import textwrap
|
||||
|
||||
import decorator
|
||||
from oslo_utils import encodeutils
|
||||
from oslo_utils import strutils
|
||||
import prettytable
|
||||
@@ -289,3 +290,11 @@ def exit(msg=''):
|
||||
if msg:
|
||||
print(msg, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def deprecated(message):
|
||||
@decorator.decorator
|
||||
def wrapper(func, *args, **kwargs):
|
||||
print(message)
|
||||
return func(*args, **kwargs)
|
||||
return wrapper
|
||||
|
@@ -805,35 +805,6 @@ class RunContainer(command.ShowOne):
|
||||
return columns, utils.get_item_properties(container, columns)
|
||||
|
||||
|
||||
class RenameContainer(command.Command):
|
||||
"""Rename specified container"""
|
||||
log = logging.getLogger(__name__ + ".RenameContainer")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(RenameContainer, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'container',
|
||||
metavar='<container>',
|
||||
help='ID or name of the container to rename.')
|
||||
parser.add_argument(
|
||||
'name',
|
||||
metavar='<name>',
|
||||
help='The new name for the container')
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = _get_client(self, parsed_args)
|
||||
container = parsed_args.container
|
||||
name = parsed_args.name
|
||||
try:
|
||||
client.containers.rename(container, name)
|
||||
print(_('Request to rename container %s has been accepted')
|
||||
% container)
|
||||
except Exception as e:
|
||||
print("rename for container %(container)s failed: %(e)s" %
|
||||
{'container': container, 'e': e})
|
||||
|
||||
|
||||
class TopContainer(command.Command):
|
||||
"""Display the running processes inside the container"""
|
||||
log = logging.getLogger(__name__ + ".TopContainer")
|
||||
@@ -882,6 +853,11 @@ class UpdateContainer(command.ShowOne):
|
||||
'--memory',
|
||||
metavar='<memory>',
|
||||
help='The container memory size in MiB')
|
||||
parser.add_argument(
|
||||
'--name',
|
||||
metavar='<name>',
|
||||
help='The new name of container to update')
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
@@ -890,6 +866,7 @@ class UpdateContainer(command.ShowOne):
|
||||
opts = {}
|
||||
opts['memory'] = parsed_args.memory
|
||||
opts['cpu'] = parsed_args.cpu
|
||||
opts['name'] = parsed_args.name
|
||||
opts = zun_utils.remove_null_parms(**opts)
|
||||
if not opts:
|
||||
raise exc.CommandError("You must update at least one property")
|
||||
|
@@ -102,21 +102,6 @@ class ContainerTests(base.TestCase):
|
||||
self.assertEqual(container['image'], container['image'])
|
||||
self.container_delete(container['name'])
|
||||
|
||||
def test_rename(self):
|
||||
"""Check container rename command with name and UUID arguments.
|
||||
|
||||
Test steps:
|
||||
1) Create container in setUp.
|
||||
2) rename container calling it with name and UUID arguments.
|
||||
3) Check new name.
|
||||
"""
|
||||
container = self.container_create(name='test_rename')
|
||||
new_name = 'test_new'
|
||||
self.container_rename(container['name'], new_name)
|
||||
container_list = self.container_list()
|
||||
self.assertIn(new_name, [x['name'] for x in container_list])
|
||||
self.container_delete(new_name)
|
||||
|
||||
def test_execute(self):
|
||||
"""Check container execute command with name and UUID arguments.
|
||||
|
||||
|
@@ -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,
|
||||
version=api_versions.APIVersion('1.13'))
|
||||
version=api_versions.APIVersion('1.14'))
|
||||
|
||||
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,
|
||||
version=api_versions.APIVersion('1.13'))
|
||||
version=api_versions.APIVersion('1.14'))
|
||||
|
||||
@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,
|
||||
version=api_versions.APIVersion('1.13'))
|
||||
version=api_versions.APIVersion('1.14'))
|
||||
|
||||
|
||||
class ShellTestKeystoneV3(ShellTest):
|
||||
@@ -319,4 +319,4 @@ class ShellTestKeystoneV3(ShellTest):
|
||||
project_domain_id='', project_domain_name='Default',
|
||||
user_domain_id='', user_domain_name='Default',
|
||||
endpoint_override=None, insecure=False, profile=None,
|
||||
version=api_versions.APIVersion('1.13'))
|
||||
version=api_versions.APIVersion('1.14'))
|
||||
|
@@ -28,6 +28,12 @@ from zunclient.common.websocketclient import websocketclient
|
||||
from zunclient import exceptions as exc
|
||||
|
||||
|
||||
DEPRECATION_MESSAGE = (
|
||||
'WARNING: Rename container command deprecated and will be removed '
|
||||
'in a future release.\nUse Update container command to avoid '
|
||||
'seeing this message.')
|
||||
|
||||
|
||||
def _show_container(container):
|
||||
zun_utils.format_container_addresses(container)
|
||||
utils.print_dict(container._info)
|
||||
@@ -636,17 +642,6 @@ def do_run(cs, args):
|
||||
raise exceptions.InvalidWebSocketLink(container_uuid)
|
||||
|
||||
|
||||
@utils.arg('container',
|
||||
metavar='<container>',
|
||||
help='ID or name of the container to rename.')
|
||||
@utils.arg('name',
|
||||
metavar='<name>',
|
||||
help='The new name for the container')
|
||||
def do_rename(cs, args):
|
||||
"""Rename a container."""
|
||||
cs.containers.rename(args.container, args.name)
|
||||
|
||||
|
||||
@utils.arg('container',
|
||||
metavar='<container>',
|
||||
help="ID or name of the container to update.")
|
||||
@@ -656,11 +651,15 @@ def do_rename(cs, args):
|
||||
@utils.arg('-m', '--memory',
|
||||
metavar='<memory>',
|
||||
help='The container memory size in MiB')
|
||||
@utils.arg('--name',
|
||||
metavar='<name>',
|
||||
help='The new name for the container')
|
||||
def do_update(cs, args):
|
||||
"""Update one or more attributes of the container."""
|
||||
opts = {}
|
||||
opts['memory'] = args.memory
|
||||
opts['cpu'] = args.cpu
|
||||
opts['name'] = args.name
|
||||
opts = zun_utils.remove_null_parms(**opts)
|
||||
if not opts:
|
||||
raise exc.CommandError("You must update at least one property")
|
||||
@@ -668,6 +667,18 @@ def do_update(cs, args):
|
||||
_show_container(container)
|
||||
|
||||
|
||||
@utils.deprecated(DEPRECATION_MESSAGE)
|
||||
@utils.arg('container',
|
||||
metavar='<container>',
|
||||
help='ID or name of the container to rename.')
|
||||
@utils.arg('name',
|
||||
metavar='<name>',
|
||||
help='The new name for the container')
|
||||
def do_rename(cs, args):
|
||||
"""Rename a container."""
|
||||
cs.containers.rename(args.container, args.name)
|
||||
|
||||
|
||||
@utils.arg('container',
|
||||
metavar='<container>',
|
||||
help='ID or name of the container to be attached to.')
|
||||
|
Reference in New Issue
Block a user