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:
parent
fe422e57ab
commit
4d14aced92
@ -160,6 +160,13 @@ fake_responses = {
|
||||
{"nodes": [NODE1]},
|
||||
)
|
||||
},
|
||||
'/v1/nodes/?driver=fake':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"nodes": [NODE1]},
|
||||
)
|
||||
},
|
||||
'/v1/nodes/detail?instance_uuid=%s' % NODE2['instance_uuid']:
|
||||
{
|
||||
'GET': (
|
||||
@ -521,6 +528,15 @@ class NodeManagerTest(testtools.TestCase):
|
||||
self.assertRaises(KeyError, self.mgr.list,
|
||||
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):
|
||||
nodes = self.mgr.list(maintenance=False)
|
||||
expect = [
|
||||
|
@ -530,7 +530,7 @@ class NodeShellTest(utils.BaseTestCase):
|
||||
def _get_client_mock_args(self, node=None, associated=None,
|
||||
maintenance=None, marker=None, limit=None,
|
||||
sort_dir=None, sort_key=None, detail=False,
|
||||
fields=None, provision_state=None):
|
||||
fields=None, provision_state=None, driver=None):
|
||||
args = mock.MagicMock()
|
||||
args.node = node
|
||||
args.associated = associated
|
||||
@ -542,6 +542,7 @@ class NodeShellTest(utils.BaseTestCase):
|
||||
args.sort_key = sort_key
|
||||
args.detail = detail
|
||||
args.fields = fields
|
||||
args.driver = driver
|
||||
|
||||
return args
|
||||
|
||||
@ -579,6 +580,24 @@ class NodeShellTest(utils.BaseTestCase):
|
||||
provision_state='wait call-back',
|
||||
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):
|
||||
client_mock = mock.MagicMock()
|
||||
args = self._get_client_mock_args(sort_key='created_at',
|
||||
|
@ -42,7 +42,7 @@ class NodeManager(base.CreateManager):
|
||||
|
||||
def list(self, associated=None, maintenance=None, marker=None, limit=None,
|
||||
detail=False, sort_key=None, sort_dir=None, fields=None,
|
||||
provision_state=None):
|
||||
provision_state=None, driver=None):
|
||||
"""Retrieve a list of nodes.
|
||||
|
||||
: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
|
||||
when 'detail' is set.
|
||||
|
||||
:param driver: Optional. String value to get only nodes using that
|
||||
driver.
|
||||
|
||||
:returns: A list of nodes.
|
||||
|
||||
"""
|
||||
@ -98,6 +101,8 @@ class NodeManager(base.CreateManager):
|
||||
filters.append('maintenance=%s' % maintenance)
|
||||
if provision_state is not None:
|
||||
filters.append('provision_state=%s' % provision_state)
|
||||
if driver is not None:
|
||||
filters.append('driver=%s' % driver)
|
||||
|
||||
path = ''
|
||||
if detail:
|
||||
|
@ -97,6 +97,10 @@ def do_node_show(cc, args):
|
||||
'--provision-state',
|
||||
metavar='<provision-state>',
|
||||
help="List nodes in specified provision state.")
|
||||
@cliutils.arg(
|
||||
'--driver',
|
||||
metavar='<driver>',
|
||||
help="List nodes using specified driver.")
|
||||
@cliutils.arg(
|
||||
'--detail',
|
||||
dest='detail',
|
||||
@ -124,6 +128,9 @@ def do_node_list(cc, args):
|
||||
if args.provision_state is not None:
|
||||
params['provision_state'] = args.provision_state
|
||||
|
||||
if args.driver is not None:
|
||||
params['driver'] = args.driver
|
||||
|
||||
if args.detail:
|
||||
fields = res_fields.NODE_DETAILED_RESOURCE.fields
|
||||
field_labels = res_fields.NODE_DETAILED_RESOURCE.labels
|
||||
|
@ -0,0 +1,3 @@
|
||||
---
|
||||
features:
|
||||
- Add support for filtering nodes using the same driver in list command.
|
Loading…
Reference in New Issue
Block a user