Add CLI to list nodes using the same driver.

Add CLI function to list nodes using the same driver.

Change-Id: I3ee3dd4fd52931a4eebb6ff037d83eb95e4fb1ba
Partial-Bug: #1530626
Depends-On: I998d6a0a6da44487d5ba90dafd417d81d1c7e504
This commit is contained in:
Kan 2016-01-06 03:33:10 +00:00
parent fe422e57ab
commit 4d14aced92
5 changed files with 52 additions and 2 deletions

View File

@ -160,6 +160,13 @@ fake_responses = {
{"nodes": [NODE1]}, {"nodes": [NODE1]},
) )
}, },
'/v1/nodes/?driver=fake':
{
'GET': (
{},
{"nodes": [NODE1]},
)
},
'/v1/nodes/detail?instance_uuid=%s' % NODE2['instance_uuid']: '/v1/nodes/detail?instance_uuid=%s' % NODE2['instance_uuid']:
{ {
'GET': ( 'GET': (
@ -521,6 +528,15 @@ class NodeManagerTest(testtools.TestCase):
self.assertRaises(KeyError, self.mgr.list, self.assertRaises(KeyError, self.mgr.list,
provision_state="test") provision_state="test")
def test_node_list_driver(self):
nodes = self.mgr.list(driver="fake")
expect = [
('GET', '/v1/nodes/?driver=fake', {}, None),
]
self.assertEqual(expect, self.api.calls)
self.assertThat(nodes, HasLength(1))
self.assertEqual(NODE1['uuid'], getattr(nodes[0], 'uuid'))
def test_node_list_no_maintenance(self): def test_node_list_no_maintenance(self):
nodes = self.mgr.list(maintenance=False) nodes = self.mgr.list(maintenance=False)
expect = [ expect = [

View File

@ -530,7 +530,7 @@ class NodeShellTest(utils.BaseTestCase):
def _get_client_mock_args(self, node=None, associated=None, def _get_client_mock_args(self, node=None, associated=None,
maintenance=None, marker=None, limit=None, maintenance=None, marker=None, limit=None,
sort_dir=None, sort_key=None, detail=False, sort_dir=None, sort_key=None, detail=False,
fields=None, provision_state=None): fields=None, provision_state=None, driver=None):
args = mock.MagicMock() args = mock.MagicMock()
args.node = node args.node = node
args.associated = associated args.associated = associated
@ -542,6 +542,7 @@ class NodeShellTest(utils.BaseTestCase):
args.sort_key = sort_key args.sort_key = sort_key
args.detail = detail args.detail = detail
args.fields = fields args.fields = fields
args.driver = driver
return args return args
@ -579,6 +580,24 @@ class NodeShellTest(utils.BaseTestCase):
provision_state='wait call-back', provision_state='wait call-back',
detail=True) detail=True)
def test_do_node_list_driver(self):
client_mock = mock.MagicMock()
args = self._get_client_mock_args(driver='fake',
detail=False)
n_shell.do_node_list(client_mock, args)
client_mock.node.list.assert_called_once_with(driver='fake',
detail=False)
def test_do_node_list_detail_driver(self):
client_mock = mock.MagicMock()
args = self._get_client_mock_args(driver='fake',
detail=True)
n_shell.do_node_list(client_mock, args)
client_mock.node.list.assert_called_once_with(driver='fake',
detail=True)
def test_do_node_list_sort_key(self): def test_do_node_list_sort_key(self):
client_mock = mock.MagicMock() client_mock = mock.MagicMock()
args = self._get_client_mock_args(sort_key='created_at', args = self._get_client_mock_args(sort_key='created_at',

View File

@ -42,7 +42,7 @@ class NodeManager(base.CreateManager):
def list(self, associated=None, maintenance=None, marker=None, limit=None, def list(self, associated=None, maintenance=None, marker=None, limit=None,
detail=False, sort_key=None, sort_dir=None, fields=None, detail=False, sort_key=None, sort_dir=None, fields=None,
provision_state=None): provision_state=None, driver=None):
"""Retrieve a list of nodes. """Retrieve a list of nodes.
:param associated: Optional. Either a Boolean or a string :param associated: Optional. Either a Boolean or a string
@ -80,6 +80,9 @@ class NodeManager(base.CreateManager):
of the resource to be returned. Can not be used of the resource to be returned. Can not be used
when 'detail' is set. when 'detail' is set.
:param driver: Optional. String value to get only nodes using that
driver.
:returns: A list of nodes. :returns: A list of nodes.
""" """
@ -98,6 +101,8 @@ class NodeManager(base.CreateManager):
filters.append('maintenance=%s' % maintenance) filters.append('maintenance=%s' % maintenance)
if provision_state is not None: if provision_state is not None:
filters.append('provision_state=%s' % provision_state) filters.append('provision_state=%s' % provision_state)
if driver is not None:
filters.append('driver=%s' % driver)
path = '' path = ''
if detail: if detail:

View File

@ -97,6 +97,10 @@ def do_node_show(cc, args):
'--provision-state', '--provision-state',
metavar='<provision-state>', metavar='<provision-state>',
help="List nodes in specified provision state.") help="List nodes in specified provision state.")
@cliutils.arg(
'--driver',
metavar='<driver>',
help="List nodes using specified driver.")
@cliutils.arg( @cliutils.arg(
'--detail', '--detail',
dest='detail', dest='detail',
@ -124,6 +128,9 @@ def do_node_list(cc, args):
if args.provision_state is not None: if args.provision_state is not None:
params['provision_state'] = args.provision_state params['provision_state'] = args.provision_state
if args.driver is not None:
params['driver'] = args.driver
if args.detail: if args.detail:
fields = res_fields.NODE_DETAILED_RESOURCE.fields fields = res_fields.NODE_DETAILED_RESOURCE.fields
field_labels = res_fields.NODE_DETAILED_RESOURCE.labels field_labels = res_fields.NODE_DETAILED_RESOURCE.labels

View File

@ -0,0 +1,3 @@
---
features:
- Add support for filtering nodes using the same driver in list command.