diff options
31 files changed, 499 insertions, 331 deletions
diff --git a/doc/source/command-objects/volume-type.rst b/doc/source/command-objects/volume-type.rst index b7aea632..50acf9fa 100644 --- a/doc/source/command-objects/volume-type.rst +++ b/doc/source/command-objects/volume-type.rst @@ -150,7 +150,7 @@ Unset volume type properties .. code:: bash os volume type unset - [--property <key>] + [--property <key> [...] ] [--project <project>] [--project-domain <project-domain>] <volume-type> diff --git a/functional/tests/network/v2/test_ip_availability.py b/functional/tests/network/v2/test_ip_availability.py new file mode 100644 index 00000000..f1302d5f --- /dev/null +++ b/functional/tests/network/v2/test_ip_availability.py @@ -0,0 +1,53 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import uuid + +from functional.common import test + + +class IPAvailabilityTests(test.TestCase): + """Functional tests for IP availability. """ + NAME = uuid.uuid4().hex + NETWORK_NAME = uuid.uuid4().hex + FIELDS = ['network_name'] + + @classmethod + def setUpClass(cls): + # Create a network for the subnet. + cls.openstack('network create ' + cls.NETWORK_NAME) + opts = cls.get_show_opts(['name']) + raw_output = cls.openstack( + 'subnet create --network ' + cls.NETWORK_NAME + + ' --subnet-range 10.10.10.0/24 ' + + cls.NAME + opts + ) + expected = cls.NAME + '\n' + cls.assertOutput(expected, raw_output) + + @classmethod + def tearDownClass(cls): + raw_subnet = cls.openstack('subnet delete ' + cls.NAME) + raw_network = cls.openstack('network delete ' + cls.NETWORK_NAME) + cls.assertOutput('', raw_subnet) + cls.assertOutput('', raw_network) + + def test_ip_availability_list(self): + opts = ' -f csv -c "Network Name"' + raw_output = self.openstack('ip availability list' + opts) + self.assertIn(self.NETWORK_NAME, raw_output) + + def test_ip_availability_show(self): + opts = self.get_show_opts(self.FIELDS) + raw_output = self.openstack( + 'ip availability show ' + self.NETWORK_NAME + opts) + self.assertEqual(self.NETWORK_NAME + "\n", raw_output) diff --git a/openstackclient/identity/v2_0/catalog.py b/openstackclient/identity/v2_0/catalog.py index 53a6fe34..c8f48cb6 100644 --- a/openstackclient/identity/v2_0/catalog.py +++ b/openstackclient/identity/v2_0/catalog.py @@ -89,7 +89,7 @@ class ShowCatalog(command.ShowOne): break if not data: - self.app.log.error('service %s not found\n' % + self.app.log.error(_('service %s not found\n') % parsed_args.service) return ([], []) diff --git a/openstackclient/identity/v2_0/endpoint.py b/openstackclient/identity/v2_0/endpoint.py index fcb82eb7..09ea738f 100644 --- a/openstackclient/identity/v2_0/endpoint.py +++ b/openstackclient/identity/v2_0/endpoint.py @@ -81,7 +81,8 @@ class DeleteEndpoint(command.Command): parser.add_argument( 'endpoint', metavar='<endpoint-id>', - help=_('Endpoint ID to delete')) + help=_('Endpoint ID to delete'), + ) return parser def take_action(self, parsed_args): diff --git a/openstackclient/identity/v2_0/project.py b/openstackclient/identity/v2_0/project.py index d90162c9..80f88d73 100644 --- a/openstackclient/identity/v2_0/project.py +++ b/openstackclient/identity/v2_0/project.py @@ -88,7 +88,7 @@ class CreateProject(command.ShowOne): identity_client.tenants, parsed_args.name, ) - self.log.info('Returning existing project %s', project.name) + self.log.info(_('Returning existing project %s'), project.name) else: raise e @@ -231,7 +231,8 @@ class ShowProject(command.ShowOne): parser.add_argument( 'project', metavar='<project>', - help=_('Project to display (name or ID)')) + help=_('Project to display (name or ID)'), + ) return parser def take_action(self, parsed_args): @@ -295,9 +296,9 @@ class UnsetProject(command.Command): metavar='<key>', action='append', default=[], + required=True, help=_('Unset a project property ' '(repeat option to unset multiple properties)'), - required=True, ) return parser @@ -308,7 +309,7 @@ class UnsetProject(command.Command): parsed_args.project, ) if not parsed_args.property: - self.app.log.error("No changes requested\n") + self.app.log.error(_("No changes requested\n")) else: kwargs = project._info for key in parsed_args.property: diff --git a/openstackclient/identity/v2_0/role.py b/openstackclient/identity/v2_0/role.py index 1fcee15f..6b014d86 100644 --- a/openstackclient/identity/v2_0/role.py +++ b/openstackclient/identity/v2_0/role.py @@ -95,7 +95,7 @@ class CreateRole(command.ShowOne): identity_client.roles, parsed_args.role_name, ) - self.log.info('Returning existing role %s', role.name) + self.log.info(_('Returning existing role %s'), role.name) else: raise e @@ -136,12 +136,12 @@ class ListRole(command.Lister): parser.add_argument( '--project', metavar='<project>', - help='Filter roles by <project> (name or ID)', + help=_('Filter roles by <project> (name or ID)'), ) parser.add_argument( '--user', metavar='<user>', - help='Filter roles by <user> (name or ID)', + help=_('Filter roles by <user> (name or ID)'), ) return parser diff --git a/openstackclient/identity/v2_0/user.py b/openstackclient/identity/v2_0/user.py index bc9bf837..f8f5df29 100644 --- a/openstackclient/identity/v2_0/user.py +++ b/openstackclient/identity/v2_0/user.py @@ -104,7 +104,7 @@ class CreateUser(command.ShowOne): identity_client.users, parsed_args.name, ) - self.log.info('Returning existing user %s', user.name) + self.log.info(_('Returning existing user %s'), user.name) else: raise e @@ -159,7 +159,8 @@ class ListUser(command.Lister): '--long', action='store_true', default=False, - help=_('List additional fields in output')) + help=_('List additional fields in output'), + ) return parser def take_action(self, parsed_args): diff --git a/openstackclient/identity/v3/catalog.py b/openstackclient/identity/v3/catalog.py index 78d71f59..4c794692 100644 --- a/openstackclient/identity/v3/catalog.py +++ b/openstackclient/identity/v3/catalog.py @@ -84,7 +84,7 @@ class ShowCatalog(command.ShowOne): break if not data: - self.app.log.error('service %s not found\n' % + self.app.log.error(_('service %s not found\n') % parsed_args.service) return ([], []) diff --git a/openstackclient/identity/v3/consumer.py b/openstackclient/identity/v3/consumer.py index 83809e51..a062b743 100644 --- a/openstackclient/identity/v3/consumer.py +++ b/openstackclient/identity/v3/consumer.py @@ -20,6 +20,7 @@ import sys from openstackclient.common import command from openstackclient.common import utils +from openstackclient.i18n import _ class CreateConsumer(command.ShowOne): @@ -30,7 +31,7 @@ class CreateConsumer(command.ShowOne): parser.add_argument( '--description', metavar='<description>', - help='New consumer description', + help=_('New consumer description'), ) return parser @@ -51,7 +52,7 @@ class DeleteConsumer(command.Command): parser.add_argument( 'consumer', metavar='<consumer>', - help='Consumer to delete', + help=_('Consumer to delete'), ) return parser @@ -83,12 +84,12 @@ class SetConsumer(command.Command): parser.add_argument( 'consumer', metavar='<consumer>', - help='Consumer to modify', + help=_('Consumer to modify'), ) parser.add_argument( '--description', metavar='<description>', - help='New consumer description', + help=_('New consumer description'), ) return parser @@ -101,7 +102,7 @@ class SetConsumer(command.Command): kwargs['description'] = parsed_args.description if not len(kwargs): - sys.stdout.write('Consumer not updated, no arguments present\n') + sys.stdout.write(_('Consumer not updated, no arguments present\n')) return consumer = identity_client.oauth1.consumers.update( @@ -116,7 +117,7 @@ class ShowConsumer(command.ShowOne): parser.add_argument( 'consumer', metavar='<consumer>', - help='Consumer to display', + help=_('Consumer to display'), ) return parser diff --git a/openstackclient/identity/v3/credential.py b/openstackclient/identity/v3/credential.py index b0d2cafd..99013478 100644 --- a/openstackclient/identity/v3/credential.py +++ b/openstackclient/identity/v3/credential.py @@ -19,6 +19,7 @@ import six from openstackclient.common import command from openstackclient.common import utils +from openstackclient.i18n import _ class CreateCredential(command.ShowOne): @@ -29,24 +30,25 @@ class CreateCredential(command.ShowOne): parser.add_argument( 'user', metavar='<user>', - help='Name or ID of user that owns the credential', + help=_('Name or ID of user that owns the credential'), ) parser.add_argument( '--type', default="cert", metavar='<type>', choices=['ec2', 'cert'], - help='New credential type', + help=_('New credential type'), ) parser.add_argument( 'data', metavar='<data>', - help='New credential data', + help=_('New credential data'), ) parser.add_argument( '--project', metavar='<project>', - help='Project name or ID which limits the scope of the credential', + help=_('Project name or ID which limits the ' + 'scope of the credential'), ) return parser @@ -77,7 +79,7 @@ class DeleteCredential(command.Command): parser.add_argument( 'credential', metavar='<credential-id>', - help='ID of credential to delete', + help=_('ID of credential to delete'), ) return parser @@ -108,31 +110,32 @@ class SetCredential(command.Command): parser.add_argument( 'credential', metavar='<credential-id>', - help='ID of credential to change', + help=_('ID of credential to change'), ) parser.add_argument( '--user', metavar='<user>', required=True, - help='Name or ID of user that owns the credential', + help=_('Name or ID of user that owns the credential'), ) parser.add_argument( '--type', metavar='<type>', choices=['ec2', 'cert'], required=True, - help='New credential type', + help=_('New credential type'), ) parser.add_argument( '--data', metavar='<data>', required=True, - help='New credential data', + help=_('New credential data'), ) parser.add_argument( '--project', metavar='<project>', - help='Project name or ID which limits the scope of the credential', + help=_('Project name or ID which limits the ' + 'scope of the credential'), ) return parser @@ -163,7 +166,7 @@ class ShowCredential(command.ShowOne): parser.add_argument( 'credential', metavar='<credential-id>', - help='ID of credential to display', + help=_('ID of credential to display'), ) return parser diff --git a/openstackclient/identity/v3/domain.py b/openstackclient/identity/v3/domain.py index fc5aba12..c345028f 100644 --- a/openstackclient/identity/v3/domain.py +++ b/openstackclient/identity/v3/domain.py @@ -33,23 +33,23 @@ class CreateDomain(command.ShowOne): parser.add_argument( 'name', metavar='<domain-name>', - help='New domain name', + help=_('New domain name'), ) parser.add_argument( '--description', metavar='<description>', - help='New domain description', + help=_('New domain description'), ) enable_group = parser.add_mutually_exclusive_group() enable_group.add_argument( '--enable', action='store_true', - help='Enable domain (default)', + help=_('Enable domain (default)'), ) enable_group.add_argument( '--disable', action='store_true', - help='Disable domain', + help=_('Disable domain'), ) parser.add_argument( '--or-show', @@ -75,7 +75,7 @@ class CreateDomain(command.ShowOne): if parsed_args.or_show: domain = utils.find_resource(identity_client.domains, parsed_args.name) - self.log.info('Returning existing domain %s', domain.name) + self.log.info(_('Returning existing domain %s'), domain.name) else: raise e @@ -91,7 +91,7 @@ class DeleteDomain(command.Command): parser.add_argument( 'domain', metavar='<domain>', - help='Domain to delete (name or ID)', + help=_('Domain to delete (name or ID)'), ) return parser @@ -123,28 +123,28 @@ class SetDomain(command.Command): parser.add_argument( 'domain', metavar='<domain>', - help='Domain to modify (name or ID)', + help=_('Domain to modify (name or ID)'), ) parser.add_argument( '--name', metavar='<name>', - help='New domain name', + help=_('New domain name'), ) parser.add_argument( '--description', metavar='<description>', - help='New domain description', + help=_('New domain description'), ) enable_group = parser.add_mutually_exclusive_group() enable_group.add_argument( '--enable', action='store_true', - help='Enable domain', + help=_('Enable domain'), ) enable_group.add_argument( '--disable', action='store_true', - help='Disable domain', + help=_('Disable domain'), ) return parser @@ -164,7 +164,7 @@ class SetDomain(command.Command): kwargs['enabled'] = False if not kwargs: - sys.stdout.write("Domain not updated, no arguments present\n") + sys.stdout.write(_("Domain not updated, no arguments present\n")) return identity_client.domains.update(domain.id, **kwargs) @@ -177,7 +177,7 @@ class ShowDomain(command.ShowOne): parser.add_argument( 'domain', metavar='<domain>', - help='Domain to display (name or ID)', + help=_('Domain to display (name or ID)'), ) return parser diff --git a/openstackclient/identity/v3/ec2creds.py b/openstackclient/identity/v3/ec2creds.py index a12b2d3b..859ec2a7 100644 --- a/openstackclient/identity/v3/ec2creds.py +++ b/openstackclient/identity/v3/ec2creds.py @@ -56,18 +56,14 @@ class CreateEC2Creds(command.ShowOne): parser.add_argument( '--project', metavar='<project>', - help=_( - 'Create credentials in project ' - '(name or ID; default: current authenticated project)' - ), + help=_('Create credentials in project ' + '(name or ID; default: current authenticated project)'), ) parser.add_argument( '--user', metavar='<user>', - help=_( - 'Create credentials for user ' - '(name or ID; default: current authenticated user)' - ), + help=_('Create credentials for user ' + '(name or ID; default: current authenticated user)'), ) common.add_user_domain_option_to_parser(parser) common.add_project_domain_option_to_parser(parser) diff --git a/openstackclient/identity/v3/endpoint.py b/openstackclient/identity/v3/endpoint.py index 5bc9d06b..39022d27 100644 --- a/openstackclient/identity/v3/endpoint.py +++ b/openstackclient/identity/v3/endpoint.py @@ -20,6 +20,7 @@ import sys from openstackclient.common import command from openstackclient.common import utils +from openstackclient.i18n import _ from openstackclient.identity import common @@ -38,23 +39,23 @@ class CreateEndpoint(command.ShowOne): parser.add_argument( 'service', metavar='<service>', - help='New endpoint service (name or ID)', + help=_('New endpoint service (name or ID)'), ) parser.add_argument( 'interface', metavar='<interface>', choices=['admin', 'public', 'internal'], - help='New endpoint interface type (admin, public or internal)', + help=_('New endpoint interface type (admin, public or internal)'), ) parser.add_argument( 'url', metavar='<url>', - help='New endpoint URL', + help=_('New endpoint URL'), ) parser.add_argument( '--region', metavar='<region-id>', - help='New endpoint region ID', + help=_('New endpoint region ID'), ) enable_group = parser.add_mutually_exclusive_group() enable_group.add_argument( @@ -62,13 +63,13 @@ class CreateEndpoint(command.ShowOne): dest='enabled', action='store_true', default=True, - help='Enable endpoint (default)', + help=_('Enable endpoint (default)'), ) enable_group.add_argument( '--disable', dest='enabled', action='store_false', - help='Disable endpoint', + help=_('Disable endpoint'), ) return parser @@ -100,7 +101,7 @@ class DeleteEndpoint(command.Command): parser.add_argument( 'endpoint', metavar='<endpoint-id>', - help='Endpoint ID to delete', + help=_('Endpoint ID to delete'), ) return parser @@ -119,18 +120,18 @@ class ListEndpoint(command.Lister): parser.add_argument( '--service', metavar='<service>', - help='Filter by service', + help=_('Filter by service'), ) parser.add_argument( '--interface', metavar='<interface>', choices=['admin', 'public', 'internal'], - help='Filter by interface type (admin, public or internal)', + help=_('Filter by interface type (admin, public or internal)'), ) parser.add_argument( '--region', metavar='<region-id>', - help='Filter by region ID', + help=_('Filter by region ID'), ) return parser @@ -167,41 +168,41 @@ class SetEndpoint(command.Command): parser.add_argument( 'endpoint', metavar='<endpoint-id>', - help='Endpoint ID to modify', + help=_('Endpoint ID to modify'), ) parser.add_argument( '--region', metavar='<region-id>', - help='New endpoint region ID', + help=_('New endpoint region ID'), ) parser.add_argument( '--interface', metavar='<interface>', choices=['admin', 'public', 'internal'], - help='New endpoint interface type (admin, public or internal)', + help=_('New endpoint interface type (admin, public or internal)'), ) parser.add_argument( '--url', metavar='<url>', - help='New endpoint URL', + help=_('New endpoint URL'), ) parser.add_argument( '--service', metavar='<service>', - help='New endpoint service (name or ID)', + help=_('New endpoint service (name or ID)'), ) enable_group = parser.add_mutually_exclusive_group() enable_group.add_argument( '--enable', dest='enabled', action='store_true', - help='Enable endpoint', + help=_('Enable endpoint'), ) enable_group.add_argument( '--disable', dest='disabled', action='store_true', - help='Disable endpoint', + help=_('Disable endpoint'), ) return parser @@ -213,7 +214,7 @@ class SetEndpoint(command.Command): if (not parsed_args.interface and not parsed_args.url and not parsed_args.service and not parsed_args.region and not parsed_args.enabled and not parsed_args.disabled): - sys.stdout.write("Endpoint not updated, no arguments present\n") + sys.stdout.write(_("Endpoint not updated, no arguments present\n")) return service_id = None @@ -244,8 +245,8 @@ class ShowEndpoint(command.ShowOne): parser.add_argument( 'endpoint', metavar='<endpoint>', - help='Endpoint to display (endpoint ID, service ID,' - ' service name, service type)', + help=_('Endpoint to display (endpoint ID, service ID,' + ' service name, service type)'), ) return parser diff --git a/openstackclient/identity/v3/federation_protocol.py b/openstackclient/identity/v3/federation_protocol.py index 27c837c5..c0f4bc93 100644 --- a/openstackclient/identity/v3/federation_protocol.py +++ b/openstackclient/identity/v3/federation_protocol.py @@ -18,6 +18,7 @@ import six from openstackclient.common import command from openstackclient.common import utils +from openstackclient.i18n import _ class CreateProtocol(command.ShowOne): @@ -28,19 +29,22 @@ class CreateProtocol(command.ShowOne): parser.add_argument( 'federation_protocol', metavar='<name>', - help='New federation protocol name (must be unique per identity ' - ' provider)') + help=_('New federation protocol name (must be unique ' + 'per identity provider)'), + ) parser.add_argument( '--identity-provider', metavar='<identity-provider>', required=True, - help='Identity provider that will support the new federation ' - ' protocol (name or ID) (required)') + help=_('Identity provider that will support the new federation ' + ' protocol (name or ID) (required)'), + ) parser.add_argument( '--mapping', metavar='<mapping>', required=True, - help='Mapping that is to be used (name or ID) (required)') + help=_('Mapping that is to be used (name or ID) (required)'), + ) return parser @@ -69,13 +73,15 @@ class DeleteProtocol(command.Command): parser.add_argument( 'federation_protocol', metavar='<federation-protocol>', - help='Federation protocol to delete (name or ID)') + help=_('Federation protocol to delete (name or ID)'), + ) parser.add_argument( '--identity-provider', metavar='<identity-provider>', required=True, - help='Identity provider that supports <federation-protocol> ' - '(name or ID) (required)') + help=_('Identity provider that supports <federation-protocol> ' + '(name or ID) (required)'), + ) return parser @@ -94,7 +100,8 @@ class ListProtocols(command.Lister): '--identity-provider', metavar='<identity-provider>', required=True, - help='Identity provider to list (name or ID) (required)') + help=_('Identity provider to list (name or ID) (required)'), + ) return parser @@ -118,24 +125,27 @@ class SetProtocol(command.Command): parser.add_argument( 'federation_protocol', metavar='<name>', - help='Federation protocol to modify (name or ID)') + help=_('Federation protocol to modify (name or ID)'), + ) parser.add_argument( '--identity-provider', metavar='<identity-provider>', required=True, - help='Identity provider that supports <federation-protocol> ' - '(name or ID) (required)') + help=_('Identity provider that supports <federation-protocol> ' + '(name or ID) (required)'), + ) parser.add_argument( '--mapping', metavar='<mapping>', - help='Mapping that is to be used (name or ID)') + help=_('Mapping that is to be used (name or ID)'), + ) return parser def take_action(self, parsed_args): identity_client = self.app.client_manager.identity if not parsed_args.mapping: - self.app.log.error("No changes requested") + self.app.log.error(_("No changes requested")) return protocol = identity_client.federation.protocols.update( @@ -159,13 +169,15 @@ class ShowProtocol(command.ShowOne): parser.add_argument( 'federation_protocol', metavar='<federation-protocol>', - help='Federation protocol to display (name or ID)') + help=_('Federation protocol to display (name or ID)'), + ) parser.add_argument( '--identity-provider', metavar='<identity-provider>', required=True, - help=('Identity provider that supports <federation-protocol> ' - '(name or ID) (required)')) + help=_('Identity provider that supports <federation-protocol> ' + '(name or ID) (required)'), + ) return parser def take_action(self, parsed_args): diff --git a/openstackclient/identity/v3/group.py b/openstackclient/identity/v3/group.py index 8fb8a047..fdb94da6 100644 --- a/openstackclient/identity/v3/group.py +++ b/openstackclient/identity/v3/group.py @@ -34,12 +34,12 @@ class AddUserToGroup(command.Command): parser.add_argument( 'group', metavar='<group>', - help='Group to contain <user> (name or ID)', + help=_('Group to contain <user> (name or ID)'), ) parser.add_argument( 'user', metavar='<user>', - help='User to add to <group> (name or ID)', + help=_('User to add to <group> (name or ID)'), ) common.add_group_domain_option_to_parser(parser) common.add_user_domain_option_to_parser(parser) @@ -58,11 +58,17 @@ class AddUserToGroup(command.Command): try: identity_client.users.add_to_group(user_id, group_id) except Exception: - sys.stderr.write("%s not added to group %s\n" % - (parsed_args.user, parsed_args.group)) + msg = _("%(user)s not added to group %(group)s\n") % { + 'user': parsed_args.user, + 'group': parsed_args.group, + } + sys.stderr.write(msg) else: - sys.stdout.write("%s added to group %s\n" % - (parsed_args.user, parsed_args.group)) + msg = _("%(user)s added to group %(group)s\n") % { + 'user': parsed_args.user, + 'group': parsed_args.group, + } + sys.stdout.write(msg) class CheckUserInGroup(command.Command): @@ -73,12 +79,12 @@ class CheckUserInGroup(command.Command): parser.add_argument( 'group', metavar='<group>', - help='Group to check (name or ID)', + help=_('Group to check (name or ID)'), ) parser.add_argument( 'user', metavar='<user>', - help='User to check (name or ID)', + help=_('User to check (name or ID)'), ) common.add_group_domain_option_to_parser(parser) common.add_user_domain_option_to_parser(parser) @@ -97,11 +103,17 @@ class CheckUserInGroup(command.Command): try: identity_client.users.check_in_group(user_id, group_id) except Exception: - sys.stderr.write("%s not in group %s\n" % - (parsed_args.user, parsed_args.group)) + msg = _("%(user)s not in group %(group)s\n") % { + 'user': parsed_args.user, + 'group': parsed_args.group, + } + sys.stderr.write(msg) else: - sys.stdout.write("%s in group %s\n" % - (parsed_args.user, parsed_args.group)) + msg = _("%(user)s in group %(group)s\n") % { + 'user': parsed_args.user, + 'group': parsed_args.group, + } + sys.stdout.write(msg) class CreateGroup(command.ShowOne): @@ -112,17 +124,17 @@ class CreateGroup(command.ShowOne): parser.add_argument( 'name', metavar='<group-name>', - help='New group name', + help=_('New group name'), ) parser.add_argument( '--domain', metavar='<domain>', - help='Domain to contain new group (name or ID)', + help=_('Domain to contain new group (name or ID)'), ) parser.add_argument( '--description', metavar='<description>', - help='New group description', + help=_('New group description'), ) parser.add_argument( '--or-show', @@ -149,7 +161,7 @@ class CreateGroup(command.ShowOne): group = utils.find_resource(identity_client.groups, parsed_args.name, domain_id=domain) - self.log.info('Returning existing group %s', group.name) + self.log.info(_('Returning existing group %s'), group.name) else: raise e @@ -166,11 +178,12 @@ class DeleteGroup(command.Command): 'groups', metavar='<group>', nargs="+", - help='Group(s) to delete (name or ID)') + help=_('Group(s) to delete (name or ID)'), + ) parser.add_argument( '--domain', metavar='<domain>', - help='Domain containing group(s) (name or ID)', + help=_('Domain containing group(s) (name or ID)'), ) return parser @@ -192,19 +205,19 @@ class ListGroup(command.Lister): parser.add_argument( '--domain', metavar='<domain>', - help='Filter group list by <domain> (name or ID)', + help=_('Filter group list by <domain> (name or ID)'), ) parser.add_argument( '--user', metavar='<user>', - help='Filter group list by <user> (name or ID)', + help=_('Filter group list by <user> (name or ID)'), ) common.add_user_domain_option_to_parser(parser) parser.add_argument( '--long', action='store_true', default=False, - help='List additional fields in output', + help=_('List additional fields in output'), ) return parser @@ -252,12 +265,12 @@ class RemoveUserFromGroup(command.Command): parser.add_argument( 'group', metavar='<group>', - help='Group containing <user> (name or ID)', + help=_('Group containing <user> (name or ID)'), ) parser.add_argument( 'user', metavar='<user>', - help='User to remove from <group> (name or ID)', + help=_('User to remove from <group> (name or ID)'), ) common.add_group_domain_option_to_parser(parser) common.add_user_domain_option_to_parser(parser) @@ -276,11 +289,17 @@ class RemoveUserFromGroup(command.Command): try: identity_client.users.remove_from_group(user_id, group_id) except Exception: - sys.stderr.write("%s not removed from group %s\n" % - (parsed_args.user, parsed_args.group)) + msg = _("%(user)s not removed from group %(group)s\n") % { + 'user': parsed_args.user, + 'group': parsed_args.group, + } + sys.stderr.write(msg) else: - sys.stdout.write("%s removed from group %s\n" % - (parsed_args.user, parsed_args.group)) + msg = _("%(user)s removed from group %(group)s\n") % { + 'user': parsed_args.user, + 'group': parsed_args.group, + } + sys.stdout.write(msg) class SetGroup(command.Command): @@ -291,20 +310,23 @@ class SetGroup(command.Command): parser.add_argument( 'group', metavar='<group>', - help='Group to modify (name or ID)') + help=_('Group to modify (name or ID)'), + ) parser.add_argument( '--domain', metavar='<domain>', - help='Domain containing <group> (name or ID)', + help=_('Domain containing <group> (name or ID)'), ) parser.add_argument( '--name', metavar='<name>', - help='New group name') + help=_('New group name'), + ) parser.add_argument( '--description', metavar='<description>', - help='New group description') + help=_('New group description'), + ) return parser def take_action(self, parsed_args): @@ -331,12 +353,12 @@ class ShowGroup(command.ShowOne): parser.add_argument( 'group', metavar='<group>', - help='Group to display (name or ID)', + help=_('Group to display (name or ID)'), ) parser.add_argument( '--domain', metavar='<domain>', - help='Domain containing <group> (name or ID)', + help=_('Domain containing <group> (name or ID)'), ) return parser diff --git a/openstackclient/identity/v3/identity_provider.py b/openstackclient/identity/v3/identity_provider.py index 39f440f4..3749aa35 100644 --- a/openstackclient/identity/v3/identity_provider.py +++ b/openstackclient/identity/v3/identity_provider.py @@ -17,6 +17,7 @@ import six from openstackclient.common import command from openstackclient.common import utils +from openstackclient.i18n import _ class CreateIdentityProvider(command.ShowOne): @@ -27,26 +28,26 @@ class CreateIdentityProvider(command.ShowOne): parser.add_argument( 'identity_provider_id', metavar='<name>', - help='New identity provider name (must be unique)' + help=_('New identity provider name (must be unique)'), ) identity_remote_id_provider = parser.add_mutually_exclusive_group() identity_remote_id_provider.add_argument( '--remote-id', metavar='<remote-id>', action='append', - help='Remote IDs to associate with the Identity Provider ' - '(repeat option to provide multiple values)' + help=_('Remote IDs to associate with the Identity Provider ' + '(repeat option to provide multiple values)'), ) identity_remote_id_provider.add_argument( '--remote-id-file', metavar='<file-name>', - help='Name of a file that contains many remote IDs to associate ' - 'with the identity provider, one per line' + help=_('Name of a file that contains many remote IDs to associate ' + 'with the identity provider, one per line'), ) parser.add_argument( '--description', metavar='<description>', - help='New identity provider description', + help=_('New identity provider description'), ) enable_identity_provider = parser.add_mutually_exclusive_group() enable_identity_provider.add_argument( @@ -54,13 +55,13 @@ class CreateIdentityProvider(command.ShowOne): dest='enabled', action='store_true', default=True, - help='Enable identity provider (default)', + help=_('Enable identity provider (default)'), ) enable_identity_provider.add_argument( '--disable', dest='enabled', action='store_false', - help='Disable the identity provider', + help=_('Disable the identity provider'), ) return parser @@ -94,7 +95,7 @@ class DeleteIdentityProvider(command.Command): parser.add_argument( 'identity_provider', metavar='<identity-provider>', - help='Identity provider to delete', + help=_('Identity provider to delete'), ) return parser @@ -126,37 +127,37 @@ class SetIdentityProvider(command.Command): parser.add_argument( 'identity_provider', metavar='<identity-provider>', - help='Identity provider to modify', + help=_('Identity provider to modify'), ) parser.add_argument( '--description', metavar='<description>', - help='Set identity provider description', + help=_('Set identity provider description'), ) identity_remote_id_provider = parser.add_mutually_exclusive_group() identity_remote_id_provider.add_argument( '--remote-id', metavar='<remote-id>', action='append', - help='Remote IDs to associate with the Identity Provider ' - '(repeat option to provide multiple values)' + help=_('Remote IDs to associate with the Identity Provider ' + '(repeat option to provide multiple values)'), ) identity_remote_id_provider.add_argument( '--remote-id-file', metavar='<file-name>', - help='Name of a file that contains many remote IDs to associate ' - 'with the identity provider, one per line' + help=_('Name of a file that contains many remote IDs to associate ' + 'with the identity provider, one per line'), ) enable_identity_provider = parser.add_mutually_exclusive_group() enable_identity_provider.add_argument( '--enable', action='store_true', - help='Enable the identity provider', + help=_('Enable the identity provider'), ) enable_identity_provider.add_argument( '--disable', action='store_true', - help='Disable the identity provider', + help=_('Disable the identity provider'), ) return parser @@ -168,7 +169,7 @@ class SetIdentityProvider(command.Command): not parsed_args.remote_id and not parsed_args.remote_id_file and not parsed_args.description): - self.log.error('No changes requested') + self.log.error(_('No changes requested')) return (None, None) # Always set remote_ids if either is passed in @@ -206,7 +207,7 @@ class ShowIdentityProvider(command.ShowOne): parser.add_argument( 'identity_provider', metavar='<identity-provider>', - help='Identity provider to display', + help=_('Identity provider to display'), ) return parser diff --git a/openstackclient/identity/v3/mapping.py b/openstackclient/identity/v3/mapping.py index 3cdc8afc..c45796e4 100644 --- a/openstackclient/identity/v3/mapping.py +++ b/openstackclient/identity/v3/mapping.py @@ -22,6 +22,7 @@ import six from openstackclient.common import command from openstackclient.common import exceptions from openstackclient.common import utils +from openstackclient.i18n import _ class _RulesReader(object): @@ -69,9 +70,9 @@ class _RulesReader(object): try: rules = json.loads(blob) except ValueError as e: - raise exceptions.CommandError( - 'An error occurred when reading ' - 'rules from file %s: %s' % (path, e)) + msg = _("An error occurred when reading rules from file " + "%(path)s: %(error)s") % {"path": path, "error": e} + raise exceptions.CommandError(msg) else: return rules @@ -84,12 +85,12 @@ class CreateMapping(command.ShowOne, _RulesReader): parser.add_argument( 'mapping', metavar='<name>', - help='New mapping name (must be unique)', + help=_('New mapping name (must be unique)'), ) parser.add_argument( '--rules', metavar='<filename>', required=True, - help='Filename that contains a set of mapping rules (required)', + help=_('Filename that contains a set of mapping rules (required)'), ) return parser @@ -113,7 +114,7 @@ class DeleteMapping(command.Command): parser.add_argument( 'mapping', metavar='<mapping>', - help='Mapping to delete', + help=_('Mapping to delete'), ) return parser @@ -145,12 +146,12 @@ class SetMapping(command.Command, _RulesReader): parser.add_argument( 'mapping', metavar='<name>', - help='Mapping to modify', + help=_('Mapping to modify'), ) parser.add_argument( '--rules', metavar='<filename>', - help='Filename that contains a new set of mapping rules', + help=_('Filename that contains a new set of mapping rules'), ) return parser @@ -158,7 +159,7 @@ class SetMapping(command.Command, _RulesReader): identity_client = self.app.client_manager.identity if not parsed_args.rules: - self.app.log.error("No changes requested") + self.app.log.error(_("No changes requested")) return rules = self._read_rules(parsed_args.rules) @@ -179,7 +180,7 @@ class ShowMapping(command.ShowOne): parser.add_argument( 'mapping', metavar='<mapping>', - help='Mapping to display', + help=_('Mapping to display'), ) return parser diff --git a/openstackclient/identity/v3/policy.py b/openstackclient/identity/v3/policy.py index 3c2d1a7c..74a783b0 100644 --- a/openstackclient/identity/v3/policy.py +++ b/openstackclient/identity/v3/policy.py @@ -20,6 +20,7 @@ import sys from openstackclient.common import command from openstackclient.common import utils +from openstackclient.i18n import _ class CreatePolicy(command.ShowOne): @@ -31,13 +32,13 @@ class CreatePolicy(command.ShowOne): '--type', metavar='<type>', default="application/json", - help='New MIME type of the policy rules file ' - '(defaults to application/json)', + help=_('New MIME type of the policy rules file ' + '(defaults to application/json)'), ) parser.add_argument( 'rules', metavar='<filename>', - help='New serialized policy rules file', + help=_('New serialized policy rules file'), ) return parser @@ -62,7 +63,7 @@ class DeletePolicy(command.Command): parser.add_argument( 'policy', metavar='<policy>', - help='Policy to delete', + help=_('Policy to delete'), ) return parser @@ -80,7 +81,7 @@ class ListPolicy(command.Lister): '--long', action='store_true', default=False, - help='List additional fields in output', + help=_('List additional fields in output'), ) return parser @@ -107,17 +108,17 @@ class SetPolicy(command.Command): parser.add_argument( 'policy', metavar='<policy>', - help='Policy to modify', + help=_('Policy to modify'), ) parser.add_argument( '--type', metavar='<type>', - help='New MIME type of the policy rules file', + help=_('New MIME type of the policy rules file'), ) parser.add_argument( '--rules', metavar='<filename>', - help='New serialized policy rules file', + help=_('New serialized policy rules file'), ) return parser @@ -135,7 +136,7 @@ class SetPolicy(command.Command): kwargs['type'] = parsed_args.type if not kwargs: - sys.stdout.write('Policy not updated, no arguments present \n') + sys.stdout.write(_('Policy not updated, no arguments present\n')) return identity_client.policies.update(parsed_args.policy, **kwargs) @@ -148,7 +149,7 @@ class ShowPolicy(command.ShowOne): parser.add_argument( 'policy', metavar='<policy>', - help='Policy to display', + help=_('Policy to display'), ) return parser diff --git a/openstackclient/identity/v3/project.py b/openstackclient/identity/v3/project.py index 4990b1b9..acf639f2 100644 --- a/openstackclient/identity/v3/project.py +++ b/openstackclient/identity/v3/project.py @@ -34,40 +34,40 @@ class CreateProject(command.ShowOne): parser.add_argument( 'name', metavar='<project-name>', - help='New project name', + help=_('New project name'), ) parser.add_argument( '--domain', metavar='<domain>', - help='Domain owning the project (name or ID)', + help=_('Domain owning the project (name or ID)'), ) parser.add_argument( '--parent', metavar='<project>', - help='Parent of the project (name or ID)', + help=_('Parent of the project (name or ID)'), ) parser.add_argument( '--description', metavar='<description>', - help='Project description', + help=_('Project description'), ) enable_group = parser.add_mutually_exclusive_group() enable_group.add_argument( '--enable', action='store_true', - help='Enable project', + help=_('Enable project'), ) enable_group.add_argument( '--disable', action='store_true', - help='Disable project', + help=_('Disable project'), ) parser.add_argument( '--property', metavar='<key=value>', action=parseractions.KeyValueAction, - help='Add a property to <name> ' - '(repeat option to set multiple properties)', + help=_('Add a property to <name> ' + '(repeat option to set multiple properties)'), ) parser.add_argument( '--or-show', @@ -112,7 +112,7 @@ class CreateProject(command.ShowOne): project = utils.find_resource(identity_client.projects, parsed_args.name, domain_id=domain) - self.log.info('Returning existing project %s', project.name) + self.log.info(_('Returning existing project %s'), project.name) else: raise e @@ -129,12 +129,12 @@ class DeleteProject(command.Command): 'projects', metavar='<project>', nargs="+", - help='Project(s) to delete (name or ID)', + help=_('Project(s) to delete (name or ID)'), ) parser.add_argument( '--domain', metavar='<domain>', - help='Domain owning <project> (name or ID)', + help=_('Domain owning <project> (name or ID)'), ) return parser @@ -163,18 +163,18 @@ class ListProject(command.Lister): parser.add_argument( '--domain', metavar='<domain>', - help='Filter projects by <domain> (name or ID)', + help=_('Filter projects by <domain> (name or ID)'), ) parser.add_argument( '--user', metavar='<user>', - help='Filter projects by <user> (name or ID)', + help=_('Filter projects by <user> (name or ID)'), ) parser.add_argument( '--long', action='store_true', default=False, - help='List additional fields in output', + help=_('List additional fields in output'), ) return parser @@ -219,40 +219,40 @@ class SetProject(command.Command): parser.add_argument( 'project', metavar='<project>', - help='Project to modify (name or ID)', + help=_('Project to modify (name or ID)'), ) parser.add_argument( '--name', metavar='<name>', - help='Set project name', + help=_('Set project name'), ) parser.add_argument( '--domain', metavar='<domain>', - help='Domain owning <project> (name or ID)', + help=_('Domain owning <project> (name or ID)'), ) parser.add_argument( '--description', metavar='<description>', - help='Set project description', + help=_('Set project description'), ) enable_group = parser.add_mutually_exclusive_group() enable_group.add_argument( '--enable', action='store_true', - help='Enable project', + help=_('Enable project'), ) enable_group.add_argument( '--disable', action='store_true', - help='Disable project', + help=_('Disable project'), ) parser.add_argument( '--property', metavar='<key=value>', action=parseractions.KeyValueAction, - help='Set a property on <project> ' - '(repeat option to set multiple properties)', + help=_('Set a property on <project> ' + '(repeat option to set multiple properties)'), ) return parser @@ -293,24 +293,24 @@ class ShowProject(command.ShowOne): parser.add_argument( 'project', metavar='<project>', - help='Project to display (name or ID)', + help=_('Project to display (name or ID)'), ) parser.add_argument( '--domain', metavar='<domain>', - help='Domain owning <project> (name or ID)', + help=_('Domain owning <project> (name or ID)'), ) parser.add_argument( '--parents', action='store_true', default=False, - help='Show the project\'s parents as a list', + help=_('Show the project\'s parents as a list'), ) parser.add_argument( '--children', action='store_true', default=False, - help='Show project\'s subtree (children) as a list', + help=_('Show project\'s subtree (children) as a list'), ) return parser diff --git a/openstackclient/identity/v3/role.py b/openstackclient/identity/v3/role.py index f93c9d80..e7078f44 100644 --- a/openstackclient/identity/v3/role.py +++ b/openstackclient/identity/v3/role.py @@ -31,23 +31,23 @@ def _add_identity_and_resource_options_to_parser(parser): domain_or_project.add_argument( '--domain', metavar='<domain>', - help='Include <domain> (name or ID)', + help=_('Include <domain> (name or ID)'), ) domain_or_project.add_argument( '--project', metavar='<project>', - help='Include <project> (name or ID)', + help=_('Include <project> (name or ID)'), ) user_or_group = parser.add_mutually_exclusive_group() user_or_group.add_argument( '--user', metavar='<user>', - help='Include <user> (name or ID)', + help=_('Include <user> (name or ID)'), ) user_or_group.add_argument( '--group', metavar='<group>', - help='Include <group> (name or ID)', + help=_('Include <group> (name or ID)'), ) common.add_group_domain_option_to_parser(parser) common.add_project_domain_option_to_parser(parser) @@ -112,7 +112,7 @@ class AddRole(command.Command): parser.add_argument( 'role', metavar='<role>', - help='Role to add to <user> (name or ID)', + help=_('Role to add to <user> (name or ID)'), ) _add_identity_and_resource_options_to_parser(parser) return parser @@ -131,9 +131,9 @@ class AddRole(command.Command): kwargs = _process_identity_and_resource_options( parsed_args, self.app.client_manager.identity) if not kwargs: - sys.stderr.write("Role not added, incorrect set of arguments " - "provided. See openstack --help for more " - "details\n") + sys.stderr.write(_("Role not added, incorrect set of arguments " + "provided. See openstack --help for more " + "details\n")) return identity_client.roles.grant(role.id, **kwargs) @@ -147,7 +147,7 @@ class CreateRole(command.ShowOne): parser.add_argument( 'name', metavar='<role-name>', - help='New role name', + help=_('New role name'), ) parser.add_argument( '--or-show', @@ -165,7 +165,7 @@ class CreateRole(command.ShowOne): if parsed_args.or_show: role = utils.find_resource(identity_client.roles, parsed_args.name) - self.log.info('Returning existing role %s', role.name) + self.log.info(_('Returning existing role %s'), role.name) else: raise e @@ -182,7 +182,7 @@ class DeleteRole(command.Command): 'roles', metavar='<role>', nargs="+", - help='Role(s) to delete (name or ID)', + help=_('Role(s) to delete (name or ID)'), ) return parser @@ -285,9 +285,9 @@ class ListRole(command.Lister): group_role.group = group.name group_role.project = project.name else: - sys.stderr.write("Error: If a user or group is specified, either " - "--domain or --project must also be specified to " - "list role grants.\n") + sys.stderr.write(_("Error: If a user or group is specified, " + "either --domain or --project must also be " + "specified to list role grants.\n")) return ([], []) return (columns, @@ -305,7 +305,7 @@ class RemoveRole(command.Command): parser.add_argument( 'role', metavar='<role>', - help='Role to remove (name or ID)', + help=_('Role to remove (name or ID)'), ) _add_identity_and_resource_options_to_parser(parser) return parser @@ -315,9 +315,8 @@ class RemoveRole(command.Command): if (not parsed_args.user and not parsed_args.domain and not parsed_args.group and not parsed_args.project): - sys.stderr.write("Incorrect set of arguments " - "provided. See openstack --help for more " - "details\n") + sys.stderr.write(_("Incorrect set of arguments provided. " + "See openstack --help for more details\n")) return role = utils.find_resource( identity_client.roles, @@ -327,8 +326,9 @@ class RemoveRole(command.Command): kwargs = _process_identity_and_resource_options( parsed_args, self.app.client_manager.identity) if not kwargs: - sys.stderr.write("Role not removed, incorrect set of arguments \ - provided. See openstack --help for more details\n") + sys.stderr.write(_("Role not removed, incorrect set of arguments " + "provided. See openstack --help for more " + "details\n")) return identity_client.roles.revoke(role.id, **kwargs) @@ -341,12 +341,12 @@ class SetRole(command.Command): parser.add_argument( 'role', metavar='<role>', - help='Role to modify (name or ID)', + help=_('Role to modify (name or ID)'), ) parser.add_argument( '--name', metavar='<name>', - help='Set role name', + help=_('Set role name'), ) return parser @@ -354,9 +354,8 @@ class SetRole(command.Command): identity_client = self.app.client_manager.identity if not parsed_args.name: - sys.stderr.write("Incorrect set of arguments " - "provided. See openstack --help for more " - "details\n") + sys.stderr.write(_("Incorrect set of arguments provided. " + "See openstack --help for more details\n")) return role = utils.find_resource( identity_client.roles, @@ -374,7 +373,7 @@ class ShowRole(command.ShowOne): parser.add_argument( 'role', metavar='<role>', - help='Role to display (name or ID)', + help=_('Role to display (name or ID)'), ) return parser diff --git a/openstackclient/identity/v3/role_assignment.py b/openstackclient/identity/v3/role_assignment.py index a1418a82..521075fe 100644 --- a/openstackclient/identity/v3/role_assignment.py +++ b/openstackclient/identity/v3/role_assignment.py @@ -15,6 +15,7 @@ from openstackclient.common import command from openstackclient.common import utils +from openstackclient.i18n import _ from openstackclient.identity import common @@ -27,41 +28,41 @@ class ListRoleAssignment(command.Lister): '--effective', action="store_true", default=False, - help='Returns only effective role assignments', + help=_('Returns only effective role assignments'), ) parser.add_argument( '--role', metavar='<role>', - help='Role to filter (name or ID)', + help=_('Role to filter (name or ID)'), ) parser.add_argument( '--names', action="store_true", - help='Display names instead of IDs', + help=_('Display names instead of IDs'), ) user_or_group = parser.add_mutually_exclusive_group() user_or_group.add_argument( '--user', metavar='<user>', - help='User to filter (name or ID)', + help=_('User to filter (name or ID)'), ) common.add_user_domain_option_to_parser(parser) user_or_group.add_argument( '--group', metavar='<group>', - help='Group to filter (name or ID)', + help=_('Group to filter (name or ID)'), ) common.add_group_domain_option_to_parser(parser) domain_or_project = parser.add_mutually_exclusive_group() domain_or_project.add_argument( '--domain', metavar='<domain>', - help='Domain to filter (name or ID)', + help=_('Domain to filter (name or ID)'), ) domain_or_project.add_argument( '--project', metavar='<project>', - help='Project to filter (name or ID)', + help=_('Project to filter (name or ID)'), ) common.add_project_domain_option_to_parser(parser) common.add_inherited_option_to_parser(parser) diff --git a/openstackclient/identity/v3/service.py b/openstackclient/identity/v3/service.py index f43ada56..35507a63 100644 --- a/openstackclient/identity/v3/service.py +++ b/openstackclient/identity/v3/service.py @@ -20,6 +20,7 @@ import sys from openstackclient.common import command from openstackclient.common import utils +from openstackclient.i18n import _ from openstackclient.identity import common @@ -31,28 +32,28 @@ class CreateService(command.ShowOne): parser.add_argument( 'type', metavar='<type>', - help='New service type (compute, image, identity, volume, etc)', + help=_('New service type (compute, image, identity, volume, etc)'), ) parser.add_argument( '--name', metavar='<name>', - help='New service name', + help=_('New service name'), ) parser.add_argument( '--description', metavar='<description>', - help='New service description', + help=_('New service description'), ) enable_group = parser.add_mutually_exclusive_group() enable_group.add_argument( '--enable', action='store_true', - help='Enable service (default)', + help=_('Enable service (default)'), ) enable_group.add_argument( '--disable', action='store_true', - help='Disable service', + help=_('Disable service'), ) return parser @@ -82,7 +83,7 @@ class DeleteService(command.Command): parser.add_argument( 'service', metavar='<service>', - help='Service to delete (type, name or ID)', + help=_('Service to delete (type, name or ID)'), ) return parser @@ -103,7 +104,7 @@ class ListService(command.Lister): '--long', action='store_true', default=False, - help='List additional fields in output', + help=_('List additional fields in output'), ) return parser @@ -128,33 +129,33 @@ class SetService(command.Command): parser.add_argument( 'service', metavar='<service>', - help='Service to update (type, name or ID)', + help=_('Service to update (type, name or ID)'), ) parser.add_argument( '--type', metavar='<type>', - help='New service type (compute, image, identity, volume, etc)', + help=_('New service type (compute, image, identity, volume, etc)'), ) parser.add_argument( '--name', metavar='<service-name>', - help='New service name', + help=_('New service name'), ) parser.add_argument( '--description', metavar='<description>', - help='New service description', + help=_('New service description'), ) enable_group = parser.add_mutually_exclusive_group() enable_group.add_argument( '--enable', action='store_true', - help='Enable service', + help=_('Enable service'), ) enable_group.add_argument( '--disable', action='store_true', - help='Disable service', + help=_('Disable service'), ) return parser @@ -166,9 +167,8 @@ class SetService(command.Command): and not parsed_args.description and not parsed_args.enable and not parsed_args.disable): - sys.stderr.write("Incorrect set of arguments " - "provided. See openstack --help for more " - "details\n") + sys.stderr.write(_("Incorrect set of arguments provided. " + "See openstack --help for more details\n")) return service = common.find_service(identity_client, parsed_args.service) @@ -198,7 +198,7 @@ class ShowService(command.ShowOne): parser.add_argument( 'service', metavar='<service>', - help='Service to display (type, name or ID)', + help=_('Service to display (type, name or ID)'), ) return parser diff --git a/openstackclient/identity/v3/service_provider.py b/openstackclient/identity/v3/service_provider.py index d4fe287e..f1e9f35d 100644 --- a/openstackclient/identity/v3/service_provider.py +++ b/openstackclient/identity/v3/service_provider.py @@ -18,6 +18,7 @@ import sys from openstackclient.common import command from openstackclient.common import utils +from openstackclient.i18n import _ class CreateServiceProvider(command.ShowOne): @@ -28,26 +29,26 @@ class CreateServiceProvider(command.ShowOne): parser.add_argument( 'service_provider_id', metavar='<name>', - help='New service provider name (must be unique)' + help=_('New service provider name (must be unique)'), ) parser.add_argument( '--auth-url', metavar='<auth-url>', required=True, - help='Authentication URL of remote federated service provider ' - '(required)', + help=_('Authentication URL of remote federated service provider ' + '(required)'), ) parser.add_argument( '--description', metavar='<description>', - help='New service provider description', + help=_('New service provider description'), ) parser.add_argument( '--service-provider-url', metavar='<sp-url>', required=True, - help='A service URL where SAML assertions are being sent ' - '(required)', + help=_('A service URL where SAML assertions are being sent ' + '(required)'), ) enable_service_provider = parser.add_mutually_exclusive_group() @@ -56,13 +57,13 @@ class CreateServiceProvider(command.ShowOne): dest='enabled', action='store_true', default=True, - help='Enable the service provider (default)', + help=_('Enable the service provider (default)'), ) enable_service_provider.add_argument( '--disable', dest='enabled', action='store_false', - help='Disable the service provider', + help=_('Disable the service provider'), ) return parser @@ -88,7 +89,7 @@ class DeleteServiceProvider(command.Command): parser.add_argument( 'service_provider', metavar='<service-provider>', - help='Service provider to delete', + help=_('Service provider to delete'), ) return parser @@ -121,34 +122,35 @@ class SetServiceProvider(command.Command): parser.add_argument( 'service_provider', metavar='<service-provider>', - help='Service provider to modify', + help=_('Service provider to modify'), ) parser.add_argument( '--auth-url', metavar='<auth-url>', - help='New Authentication URL of remote federated service provider', + help=_('New Authentication URL of remote ' + 'federated service provider'), ) parser.add_argument( '--description', metavar='<description>', - help='New service provider description', + help=_('New service provider description'), ) parser.add_argument( '--service-provider-url', metavar='<sp-url>', - help='New service provider URL, where SAML assertions are sent', + help=_('New service provider URL, where SAML assertions are sent'), ) enable_service_provider = parser.add_mutually_exclusive_group() enable_service_provider.add_argument( '--enable', action='store_true', - help='Enable the service provider', + help=_('Enable the service provider'), ) enable_service_provider.add_argument( '--disable', action='store_true', - help='Disable the service provider', + help=_('Disable the service provider'), ) return parser @@ -164,8 +166,8 @@ class SetServiceProvider(command.Command): if not any((enabled is not None, parsed_args.description, parsed_args.service_provider_url, parsed_args.auth_url)): - sys.stdout.write("Service Provider not updated, no arguments " - "present\n") + sys.stdout.write(_("Service Provider not updated, no arguments " + "present\n")) return (None, None) service_provider = federation_client.service_providers.update( @@ -184,7 +186,7 @@ class ShowServiceProvider(command.ShowOne): parser.add_argument( 'service_provider', metavar='<service-provider>', - help='Service provider to display', + help=_('Service provider to display'), ) return parser diff --git a/openstackclient/identity/v3/token.py b/openstackclient/identity/v3/token.py index bdc5e95f..56a7497c 100644 --- a/openstackclient/identity/v3/token.py +++ b/openstackclient/identity/v3/token.py @@ -20,6 +20,7 @@ import six from openstackclient.common import command from openstackclient.common import exceptions from openstackclient.common import utils +from openstackclient.i18n import _ from openstackclient.identity import common @@ -31,17 +32,17 @@ class AuthorizeRequestToken(command.ShowOne): parser.add_argument( '--request-key', metavar='<request-key>', - help='Request token to authorize (ID only) (required)', - required=True + required=True, + help=_('Request token to authorize (ID only) (required)'), ) parser.add_argument( '--role', metavar='<role>', action='append', default=[], - help='Roles to authorize (name or ID) ' - '(repeat option to set multiple values, required)', - required=True + required=True, + help=_('Roles to authorize (name or ID) ' + '(repeat option to set multiple values, required)'), ) return parser @@ -72,31 +73,31 @@ class CreateAccessToken(command.ShowOne): parser.add_argument( '--consumer-key', metavar='<consumer-key>', - help='Consumer key (required)', + help=_('Consumer key (required)'), required=True ) parser.add_argument( '--consumer-secret', metavar='<consumer-secret>', - help='Consumer secret (required)', + help=_('Consumer secret (required)'), required=True ) parser.add_argument( '--request-key', metavar='<request-key>', - help='Request token to exchange for access token (required)', + help=_('Request token to exchange for access token (required)'), required=True ) parser.add_argument( '--request-secret', metavar='<request-secret>', - help='Secret associated with <request-key> (required)', + help=_('Secret associated with <request-key> (required)'), required=True ) parser.add_argument( '--verifier', metavar='<verifier>', - help='Verifier associated with <request-key> (required)', + help=_('Verifier associated with <request-key> (required)'), required=True ) return parser @@ -118,26 +119,26 @@ class CreateRequestToken(command.ShowOne): parser.add_argument( '--consumer-key', metavar='<consumer-key>', - help='Consumer key (required)', + help=_('Consumer key (required)'), required=True ) parser.add_argument( '--consumer-secret', metavar='<consumer-secret>', - help='Consumer secret (required)', + help=_('Consumer secret (required)'), required=True ) parser.add_argument( '--project', metavar='<project>', - help='Project that consumer wants to access (name or ID)' - ' (required)', + help=_('Project that consumer wants to access (name or ID)' + ' (required)'), required=True ) parser.add_argument( '--domain', metavar='<domain>', - help='Domain owning <project> (name or ID)', + help=_('Domain owning <project> (name or ID)'), ) return parser @@ -175,7 +176,7 @@ class IssueToken(command.ShowOne): def take_action(self, parsed_args): if not self.app.client_manager.auth_ref: raise exceptions.AuthorizationFailure( - "Only an authorized user may issue a new token.") + _("Only an authorized user may issue a new token.")) token = self.app.client_manager.auth_ref.service_catalog.get_token() if 'tenant_id' in token: token['project_id'] = token.pop('tenant_id') @@ -190,7 +191,7 @@ class RevokeToken(command.Command): parser.add_argument( 'token', metavar='<token>', - help='Token to be deleted', + help=_('Token to be deleted'), ) return parser diff --git a/openstackclient/identity/v3/trust.py b/openstackclient/identity/v3/trust.py index b6f5c6b4..336b703c 100644 --- a/openstackclient/identity/v3/trust.py +++ b/openstackclient/identity/v3/trust.py @@ -18,6 +18,7 @@ import six from openstackclient.common import command from openstackclient.common import utils +from openstackclient.i18n import _ from openstackclient.identity import common @@ -29,26 +30,26 @@ class CreateTrust(command.ShowOne): parser.add_argument( 'trustor', metavar='<trustor-user>', - help='User that is delegating authorization (name or ID)', + help=_('User that is delegating authorization (name or ID)'), ) parser.add_argument( 'trustee', metavar='<trustee-user>', - help='User that is assuming authorization (name or ID)', + help=_('User that is assuming authorization (name or ID)'), ) parser.add_argument( '--project', metavar='<project>', required=True, - help='Project being delegated (name or ID) (required)', + help=_('Project being delegated (name or ID) (required)'), ) parser.add_argument( '--role', metavar='<role>', action='append', default=[], - help='Roles to authorize (name or ID) ' - '(repeat option to set multiple values, required)', + help=_('Roles to authorize (name or ID) ' + '(repeat option to set multiple values, required)'), required=True ) parser.add_argument( @@ -56,25 +57,25 @@ class CreateTrust(command.ShowOne): dest='impersonate', action='store_true', default=False, - help='Tokens generated from the trust will represent <trustor>' - ' (defaults to False)', + help=_('Tokens generated from the trust will represent <trustor>' + ' (defaults to False)'), ) parser.add_argument( '--expiration', metavar='<expiration>', - help='Sets an expiration date for the trust' - ' (format of YYYY-mm-ddTHH:MM:SS)', + help=_('Sets an expiration date for the trust' + ' (format of YYYY-mm-ddTHH:MM:SS)'), ) common.add_project_domain_option_to_parser(parser) parser.add_argument( '--trustor-domain', metavar='<trustor-domain>', - help='Domain that contains <trustor> (name or ID)', + help=_('Domain that contains <trustor> (name or ID)'), ) parser.add_argument( '--trustee-domain', metavar='<trustee-domain>', - help='Domain that contains <trustee> (name or ID)', + help=_('Domain that contains <trustee> (name or ID)'), ) return parser @@ -136,8 +137,8 @@ class DeleteTrust(command.Command): parser.add_argument( 'trust', metavar='<trust>', - help='Trust(s) to delete', nargs="+", + help=_('Trust(s) to delete'), ) return parser @@ -170,7 +171,7 @@ class ShowTrust(command.ShowOne): parser.add_argument( 'trust', metavar='<trust>', - help='Trust to display', + help=_('Trust to display'), ) return parser diff --git a/openstackclient/identity/v3/unscoped_saml.py b/openstackclient/identity/v3/unscoped_saml.py index 8e2616a6..5cb8e486 100644 --- a/openstackclient/identity/v3/unscoped_saml.py +++ b/openstackclient/identity/v3/unscoped_saml.py @@ -20,6 +20,7 @@ a scoped token.""" from openstackclient.common import command from openstackclient.common import exceptions from openstackclient.common import utils +from openstackclient.i18n import _ UNSCOPED_AUTH_PLUGINS = ['v3unscopedsaml', 'v3unscopedadfs', 'v3oidc'] @@ -33,10 +34,10 @@ def auth_with_unscoped_saml(func): if auth_plugin_name in UNSCOPED_AUTH_PLUGINS: return func(self, parsed_args) else: - msg = ('This command requires the use of an unscoped SAML ' - 'authentication plugin. Please use argument ' - '--os-auth-type with one of the following ' - 'plugins: ' + ', '.join(UNSCOPED_AUTH_PLUGINS)) + msg = (_('This command requires the use of an unscoped SAML ' + 'authentication plugin. Please use argument ' + '--os-auth-type with one of the following ' + 'plugins: %s') % ', '.join(UNSCOPED_AUTH_PLUGINS)) raise exceptions.CommandError(msg) return _decorated diff --git a/openstackclient/identity/v3/user.py b/openstackclient/identity/v3/user.py index 8bc4183b..a71b4b78 100644 --- a/openstackclient/identity/v3/user.py +++ b/openstackclient/identity/v3/user.py @@ -35,50 +35,50 @@ class CreateUser(command.ShowOne): parser.add_argument( 'name', metavar='<name>', - help='New user name', + help=_('New user name'), ) parser.add_argument( '--domain', metavar='<domain>', - help='Default domain (name or ID)', + help=_('Default domain (name or ID)'), ) parser.add_argument( '--project', metavar='<project>', - help='Default project (name or ID)', + help=_('Default project (name or ID)'), ) common.add_project_domain_option_to_parser(parser) parser.add_argument( '--password', metavar='<password>', - help='Set user password', + help=_('Set user password'), ) parser.add_argument( '--password-prompt', dest="password_prompt", action="store_true", - help='Prompt interactively for password', + help=_('Prompt interactively for password'), ) parser.add_argument( '--email', metavar='<email-address>', - help='Set user email address', + help=_('Set user email address'), ) parser.add_argument( '--description', metavar='<description>', - help='User description', + help=_('User description'), ) enable_group = parser.add_mutually_exclusive_group() enable_group.add_argument( '--enable', action='store_true', - help='Enable user (default)', + help=_('Enable user (default)'), ) enable_group.add_argument( '--disable', action='store_true', - help='Disable user', + help=_('Disable user'), ) parser.add_argument( '--or-show', @@ -122,7 +122,7 @@ class CreateUser(command.ShowOne): user = utils.find_resource(identity_client.users, parsed_args.name, domain_id=domain_id) - self.log.info('Returning existing user %s', user.name) + self.log.info(_('Returning existing user %s'), user.name) else: raise e @@ -139,12 +139,12 @@ class DeleteUser(command.Command): 'users', metavar='<user>', nargs="+", - help='User(s) to delete (name or ID)', + help=_('User(s) to delete (name or ID)'), ) parser.add_argument( '--domain', metavar='<domain>', - help='Domain owning <user> (name or ID)', + help=_('Domain owning <user> (name or ID)'), ) return parser @@ -173,24 +173,24 @@ class ListUser(command.Lister): parser.add_argument( '--domain', metavar='<domain>', - help='Filter users by <domain> (name or ID)', + help=_('Filter users by <domain> (name or ID)'), ) project_or_group = parser.add_mutually_exclusive_group() project_or_group.add_argument( '--group', metavar='<group>', - help='Filter users by <group> membership (name or ID)', + help=_('Filter users by <group> membership (name or ID)'), ) project_or_group.add_argument( '--project', metavar='<project>', - help='Filter users by <project> (name or ID)', + help=_('Filter users by <project> (name or ID)'), ) parser.add_argument( '--long', action='store_true', default=False, - help='List additional fields in output', + help=_('List additional fields in output'), ) return parser @@ -273,50 +273,50 @@ class SetUser(command.Command): parser.add_argument( 'user', metavar='<user>', - help='User to change (name or ID)', + help=_('User to change (name or ID)'), ) parser.add_argument( '--name', metavar='<name>', - help='Set user name', + help=_('Set user name'), ) parser.add_argument( '--project', metavar='<project>', - help='Set default project (name or ID)', + help=_('Set default project (name or ID)'), ) common.add_project_domain_option_to_parser(parser) parser.add_argument( '--password', metavar='<password>', - help='Set user password', + help=_('Set user password'), ) parser.add_argument( '--password-prompt', dest="password_prompt", action="store_true", - help='Prompt interactively for password', + help=_('Prompt interactively for password'), ) parser.add_argument( '--email', metavar='<email-address>', - help='Set user email address', + help=_('Set user email address'), ) parser.add_argument( '--description', metavar='<description>', - help='Set user description', + help=_('Set user description'), ) enable_group = parser.add_mutually_exclusive_group() enable_group.add_argument( '--enable', action='store_true', - help='Enable user (default)', + help=_('Enable user (default)'), ) enable_group.add_argument( '--disable', action='store_true', - help='Disable user', + help=_('Disable user'), ) return parser @@ -334,9 +334,8 @@ class SetUser(command.Command): and not parsed_args.description and not parsed_args.enable and not parsed_args.disable): - sys.stderr.write("Incorrect set of arguments " - "provided. See openstack --help for more " - "details\n") + sys.stderr.write(_("Incorrect set of arguments provided. " + "See openstack --help for more details\n")) return user = utils.find_resource( @@ -376,12 +375,12 @@ class SetPasswordUser(command.Command): parser.add_argument( '--password', metavar='<new-password>', - help='New user password' + help=_('New user password'), ) parser.add_argument( '--original-password', metavar='<original-password>', - help='Original user password' + help=_('Original user password'), ) return parser @@ -429,12 +428,12 @@ class ShowUser(command.ShowOne): parser.add_argument( 'user', metavar='<user>', - help='User to display (name or ID)', + help=_('User to display (name or ID)'), ) parser.add_argument( '--domain', metavar='<domain>', - help='Domain owning <user> (name or ID)', + help=_('Domain owning <user> (name or ID)'), ) return parser diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py index ca02281f..7ef3964b 100644 --- a/openstackclient/network/v2/port.py +++ b/openstackclient/network/v2/port.py @@ -284,10 +284,23 @@ class DeletePort(command.Command): def take_action(self, parsed_args): client = self.app.client_manager.network + result = 0 for port in parsed_args.port: - res = client.find_port(port) - client.delete_port(res) + try: + obj = client.find_port(port, ignore_missing=False) + client.delete_port(obj) + except Exception as e: + result += 1 + self.app.log.error(_("Failed to delete port with " + "name or ID '%(port)s': %(e)s") + % {'port': port, 'e': e}) + + if result > 0: + total = len(parsed_args.port) + msg = (_("%(result)s of %(total)s ports failed " + "to delete.") % {'result': result, 'total': total}) + raise exceptions.CommandError(msg) class ListPort(command.Lister): diff --git a/openstackclient/tests/network/v2/test_port.py b/openstackclient/tests/network/v2/test_port.py index c3f175bf..dd98a637 100644 --- a/openstackclient/tests/network/v2/test_port.py +++ b/openstackclient/tests/network/v2/test_port.py @@ -13,6 +13,8 @@ import mock +from mock import call +from openstackclient.common import exceptions from openstackclient.common import utils from openstackclient.network.v2 import port from openstackclient.tests.network.v2 import fakes as network_fakes @@ -174,30 +176,82 @@ class TestCreatePort(TestPort): class TestDeletePort(TestPort): - # The port to delete. - _port = network_fakes.FakePort.create_one_port() + # Ports to delete. + _ports = network_fakes.FakePort.create_ports(count=2) def setUp(self): super(TestDeletePort, self).setUp() self.network.delete_port = mock.Mock(return_value=None) - self.network.find_port = mock.Mock(return_value=self._port) + self.network.find_port = network_fakes.FakePort.get_ports( + ports=self._ports) # Get the command object to test self.cmd = port.DeletePort(self.app, self.namespace) - def test_delete(self): + def test_port_delete(self): arglist = [ - self._port.name, + self._ports[0].name, ] verifylist = [ - ('port', [self._port.name]), + ('port', [self._ports[0].name]), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) - self.network.delete_port.assert_called_once_with(self._port) + self.network.find_port.assert_called_once_with( + self._ports[0].name, ignore_missing=False) + self.network.delete_port.assert_called_once_with(self._ports[0]) self.assertIsNone(result) + def test_multi_ports_delete(self): + arglist = [] + verifylist = [] + + for p in self._ports: + arglist.append(p.name) + verifylist = [ + ('port', arglist), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + result = self.cmd.take_action(parsed_args) + + calls = [] + for p in self._ports: + calls.append(call(p)) + self.network.delete_port.assert_has_calls(calls) + self.assertIsNone(result) + + def test_multi_ports_delete_with_exception(self): + arglist = [ + self._ports[0].name, + 'unexist_port', + ] + verifylist = [ + ('port', + [self._ports[0].name, 'unexist_port']), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + find_mock_result = [self._ports[0], exceptions.CommandError] + self.network.find_port = ( + mock.MagicMock(side_effect=find_mock_result) + ) + + try: + self.cmd.take_action(parsed_args) + self.fail('CommandError should be raised.') + except exceptions.CommandError as e: + self.assertEqual('1 of 2 ports failed to delete.', str(e)) + + self.network.find_port.assert_any_call( + self._ports[0].name, ignore_missing=False) + self.network.find_port.assert_any_call( + 'unexist_port', ignore_missing=False) + self.network.delete_port.assert_called_once_with( + self._ports[0] + ) + class TestListPort(TestPort): diff --git a/openstackclient/tests/volume/v2/test_type.py b/openstackclient/tests/volume/v2/test_type.py index 872b4ae9..10c38612 100644 --- a/openstackclient/tests/volume/v2/test_type.py +++ b/openstackclient/tests/volume/v2/test_type.py @@ -397,17 +397,19 @@ class TestTypeUnset(TestType): def test_type_unset(self): arglist = [ '--property', 'property', + '--property', 'multi_property', self.volume_type.id, ] verifylist = [ - ('property', 'property'), + ('property', ['property', 'multi_property']), ('volume_type', self.volume_type.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) - self.volume_type.unset_keys.assert_called_once_with('property') + self.volume_type.unset_keys.assert_called_once_with( + ['property', 'multi_property']) self.assertIsNone(result) def test_type_unset_project_access(self): diff --git a/openstackclient/volume/v2/volume_type.py b/openstackclient/volume/v2/volume_type.py index e44e39ff..9aed17bc 100644 --- a/openstackclient/volume/v2/volume_type.py +++ b/openstackclient/volume/v2/volume_type.py @@ -256,6 +256,7 @@ class UnsetVolumeType(command.Command): parser.add_argument( '--property', metavar='<key>', + action='append', help=_('Remove a property from this volume type ' '(repeat option to remove multiple properties)'), ) |