Implements basic container operations
- do_container_create - do_container_list - do_container_delete - do_container_show Change-Id: I7fa57590b37df92cfbfffe2a2c69a7029bec27e7
This commit is contained in:
parent
24ff6c37cb
commit
39eb5d5fcf
@ -18,7 +18,7 @@ from magnumclient import exceptions
|
||||
|
||||
|
||||
# FIXME: Modify correct attributes.
|
||||
CREATION_ATTRIBUTES = ['description']
|
||||
CREATION_ATTRIBUTES = ['name', 'desc']
|
||||
|
||||
|
||||
class Container(base.Resource):
|
||||
@ -72,9 +72,13 @@ class ContainerManager(base.Manager):
|
||||
path += '?' + '&'.join(filters)
|
||||
|
||||
if limit is None:
|
||||
return self._list(self._path(path), "containers")
|
||||
# TODO(yuanying): if endpoint returns "map",
|
||||
# change None to response_key
|
||||
return self._list(self._path(path), None)
|
||||
else:
|
||||
return self._list_pagination(self._path(path), "containers",
|
||||
# TODO(yuanying): if endpoint returns "map",
|
||||
# change None to response_key
|
||||
return self._list_pagination(self._path(path), None,
|
||||
limit=limit)
|
||||
|
||||
def get(self, container_id):
|
||||
@ -89,6 +93,7 @@ class ContainerManager(base.Manager):
|
||||
if key in CREATION_ATTRIBUTES:
|
||||
new[key] = value
|
||||
else:
|
||||
pass
|
||||
raise exceptions.InvalidAttribute()
|
||||
return self._create(self._path(), new)
|
||||
|
||||
|
@ -13,6 +13,20 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
|
||||
from magnumclient.openstack.common import cliutils as utils
|
||||
|
||||
|
||||
def _print_list_field(field):
|
||||
return lambda obj: ', '.join(getattr(obj, field))
|
||||
|
||||
|
||||
def _show_container(container):
|
||||
utils.print_dict(container._info)
|
||||
|
||||
|
||||
def do_bay_list(cs, args):
|
||||
pass
|
||||
@ -62,20 +76,73 @@ def do_service_show(cs, args):
|
||||
pass
|
||||
|
||||
|
||||
#
|
||||
# Containers
|
||||
# ~~~~~~~~~~
|
||||
# container-create [--json <file>]
|
||||
#
|
||||
# container-list
|
||||
#
|
||||
# container-delete --id <container_id>
|
||||
#
|
||||
# container-show --id <container_id> [--json]
|
||||
#
|
||||
# TODO(yuanying): container-reboot
|
||||
#
|
||||
# TODO(yuanying): container-stop
|
||||
#
|
||||
# TODO(yuanying): container-start
|
||||
#
|
||||
# TODO(yuanying): container-pause
|
||||
#
|
||||
# TODO(yuanying): container-unpause
|
||||
#
|
||||
# TODO(yuanying): container-logs
|
||||
#
|
||||
# TODO(yuanying): container-execute
|
||||
#
|
||||
|
||||
|
||||
@utils.arg('--json',
|
||||
default=sys.stdin,
|
||||
type=argparse.FileType('r'),
|
||||
help='JSON representation of container.')
|
||||
def do_container_create(cs, args):
|
||||
pass
|
||||
"""Create a container."""
|
||||
container = json.loads(args.json.read())
|
||||
_show_container(cs.containers.create(**container))
|
||||
|
||||
|
||||
def do_container_list(cs, args):
|
||||
pass
|
||||
"""Print a list of available containers."""
|
||||
containers = cs.containers.list()
|
||||
columns = ('name', 'desc')
|
||||
utils.print_list(containers, columns,
|
||||
{'versions': _print_list_field('versions')})
|
||||
|
||||
|
||||
@utils.arg('--id',
|
||||
metavar='<container_id>',
|
||||
help='ID of the container to delete.')
|
||||
def do_container_delete(cs, args):
|
||||
pass
|
||||
"""Delete a cluster."""
|
||||
cs.containers.delete(args.id)
|
||||
|
||||
|
||||
@utils.arg('--id',
|
||||
metavar='<container_id>',
|
||||
help='ID of the container to show.')
|
||||
@utils.arg('--json',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='Print JSON representation of the container.')
|
||||
def do_container_show(cs, args):
|
||||
pass
|
||||
"""Show details of a container."""
|
||||
container = cs.containers.get(args.id)
|
||||
if args.json:
|
||||
print(json.dumps(container._info))
|
||||
else:
|
||||
_show_container(container)
|
||||
|
||||
|
||||
def do_container_reboot(cs, args):
|
||||
|
0
magnumclient/tests/api/__init__.py
Normal file
0
magnumclient/tests/api/__init__.py
Normal file
67
magnumclient/tests/api/test_shell.py
Normal file
67
magnumclient/tests/api/test_shell.py
Normal file
@ -0,0 +1,67 @@
|
||||
# Copyright 2014 NEC Corporation. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
|
||||
import mock
|
||||
|
||||
from magnumclient.api import shell
|
||||
from magnumclient.tests import base
|
||||
|
||||
|
||||
container_fixture = {
|
||||
"name": "container",
|
||||
"desc": "container description."
|
||||
}
|
||||
|
||||
|
||||
class ShellTest(base.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ShellTest, self).setUp()
|
||||
|
||||
def test_do_container_create(self):
|
||||
client_mock = mock.MagicMock()
|
||||
args = mock.MagicMock()
|
||||
args.json.read.return_value = json.dumps(container_fixture)
|
||||
|
||||
shell.do_container_create(client_mock, args)
|
||||
client_mock.containers.create.assert_called_once_with(
|
||||
**container_fixture)
|
||||
|
||||
def test_do_container_list(self):
|
||||
client_mock = mock.MagicMock()
|
||||
args = mock.MagicMock()
|
||||
|
||||
shell.do_container_list(client_mock, args)
|
||||
client_mock.containers.list.assert_called_once_with()
|
||||
|
||||
def test_do_container_delete(self):
|
||||
client_mock = mock.MagicMock()
|
||||
args = mock.MagicMock()
|
||||
container_id = "container_id"
|
||||
args.id = container_id
|
||||
|
||||
shell.do_container_delete(client_mock, args)
|
||||
client_mock.containers.delete.assert_called_once_with(container_id)
|
||||
|
||||
def test_do_container_show(self):
|
||||
client_mock = mock.MagicMock()
|
||||
args = mock.MagicMock()
|
||||
container_id = "container_id"
|
||||
args.id = container_id
|
||||
args.json = None
|
||||
|
||||
shell.do_container_show(client_mock, args)
|
||||
client_mock.containers.get.assert_called_once_with(container_id)
|
@ -1,6 +1,7 @@
|
||||
# The order of packages is significant, because pip processes them in the order
|
||||
# of appearance. Changing the order has an impact on the overall integration
|
||||
# process, which may cause wedges in the gate later.
|
||||
argparse
|
||||
pbr>=0.6,!=0.7,<1.0
|
||||
Babel>=1.3
|
||||
oslo.config>=1.4.0 # Apache-2.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user