Add --no-maintenance to OSC 'baremetal node list'

This adds the optional argument '--no-maintenance' to the
'openstack baremetal node list' command. Specifying this
limits the list to only include nodes that are not in
maintenance mode.

Closes-Bug: #1619090
Change-Id: I50ac6ffb434564b4afb0d96622d94f56ce29ec0b
Co-Authored-By: Ruby Loo <ruby.loo@intel.com>
This commit is contained in:
Himanshu Kumar 2016-09-20 15:04:27 +05:30 committed by Ruby Loo
parent 36e7dbffe7
commit 4487a37202
3 changed files with 54 additions and 3 deletions

View File

@ -445,12 +445,20 @@ class ListBaremetalNode(command.Lister):
'(asc or desc) (default: asc). Multiple fields and '
'directions can be specified, separated by comma.',
)
parser.add_argument(
maint_group = parser.add_mutually_exclusive_group(required=False)
maint_group.add_argument(
'--maintenance',
dest='maintenance',
action='store_true',
default=False,
help="List nodes in maintenance mode.",
help="Limit list to nodes in maintenance mode",
)
maint_group.add_argument(
'--no-maintenance',
dest='no_maintenance',
action='store_true',
default=False,
help="Limit list to nodes not in maintenance mode",
)
parser.add_argument(
'--associated',
@ -512,7 +520,9 @@ class ListBaremetalNode(command.Lister):
if parsed_args.associated:
params['associated'] = parsed_args.associated
if parsed_args.maintenance:
params['maintenance'] = parsed_args.maintenance
params['maintenance'] = True
elif parsed_args.no_maintenance:
params['maintenance'] = False
if parsed_args.provision_state:
params['provision_state'] = parsed_args.provision_state
if parsed_args.resource_class:

View File

@ -555,6 +555,41 @@ class TestBaremetalList(TestBaremetal):
**kwargs
)
def test_baremetal_list_no_maintenance(self):
arglist = [
'--no-maintenance',
]
verifylist = [
('no_maintenance', True),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
'marker': None,
'limit': None,
'maintenance': False,
}
self.baremetal_mock.node.list.assert_called_with(
**kwargs
)
def test_baremetal_list_both_maintenances(self):
arglist = [
'--maintenance',
'--no-maintenance',
]
verifylist = []
self.assertRaises(oscutils.ParserException,
self.check_parser,
self.cmd, arglist, verifylist)
def test_baremetal_list_associated(self):
arglist = [
'--associated',

View File

@ -0,0 +1,6 @@
---
features:
- |
For OSC, adds ability to get list of nodes that are not in
maintenance mode via the --no-maintenance optional argument
to the ``openstack baremetal node list`` command.