diff --git a/openstackclient/identity/v3/domain.py b/openstackclient/identity/v3/domain.py index e33fce05c5..e0bd10202a 100644 --- a/openstackclient/identity/v3/domain.py +++ b/openstackclient/identity/v3/domain.py @@ -126,9 +126,30 @@ class DeleteDomain(command.Command): class ListDomain(command.Lister): _description = _("List domains") + def get_parser(self, prog_name): + parser = super(ListDomain, self).get_parser(prog_name) + parser.add_argument( + '--name', + metavar='', + help=_('The domain name'), + ) + parser.add_argument( + '--enabled', + dest='enabled', + action='store_true', + help=_('The domains that are enabled will be returned'), + ) + return parser + def take_action(self, parsed_args): + kwargs = {} + if parsed_args.name: + kwargs['name'] = parsed_args.name + if parsed_args.enabled: + kwargs['enabled'] = True + columns = ('ID', 'Name', 'Enabled', 'Description') - data = self.app.client_manager.identity.domains.list() + data = self.app.client_manager.identity.domains.list(**kwargs) return (columns, (utils.get_item_properties( s, columns, diff --git a/openstackclient/tests/unit/identity/v3/test_domain.py b/openstackclient/tests/unit/identity/v3/test_domain.py index 46f389e890..c39f1bd3d7 100644 --- a/openstackclient/tests/unit/identity/v3/test_domain.py +++ b/openstackclient/tests/unit/identity/v3/test_domain.py @@ -293,6 +293,61 @@ class TestDomainList(TestDomain): ), ) self.assertEqual(datalist, tuple(data)) + def test_domain_list_with_option_name(self): + arglist = ['--name', + self.domain.name] + verifylist = [ + ('name', self.domain.name) + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + # In base command class Lister in cliff, abstract method take_action() + # returns a tuple containing the column names and an iterable + # containing the data to be listed. + columns, data = self.cmd.take_action(parsed_args) + + kwargs = { + 'name': self.domain.name + } + self.domains_mock.list.assert_called_with(**kwargs) + + collist = ('ID', 'Name', 'Enabled', 'Description') + self.assertEqual(collist, columns) + datalist = (( + self.domain.id, + self.domain.name, + True, + self.domain.description, + ), ) + self.assertEqual(datalist, tuple(data)) + + def test_domain_list_with_option_enabled(self): + arglist = ['--enabled'] + verifylist = [ + ('enabled', True) + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + # In base command class Lister in cliff, abstract method take_action() + # returns a tuple containing the column names and an iterable + # containing the data to be listed. + columns, data = self.cmd.take_action(parsed_args) + + kwargs = { + 'enabled': True + } + self.domains_mock.list.assert_called_with(**kwargs) + + collist = ('ID', 'Name', 'Enabled', 'Description') + self.assertEqual(collist, columns) + datalist = (( + self.domain.id, + self.domain.name, + True, + self.domain.description, + ), ) + self.assertEqual(datalist, tuple(data)) + class TestDomainSet(TestDomain): diff --git a/releasenotes/notes/add_name_and_enabled_to_list_domain-6d23f02994b51c67.yaml b/releasenotes/notes/add_name_and_enabled_to_list_domain-6d23f02994b51c67.yaml new file mode 100644 index 0000000000..4eb58b7833 --- /dev/null +++ b/releasenotes/notes/add_name_and_enabled_to_list_domain-6d23f02994b51c67.yaml @@ -0,0 +1,3 @@ +--- +features: + - Add ``--name`` and ``--domain`` option to ``domain list`` command. \ No newline at end of file