Add optional parameter --bay when doing container list
User can use --bay to filter the results of container-list in case of he/she has multiple bays. Please be note that --bay is an optional parameter. Depends-On: Ie9461fb672abfc50f4648bae0999db2caf3939f6 Partially implements: blueprint add-bay-column-to-container Change-Id: I4ae74afc543f841434ba0242cfe42c727afb9d7d
This commit is contained in:
@@ -59,6 +59,17 @@ fake_responses = {
|
|||||||
CREATE_CONTAINER,
|
CREATE_CONTAINER,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
'/v1/containers/?bay_ident=25d5d872-1f4e-4134-ae15-c5fa38cb09a3':
|
||||||
|
{
|
||||||
|
'GET': (
|
||||||
|
{},
|
||||||
|
{'containers': [CONTAINER1, CONTAINER2]},
|
||||||
|
),
|
||||||
|
'POST': (
|
||||||
|
{},
|
||||||
|
CREATE_CONTAINER,
|
||||||
|
),
|
||||||
|
},
|
||||||
'/v1/containers/%s' % CONTAINER1['id']:
|
'/v1/containers/%s' % CONTAINER1['id']:
|
||||||
{
|
{
|
||||||
'GET': (
|
'GET': (
|
||||||
@@ -205,6 +216,16 @@ class ContainerManagerTest(testtools.TestCase):
|
|||||||
self.assertEqual(expect, self.api.calls)
|
self.assertEqual(expect, self.api.calls)
|
||||||
self.assertThat(containers, matchers.HasLength(2))
|
self.assertThat(containers, matchers.HasLength(2))
|
||||||
|
|
||||||
|
def test_container_list_with_bay(self):
|
||||||
|
containers = self.mgr.list(
|
||||||
|
bay_ident='25d5d872-1f4e-4134-ae15-c5fa38cb09a3')
|
||||||
|
expect = [
|
||||||
|
('GET', '/v1/containers/?bay_ident=25d5d872-1f4e-4134'
|
||||||
|
'-ae15-c5fa38cb09a3', {}, None),
|
||||||
|
]
|
||||||
|
self.assertEqual(expect, self.api.calls)
|
||||||
|
self.assertThat(containers, matchers.HasLength(2))
|
||||||
|
|
||||||
def test_container_show(self):
|
def test_container_show(self):
|
||||||
container = self.mgr.get(CONTAINER1['id'])
|
container = self.mgr.get(CONTAINER1['id'])
|
||||||
expect = [
|
expect = [
|
||||||
|
|||||||
@@ -24,6 +24,11 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
|
|||||||
self._test_arg_success('container-list')
|
self._test_arg_success('container-list')
|
||||||
self.assertTrue(mock_list.called)
|
self.assertTrue(mock_list.called)
|
||||||
|
|
||||||
|
@mock.patch('magnumclient.v1.containers.ContainerManager.list')
|
||||||
|
def test_container_list_success_with_bay(self, mock_list):
|
||||||
|
self._test_arg_success('container-list --bay bay_uuid')
|
||||||
|
self.assertTrue(mock_list.called)
|
||||||
|
|
||||||
@mock.patch('magnumclient.v1.containers.ContainerManager.list')
|
@mock.patch('magnumclient.v1.containers.ContainerManager.list')
|
||||||
def test_container_list_failure(self, mock_list):
|
def test_container_list_failure(self, mock_list):
|
||||||
self._test_arg_failure('container-list --wrong',
|
self._test_arg_failure('container-list --wrong',
|
||||||
|
|||||||
@@ -31,11 +31,17 @@ class ContainerManager(base.Manager):
|
|||||||
resource_class = Container
|
resource_class = Container
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _path(id=None):
|
def _path(id=None, bay_ident=None):
|
||||||
return '/v1/containers/%s' % id if id else '/v1/containers'
|
|
||||||
|
if id:
|
||||||
|
return '/v1/containers/%s' % id
|
||||||
|
elif bay_ident:
|
||||||
|
return '/v1/containers/?bay_ident=%s' % (bay_ident)
|
||||||
|
else:
|
||||||
|
return '/v1/containers'
|
||||||
|
|
||||||
def list(self, marker=None, limit=None, sort_key=None,
|
def list(self, marker=None, limit=None, sort_key=None,
|
||||||
sort_dir=None, detail=False):
|
sort_dir=None, detail=False, bay_ident=None):
|
||||||
"""Retrieve a list of containers.
|
"""Retrieve a list of containers.
|
||||||
|
|
||||||
:param marker: Optional, the UUID of a containers, eg the last
|
:param marker: Optional, the UUID of a containers, eg the last
|
||||||
@@ -75,11 +81,14 @@ class ContainerManager(base.Manager):
|
|||||||
if limit is None:
|
if limit is None:
|
||||||
# TODO(yuanying): if endpoint returns "map",
|
# TODO(yuanying): if endpoint returns "map",
|
||||||
# change None to response_key
|
# change None to response_key
|
||||||
return self._list(self._path(path), "containers")
|
return self._list(self._path(path, bay_ident=bay_ident),
|
||||||
|
"containers")
|
||||||
else:
|
else:
|
||||||
# TODO(yuanying): if endpoint returns "map",
|
# TODO(yuanying): if endpoint returns "map",
|
||||||
# change None to response_key
|
# change None to response_key
|
||||||
return self._list_pagination(self._path(path), "containers",
|
return self._list_pagination(self._path(path,
|
||||||
|
bay_ident=bay_ident),
|
||||||
|
"containers",
|
||||||
limit=limit)
|
limit=limit)
|
||||||
|
|
||||||
def get(self, id):
|
def get(self, id):
|
||||||
|
|||||||
@@ -57,10 +57,14 @@ def do_container_create(cs, args):
|
|||||||
_show_container(cs.containers.create(**opts))
|
_show_container(cs.containers.create(**opts))
|
||||||
|
|
||||||
|
|
||||||
|
@utils.arg('--bay',
|
||||||
|
metavar='<bay>', help="UUID or Name of Bay")
|
||||||
def do_container_list(cs, args):
|
def do_container_list(cs, args):
|
||||||
"""Print a list of available containers."""
|
"""Print a list of available containers."""
|
||||||
containers = cs.containers.list()
|
opts = {}
|
||||||
columns = ('uuid', 'name', 'status')
|
opts['bay_ident'] = args.bay
|
||||||
|
containers = cs.containers.list(**opts)
|
||||||
|
columns = ('uuid', 'name', 'status', 'bay_uuid')
|
||||||
utils.print_list(containers, columns,
|
utils.print_list(containers, columns,
|
||||||
{'versions': magnum_utils.print_list_field('versions')})
|
{'versions': magnum_utils.print_list_field('versions')})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user