diff options
Diffstat (limited to 'openstackclient/identity')
| -rw-r--r-- | openstackclient/identity/v2_0/role.py | 148 | ||||
| -rw-r--r-- | openstackclient/identity/v2_0/service.py | 30 | ||||
| -rw-r--r-- | openstackclient/identity/v3/role.py | 125 |
3 files changed, 17 insertions, 286 deletions
diff --git a/openstackclient/identity/v2_0/role.py b/openstackclient/identity/v2_0/role.py index e254e05f..e9fe50fa 100644 --- a/openstackclient/identity/v2_0/role.py +++ b/openstackclient/identity/v2_0/role.py @@ -148,155 +148,11 @@ class DeleteRole(command.Command): class ListRole(command.Lister): _description = _("List roles") - def get_parser(self, prog_name): - parser = super(ListRole, self).get_parser(prog_name) - parser.add_argument( - '--project', - metavar='<project>', - help=_('Filter roles by <project> (name or ID)'), - ) - parser.add_argument( - '--user', - metavar='<user>', - help=_('Filter roles by <user> (name or ID)'), - ) - return parser - def take_action(self, parsed_args): - - def _deprecated(): - # NOTE(henry-nash): Deprecated as of Newton, so we should remove - # this in the 'P' release. - self.log.warning(_('Listing assignments using role list is ' - 'deprecated as of the Newton release. Use role ' - 'assignment list --user <user-name> --project ' - '<project-name> --names instead.')) - identity_client = self.app.client_manager.identity - auth_ref = self.app.client_manager.auth_ref - - # No user or project specified, list all roles in the system - if not parsed_args.user and not parsed_args.project: - columns = ('ID', 'Name') - data = identity_client.roles.list() - elif parsed_args.user and parsed_args.project: - user = utils.find_resource( - identity_client.users, - parsed_args.user, - ) - project = utils.find_resource( - identity_client.projects, - parsed_args.project, - ) - _deprecated() - data = identity_client.roles.roles_for_user(user.id, project.id) - - elif parsed_args.user: - user = utils.find_resource( - identity_client.users, - parsed_args.user, - ) - if self.app.client_manager.auth_ref: - project = utils.find_resource( - identity_client.projects, - auth_ref.project_id - ) - else: - msg = _("Project must be specified") - raise exceptions.CommandError(msg) - _deprecated() - data = identity_client.roles.roles_for_user(user.id, project.id) - elif parsed_args.project: - project = utils.find_resource( - identity_client.projects, - parsed_args.project, - ) - if self.app.client_manager.auth_ref: - user = utils.find_resource( - identity_client.users, - auth_ref.user_id - ) - else: - msg = _("User must be specified") - raise exceptions.CommandError(msg) - _deprecated() - data = identity_client.roles.roles_for_user(user.id, project.id) - - if parsed_args.user or parsed_args.project: - columns = ('ID', 'Name', 'Project', 'User') - for user_role in data: - user_role.user = user.name - user_role.project = project.name - - return (columns, - (utils.get_item_properties( - s, columns, - formatters={}, - ) for s in data)) - - -class ListUserRole(command.Lister): - _description = _("List user-role assignments") - - def get_parser(self, prog_name): - parser = super(ListUserRole, self).get_parser(prog_name) - parser.add_argument( - 'user', - metavar='<user>', - nargs='?', - help=_('User to list (name or ID)'), - ) - parser.add_argument( - '--project', - metavar='<project>', - help=_('Filter users by <project> (name or ID)'), - ) - return parser - - def take_action(self, parsed_args): - identity_client = self.app.client_manager.identity - auth_ref = self.app.client_manager.auth_ref - - # Project and user are required, if not included in command args - # default to the values used for authentication. For token-flow - # authentication they must be included on the command line. - if (not parsed_args.project and - self.app.client_manager.auth_ref.project_id): - parsed_args.project = auth_ref.project_id - if not parsed_args.project: - msg = _("Project must be specified") - raise exceptions.CommandError(msg) - - if (not parsed_args.user and - self.app.client_manager.auth_ref.user_id): - parsed_args.user = auth_ref.user_id - if not parsed_args.user: - msg = _("User must be specified") - raise exceptions.CommandError(msg) - - self.log.warning(_('Listing assignments using user role list is ' - 'deprecated as of the Newton release. Use role ' - 'assignment list --user <user-name> --project ' - '<project-name> --names instead.')) - project = utils.find_resource( - identity_client.tenants, - parsed_args.project, - ) - user = utils.find_resource(identity_client.users, parsed_args.user) - - data = identity_client.roles.roles_for_user(user.id, project.id) - - columns = ( - 'ID', - 'Name', - 'Project', - 'User', - ) - # Add the names to the output even though they will be constant - for role in data: - role.user = user.name - role.project = project.name + columns = ('ID', 'Name') + data = identity_client.roles.list() return (columns, (utils.get_item_properties( diff --git a/openstackclient/identity/v2_0/service.py b/openstackclient/identity/v2_0/service.py index 80f2d72a..653de8eb 100644 --- a/openstackclient/identity/v2_0/service.py +++ b/openstackclient/identity/v2_0/service.py @@ -15,7 +15,6 @@ """Service action implementations""" -import argparse import logging from osc_lib.command import command @@ -36,17 +35,11 @@ class CreateService(command.ShowOne): def get_parser(self, prog_name): parser = super(CreateService, self).get_parser(prog_name) parser.add_argument( - 'type_or_name', + 'type', metavar='<type>', help=_('New service type (compute, image, identity, volume, etc)'), ) - type_or_name_group = parser.add_mutually_exclusive_group() - type_or_name_group.add_argument( - '--type', - metavar='<type>', - help=argparse.SUPPRESS, - ) - type_or_name_group.add_argument( + parser.add_argument( '--name', metavar='<name>', help=_('New service name'), @@ -61,29 +54,14 @@ class CreateService(command.ShowOne): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - type_or_name = parsed_args.type_or_name name = parsed_args.name type = parsed_args.type - # If only a single positional is present, it's a <type>. - # This is not currently legal so it is considered a new case. - if not type and not name: - type = type_or_name - # If --type option is present then positional is handled as <name>; - # display deprecation message. - elif type: - name = type_or_name - LOG.warning(_('The argument --type is deprecated, use service' - ' create --name <service-name> type instead.')) - # If --name option is present the positional is handled as <type>. - # Making --type optional is new, but back-compatible - elif name: - type = type_or_name - service = identity_client.services.create( name, type, - parsed_args.description) + parsed_args.description, + ) info = {} info.update(service._info) diff --git a/openstackclient/identity/v3/role.py b/openstackclient/identity/v3/role.py index 58a76f8a..0eeddd37 100644 --- a/openstackclient/identity/v3/role.py +++ b/openstackclient/identity/v3/role.py @@ -266,131 +266,28 @@ class ListRole(command.Lister): def get_parser(self, prog_name): parser = super(ListRole, self).get_parser(prog_name) - - # TODO(henry-nash): The use of the List Role command to list - # assignments (as well as roles) has been deprecated. In order - # to support domain specific roles, we are overriding the domain - # option to allow specification of the domain for the role. This does - # not conflict with any existing commands, since for the deprecated - # assignments listing you were never allowed to only specify a domain - # (you also needed to specify a user). - # - # Once we have removed the deprecated options entirely, we must - # replace the call to _add_identity_and_resource_options_to_parser() - # below with just adding the domain option into the parser. - _add_identity_and_resource_options_to_parser(parser) + parser.add_argument( + '--domain', + metavar='<domain>', + help=_('Include <domain> (name or ID)'), + ) return parser def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - if parsed_args.user: - user = common.find_user( - identity_client, - parsed_args.user, - parsed_args.user_domain, - ) - elif parsed_args.group: - group = common.find_group( - identity_client, - parsed_args.group, - parsed_args.group_domain, - ) - if parsed_args.domain: domain = common.find_domain( identity_client, parsed_args.domain, ) - elif parsed_args.project: - project = common.find_project( - identity_client, - parsed_args.project, - parsed_args.project_domain, - ) - - # no user or group specified, list all roles in the system - if not parsed_args.user and not parsed_args.group: - if not parsed_args.domain: - columns = ('ID', 'Name') - data = identity_client.roles.list() - else: - columns = ('ID', 'Name', 'Domain') - data = identity_client.roles.list(domain_id=domain.id) - for role in data: - role.domain = domain.name - elif parsed_args.user and parsed_args.domain: - columns = ('ID', 'Name', 'Domain', 'User') - data = identity_client.roles.list( - user=user, - domain=domain, - os_inherit_extension_inherited=parsed_args.inherited - ) - for user_role in data: - user_role.user = user.name - user_role.domain = domain.name - self.log.warning(_('Listing assignments using role list is ' - 'deprecated. Use role assignment list --user ' - '<user-name> --domain <domain-name> --names ' - 'instead.')) - elif parsed_args.user and parsed_args.project: - columns = ('ID', 'Name', 'Project', 'User') - data = identity_client.roles.list( - user=user, - project=project, - os_inherit_extension_inherited=parsed_args.inherited - ) - for user_role in data: - user_role.user = user.name - user_role.project = project.name - self.log.warning(_('Listing assignments using role list is ' - 'deprecated. Use role assignment list --user ' - '<user-name> --project <project-name> --names ' - 'instead.')) - elif parsed_args.user: - columns = ('ID', 'Name') - data = identity_client.roles.list( - user=user, - domain='default', - os_inherit_extension_inherited=parsed_args.inherited - ) - self.log.warning(_('Listing assignments using role list is ' - 'deprecated. Use role assignment list --user ' - '<user-name> --domain default --names ' - 'instead.')) - elif parsed_args.group and parsed_args.domain: - columns = ('ID', 'Name', 'Domain', 'Group') - data = identity_client.roles.list( - group=group, - domain=domain, - os_inherit_extension_inherited=parsed_args.inherited - ) - for group_role in data: - group_role.group = group.name - group_role.domain = domain.name - self.log.warning(_('Listing assignments using role list is ' - 'deprecated. Use role assignment list --group ' - '<group-name> --domain <domain-name> --names ' - 'instead.')) - elif parsed_args.group and parsed_args.project: - columns = ('ID', 'Name', 'Project', 'Group') - data = identity_client.roles.list( - group=group, - project=project, - os_inherit_extension_inherited=parsed_args.inherited - ) - for group_role in data: - group_role.group = group.name - group_role.project = project.name - self.log.warning(_('Listing assignments using role list is ' - 'deprecated. Use role assignment list --group ' - '<group-name> --project <project-name> --names ' - 'instead.')) + columns = ('ID', 'Name', 'Domain') + data = identity_client.roles.list(domain_id=domain.id) + for role in data: + role.domain = domain.name else: - msg = _("Error: If a user or group is specified, " - "either --domain or --project must also be " - "specified to list role grants.") - raise exceptions.CommandError(msg) + columns = ('ID', 'Name') + data = identity_client.roles.list() return (columns, (utils.get_item_properties( |
