Merge "Enhance zun update command"
This commit is contained in:
@@ -48,7 +48,6 @@ openstack.container.v1 =
|
|||||||
appcontainer_kill = zunclient.osc.v1.containers:KillContainer
|
appcontainer_kill = zunclient.osc.v1.containers:KillContainer
|
||||||
appcontainer_stop = zunclient.osc.v1.containers:StopContainer
|
appcontainer_stop = zunclient.osc.v1.containers:StopContainer
|
||||||
appcontainer_run = zunclient.osc.v1.containers:RunContainer
|
appcontainer_run = zunclient.osc.v1.containers:RunContainer
|
||||||
appcontainer_rename = zunclient.osc.v1.containers:RenameContainer
|
|
||||||
appcontainer_top = zunclient.osc.v1.containers:TopContainer
|
appcontainer_top = zunclient.osc.v1.containers:TopContainer
|
||||||
appcontainer_set = zunclient.osc.v1.containers:UpdateContainer
|
appcontainer_set = zunclient.osc.v1.containers:UpdateContainer
|
||||||
appcontainer_attach = zunclient.osc.v1.containers:AttachContainer
|
appcontainer_attach = zunclient.osc.v1.containers:AttachContainer
|
||||||
|
|||||||
2
tox.ini
2
tox.ini
@@ -1,6 +1,6 @@
|
|||||||
[tox]
|
[tox]
|
||||||
minversion = 1.6
|
minversion = 1.6
|
||||||
envlist = py35,py27,pypy,pep8
|
envlist = py35,py27,pep8
|
||||||
skipsdist = True
|
skipsdist = True
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
|
|||||||
@@ -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.13'
|
MAX_API_VERSION = '1.14'
|
||||||
DEFAULT_API_VERSION = MAX_API_VERSION
|
DEFAULT_API_VERSION = MAX_API_VERSION
|
||||||
|
|
||||||
_SUBSTITUTIONS = {}
|
_SUBSTITUTIONS = {}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
|
import decorator
|
||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
from oslo_utils import strutils
|
from oslo_utils import strutils
|
||||||
import prettytable
|
import prettytable
|
||||||
@@ -289,3 +290,11 @@ def exit(msg=''):
|
|||||||
if msg:
|
if msg:
|
||||||
print(msg, file=sys.stderr)
|
print(msg, file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def deprecated(message):
|
||||||
|
@decorator.decorator
|
||||||
|
def wrapper(func, *args, **kwargs):
|
||||||
|
print(message)
|
||||||
|
return func(*args, **kwargs)
|
||||||
|
return wrapper
|
||||||
|
|||||||
@@ -850,35 +850,6 @@ class RunContainer(command.ShowOne):
|
|||||||
return columns, utils.get_item_properties(container, columns)
|
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):
|
class TopContainer(command.Command):
|
||||||
"""Display the running processes inside the container"""
|
"""Display the running processes inside the container"""
|
||||||
log = logging.getLogger(__name__ + ".TopContainer")
|
log = logging.getLogger(__name__ + ".TopContainer")
|
||||||
@@ -927,6 +898,11 @@ class UpdateContainer(command.ShowOne):
|
|||||||
'--memory',
|
'--memory',
|
||||||
metavar='<memory>',
|
metavar='<memory>',
|
||||||
help='The container memory size in MiB')
|
help='The container memory size in MiB')
|
||||||
|
parser.add_argument(
|
||||||
|
'--name',
|
||||||
|
metavar='<name>',
|
||||||
|
help='The new name of container to update')
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
@@ -935,6 +911,7 @@ class UpdateContainer(command.ShowOne):
|
|||||||
opts = {}
|
opts = {}
|
||||||
opts['memory'] = parsed_args.memory
|
opts['memory'] = parsed_args.memory
|
||||||
opts['cpu'] = parsed_args.cpu
|
opts['cpu'] = parsed_args.cpu
|
||||||
|
opts['name'] = parsed_args.name
|
||||||
opts = zun_utils.remove_null_parms(**opts)
|
opts = zun_utils.remove_null_parms(**opts)
|
||||||
if not opts:
|
if not opts:
|
||||||
raise exc.CommandError("You must update at least one property")
|
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.assertEqual(container['image'], container['image'])
|
||||||
self.container_delete(container['name'])
|
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):
|
def test_execute(self):
|
||||||
"""Check container execute command with name and UUID arguments.
|
"""Check container execute command with name and UUID arguments.
|
||||||
|
|
||||||
|
|||||||
@@ -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,
|
endpoint_override=None, insecure=False,
|
||||||
version=api_versions.APIVersion('1.13'))
|
version=api_versions.APIVersion('1.14'))
|
||||||
|
|
||||||
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,
|
endpoint_override=None, insecure=False,
|
||||||
version=api_versions.APIVersion('1.13'))
|
version=api_versions.APIVersion('1.14'))
|
||||||
|
|
||||||
@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,
|
endpoint_override=None, insecure=False,
|
||||||
version=api_versions.APIVersion('1.13'))
|
version=api_versions.APIVersion('1.14'))
|
||||||
|
|
||||||
|
|
||||||
class ShellTestKeystoneV3(ShellTest):
|
class ShellTestKeystoneV3(ShellTest):
|
||||||
@@ -319,4 +319,4 @@ class ShellTestKeystoneV3(ShellTest):
|
|||||||
project_domain_id='', project_domain_name='Default',
|
project_domain_id='', project_domain_name='Default',
|
||||||
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,
|
||||||
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
|
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):
|
def _show_container(container):
|
||||||
zun_utils.format_container_addresses(container)
|
zun_utils.format_container_addresses(container)
|
||||||
utils.print_dict(container._info)
|
utils.print_dict(container._info)
|
||||||
@@ -673,17 +679,6 @@ def do_run(cs, args):
|
|||||||
raise exceptions.InvalidWebSocketLink(container_uuid)
|
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',
|
@utils.arg('container',
|
||||||
metavar='<container>',
|
metavar='<container>',
|
||||||
help="ID or name of the container to update.")
|
help="ID or name of the container to update.")
|
||||||
@@ -693,11 +688,15 @@ def do_rename(cs, args):
|
|||||||
@utils.arg('-m', '--memory',
|
@utils.arg('-m', '--memory',
|
||||||
metavar='<memory>',
|
metavar='<memory>',
|
||||||
help='The container memory size in MiB')
|
help='The container memory size in MiB')
|
||||||
|
@utils.arg('--name',
|
||||||
|
metavar='<name>',
|
||||||
|
help='The new name for the container')
|
||||||
def do_update(cs, args):
|
def do_update(cs, args):
|
||||||
"""Update one or more attributes of the container."""
|
"""Update one or more attributes of the container."""
|
||||||
opts = {}
|
opts = {}
|
||||||
opts['memory'] = args.memory
|
opts['memory'] = args.memory
|
||||||
opts['cpu'] = args.cpu
|
opts['cpu'] = args.cpu
|
||||||
|
opts['name'] = args.name
|
||||||
opts = zun_utils.remove_null_parms(**opts)
|
opts = zun_utils.remove_null_parms(**opts)
|
||||||
if not opts:
|
if not opts:
|
||||||
raise exc.CommandError("You must update at least one property")
|
raise exc.CommandError("You must update at least one property")
|
||||||
@@ -705,6 +704,18 @@ def do_update(cs, args):
|
|||||||
_show_container(container)
|
_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',
|
@utils.arg('container',
|
||||||
metavar='<container>',
|
metavar='<container>',
|
||||||
help='ID or name of the container to be attached to.')
|
help='ID or name of the container to be attached to.')
|
||||||
|
|||||||
Reference in New Issue
Block a user