Extend OSC "node list" cmd to fetch nodes without instance UUID
The openstackclient command to get a list of nodes is 'openstack baremetal node list'. It has the optional argument '--associated'. If this is specified, it will return nodes that are associated with instances (ie, node.instance_uuid is set to some UUID). However, there is no way to filter the nodes to get ones that are NOT associated with instances. Added "--unassociated" option and unit testcase for this. Change-Id: Iad60e92335bab4eb4a71aedb4e90d34d0186c5cc Closes-bug: #1619091
This commit is contained in:
parent
2a36c060bf
commit
9f788f480e
@ -453,12 +453,16 @@ class ListBaremetalNode(command.Lister):
|
||||
default=False,
|
||||
help="List nodes in maintenance mode.",
|
||||
)
|
||||
parser.add_argument(
|
||||
associated_group = parser.add_mutually_exclusive_group()
|
||||
associated_group.add_argument(
|
||||
'--associated',
|
||||
dest='associated',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help="List only nodes associated with an instance."
|
||||
help=_('List only nodes associated with an instance.'),
|
||||
)
|
||||
associated_group.add_argument(
|
||||
'--unassociated',
|
||||
action='store_true',
|
||||
help=_('List only nodes not associated with an instance.'),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--provision-state',
|
||||
@ -511,7 +515,9 @@ class ListBaremetalNode(command.Lister):
|
||||
params['limit'] = parsed_args.limit
|
||||
params['marker'] = parsed_args.marker
|
||||
if parsed_args.associated:
|
||||
params['associated'] = parsed_args.associated
|
||||
params['associated'] = True
|
||||
if parsed_args.unassociated:
|
||||
params['associated'] = False
|
||||
if parsed_args.maintenance:
|
||||
params['maintenance'] = parsed_args.maintenance
|
||||
if parsed_args.provision_state:
|
||||
|
@ -580,6 +580,39 @@ class TestBaremetalList(TestBaremetal):
|
||||
**kwargs
|
||||
)
|
||||
|
||||
def test_baremetal_list_unassociated(self):
|
||||
arglist = [
|
||||
'--unassociated',
|
||||
]
|
||||
verifylist = [
|
||||
('associated', False),
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
# Set expected values
|
||||
kwargs = {
|
||||
'marker': None,
|
||||
'limit': None,
|
||||
'associated': False,
|
||||
}
|
||||
|
||||
self.baremetal_mock.node.list.assert_called_with(
|
||||
**kwargs
|
||||
)
|
||||
|
||||
def test_baremetal_list_both_associated_unassociated_not_allowed(self):
|
||||
arglist = [
|
||||
'--associated', '--unassociated',
|
||||
]
|
||||
verifylist = []
|
||||
|
||||
self.assertRaises(oscutils.ParserException,
|
||||
self.check_parser,
|
||||
self.cmd, arglist, verifylist)
|
||||
|
||||
def test_baremetal_list_provision_state(self):
|
||||
arglist = [
|
||||
'--provision-state', 'active',
|
||||
|
@ -0,0 +1,7 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Adds an option ``--unassociated`` to the
|
||||
``openstack baremetal node list`` command. It provides the
|
||||
ability to get a list of the nodes that are not associated
|
||||
with instances.
|
Loading…
Reference in New Issue
Block a user