diff --git a/ironicclient/osc/v1/baremetal_node.py b/ironicclient/osc/v1/baremetal_node.py index 0037ccfca..19796058c 100644 --- a/ironicclient/osc/v1/baremetal_node.py +++ b/ironicclient/osc/v1/baremetal_node.py @@ -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: diff --git a/ironicclient/tests/unit/osc/v1/test_baremetal_node.py b/ironicclient/tests/unit/osc/v1/test_baremetal_node.py index ab7b73808..4201ddb72 100644 --- a/ironicclient/tests/unit/osc/v1/test_baremetal_node.py +++ b/ironicclient/tests/unit/osc/v1/test_baremetal_node.py @@ -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', diff --git a/releasenotes/notes/osc-node-list-no-maintenance-ff1cef7cfbe60fb9.yaml b/releasenotes/notes/osc-node-list-no-maintenance-ff1cef7cfbe60fb9.yaml new file mode 100644 index 000000000..28dec4878 --- /dev/null +++ b/releasenotes/notes/osc-node-list-no-maintenance-ff1cef7cfbe60fb9.yaml @@ -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.