Add support for domains when deleting identity v3 resources

Currently, only deleting via IDs is possible for groups, projects
and users.
We should have an optional --domain argument that allows for
a name to be specified for the resource. (Since these are all
namespaced by domains).

Change-Id: I18ace3db85a3969f0b97678d432d6f8368baa9cd
This commit is contained in:
Steve Martinelli 2014-11-19 15:31:25 -05:00
parent 04d30c1855
commit 4b239eea42
5 changed files with 55 additions and 9 deletions

View File

@ -58,6 +58,12 @@ Delete an existing project
os project delete
<project>
.. option:: --domain <domain>
Domain owning :ref:`\<project\> <_project_delete-project>` (name or ID)
.. versionadded:: 3
.. _project_delete-project:
.. describe:: <project>

View File

@ -80,6 +80,14 @@ Delete user
os user delete
<user>
.. option:: --domain <domain>
Domain owning :ref:`\<user\> <_user_delete-user>` (name or ID)
.. versionadded:: 3
.. _user_delete-user:
.. describe:: <user>
User to delete (name or ID)

View File

@ -169,12 +169,26 @@ class DeleteGroup(command.Command):
'group',
metavar='<group>',
help='Name or ID of group to delete')
parser.add_argument(
'--domain',
metavar='<domain>',
help='Domain where group resides (name or ID)',
)
return parser
def take_action(self, parsed_args):
self.log.debug('take_action(%s)', parsed_args)
identity_client = self.app.client_manager.identity
group = utils.find_resource(identity_client.groups, parsed_args.group)
if parsed_args.domain:
domain = common.find_domain(identity_client, parsed_args.domain)
group = utils.find_resource(identity_client.groups,
parsed_args.group,
domain_id=domain.id)
else:
group = utils.find_resource(identity_client.groups,
parsed_args.group)
identity_client.groups.delete(group.id)
return

View File

@ -126,16 +126,25 @@ class DeleteProject(command.Command):
metavar='<project>',
help='Project to delete (name or ID)',
)
parser.add_argument(
'--domain',
metavar='<domain>',
help='Domain owning <project> (name or ID)',
)
return parser
def take_action(self, parsed_args):
self.log.debug('take_action(%s)', parsed_args)
identity_client = self.app.client_manager.identity
project = utils.find_resource(
identity_client.projects,
parsed_args.project,
)
if parsed_args.domain:
domain = common.find_domain(identity_client, parsed_args.domain)
project = utils.find_resource(identity_client.projects,
parsed_args.project,
domain_id=domain.id)
else:
project = utils.find_resource(identity_client.projects,
parsed_args.project)
identity_client.projects.delete(project.id)
return

View File

@ -148,16 +148,25 @@ class DeleteUser(command.Command):
metavar='<user>',
help='User to delete (name or ID)',
)
parser.add_argument(
'--domain',
metavar='<domain>',
help='Domain owning <user> (name or ID)',
)
return parser
def take_action(self, parsed_args):
self.log.debug('take_action(%s)', parsed_args)
identity_client = self.app.client_manager.identity
user = utils.find_resource(
identity_client.users,
parsed_args.user,
)
if parsed_args.domain:
domain = common.find_domain(identity_client, parsed_args.domain)
user = utils.find_resource(identity_client.users,
parsed_args.user,
domain_id=domain.id)
else:
user = utils.find_resource(identity_client.users,
parsed_args.user)
identity_client.users.delete(user.id)
return