diff --git a/ironicclient/osc/v1/baremetal_node.py b/ironicclient/osc/v1/baremetal_node.py index a34571da3..eabc64864 100644 --- a/ironicclient/osc/v1/baremetal_node.py +++ b/ironicclient/osc/v1/baremetal_node.py @@ -489,12 +489,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', @@ -547,7 +551,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: diff --git a/ironicclient/tests/unit/osc/v1/test_baremetal_node.py b/ironicclient/tests/unit/osc/v1/test_baremetal_node.py index 3a9373b2d..54dddf2af 100644 --- a/ironicclient/tests/unit/osc/v1/test_baremetal_node.py +++ b/ironicclient/tests/unit/osc/v1/test_baremetal_node.py @@ -631,6 +631,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', diff --git a/releasenotes/notes/osc-node-list-unassociated-60e46958a0abc3e5.yaml b/releasenotes/notes/osc-node-list-unassociated-60e46958a0abc3e5.yaml new file mode 100644 index 000000000..91963a18b --- /dev/null +++ b/releasenotes/notes/osc-node-list-unassociated-60e46958a0abc3e5.yaml @@ -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.