[pkg-eucalyptus-commits] [SCM] managing cloud instances for Eucalyptus branch, master, updated. 3.0.0-alpha3-257-g1da8e3a
Garrett Holmstrom
gholms at fedoraproject.org
Sun Jun 16 02:30:22 UTC 2013
The following commit has been merged in the master branch:
commit 2ad54cbd5329b3dac17da177860a7c5f151d2ff3
Author: Garrett Holmstrom <gholms at fedoraproject.org>
Date: Tue Feb 19 20:19:47 2013 -0800
Port DeleteGroup
diff --git a/bin/euare-groupdel b/bin/euare-groupdel
index 374da2e..3ff278c 100755
--- a/bin/euare-groupdel
+++ b/bin/euare-groupdel
@@ -1,7 +1,6 @@
-#!/usr/bin/python
+#!/usr/bin/python -tt
import euca2ools.commands.euare.deletegroup
if __name__ == '__main__':
- r = euca2ools.commands.euare.deletegroup.DeleteGroup()
- r.main_cli()
+ euca2ools.commands.euare.deletegroup.DeleteGroup.run()
diff --git a/euca2ools/commands/euare/deletegroup.py b/euca2ools/commands/euare/deletegroup.py
index 8e8b5c5..1ebf80a 100644
--- a/euca2ools/commands/euare/deletegroup.py
+++ b/euca2ools/commands/euare/deletegroup.py
@@ -1,6 +1,6 @@
# Software License Agreement (BSD License)
#
-# Copyright (c) 2009-2011, Eucalyptus Systems, Inc.
+# Copyright (c) 2009-2013, Eucalyptus Systems, Inc.
# All rights reserved.
#
# Redistribution and use of this software in source and binary forms, with or
@@ -27,94 +27,64 @@
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
-#
-# Author: Neil Soman neil at eucalyptus.com
-# Mitch Garnaat mgarnaat at eucalyptus.com
-from boto.roboto.awsqueryrequest import AWSQueryRequest
-from boto.roboto.param import Param
-import euca2ools.commands.euare
-import euca2ools.utils
-from euca2ools.commands.euare.listgrouppolicies import ListGroupPolicies
+import argparse
from euca2ools.commands.euare.deletegrouppolicy import DeleteGroupPolicy
from euca2ools.commands.euare.getgroup import GetGroup
+from euca2ools.commands.euare.listgrouppolicies import ListGroupPolicies
from euca2ools.commands.euare.removeuserfromgroup import RemoveUserFromGroup
+from requestbuilder import Arg
+from . import EuareRequest, DELEGATE
-class DeleteGroup(AWSQueryRequest):
+class DeleteGroup(EuareRequest):
+ DESCRIPTION = 'Delete a group'
+ ARGS = [Arg('-g', '--group-name', dest='GroupName', metavar='GROUP',
+ required=True, help='name of the group to delete (required)'),
+ Arg('-r', '--recursive', action='store_true', route_to=None,
+ help='''remove all user memberships and policies associated
+ with the group first'''),
+ Arg('-R', '--recursive-euca', dest='IsRecursive',
+ action='store_const', const='true', help=argparse.SUPPRESS),
+ Arg('-p', '--pretend', action='store_true', route_to=None,
+ help='''list the user memberships and policies that would be
+ deleted instead of actually deleting them. Implies
+ -r.'''),
+ DELEGATE]
- ServiceClass = euca2ools.commands.euare.Euare
+ def main(self):
+ if self.args['recursive'] or self.args['pretend']:
+ # Figure out what we'd have to delete
+ req = GetGroup(service=self.service,
+ GroupName=self.args['GroupName'],
+ DelegateAccount=self.args['DelegateAccount'])
+ members = req.main().get('Users', [])
+ req = ListGroupPolicies(service=self.service,
+ GroupName=self.args['GroupName'],
+ DelegateAccount=self.args['DelegateAccount'])
+ policies = req.main().get('PolicyNames', [])
+ if self.args['pretend']:
+ return {'members': [member['Arn'] for member in members],
+ 'policies': policies}
+ else:
+ if self.args['recursive']:
+ member_names = [member['UserName'] for member in members]
+ req = RemoveUserFromGroup(service=self.service,
+ GroupName=self.args['GroupName'],
+ user_names=member_names,
+ DelegateAccount=self.args['DelegateAccount'])
+ req.main()
+ for policy in policies:
+ req = DeleteGroupPolicy(service=self.service,
+ GroupName=self.args['GroupName'], PolicyName=policy,
+ DelegateAccount=self.args['DelegateAccount'])
+ req.main()
+ return self.send()
- Description = """DeleteGroup"""
- Params = [
- Param(name='GroupName',
- short_name='g',
- long_name='group-name',
- ptype='string',
- optional=False,
- doc=""" Name of the group to delete. """),
- Param(name='DelegateAccount',
- short_name=None,
- long_name='delegate',
- ptype='string',
- optional=True,
- doc=""" [Eucalyptus extension] Process this command as if the administrator of the specified account had run it. This option is only usable by cloud administrators. """),
- Param(name='recursive',
- short_name='r',
- long_name='recursive',
- ptype='boolean',
- optional=True,
- request_param=False,
- doc=""" Removes all Users from the Group, deletes all Policies associated with the Group, then deletes the Group."""),
- Param(name='IsRecursive',
- short_name='R',
- long_name='recursive-euca',
- ptype='boolean',
- optional=True,
- doc=""" [Eucalyptus extension] Same as -r, but all operations are performed by the server instead of the client."""),
- Param(name='pretend',
- short_name='p',
- long_name='pretend',
- ptype='boolean',
- optional=True,
- doc=""" Returns a list of Users and Policies that would be deleted if the -r or -R option were actually performed.""")
- ]
-
- def cli_formatter(self, data):
- if data and self.pretend:
+ def print_result(self, result):
+ if self.args['pretend']:
print 'users'
- for user in data['users']:
- print '\t%s' % user['Arn']
+ for arn in result['members']:
+ print '\t' + arn
print 'policies'
- for policy in data['policies']:
- print '\t%s' % policy
-
- def main(self, **args):
- data = {}
- recursive_local = self.cli_options.recursive or \
- args.get('recursive', False)
- recursive_server = self.cli_options.recursive_euca or \
- args.get('recursive_euca', False)
- self.pretend = self.cli_options.pretend or args.get('pretend', False)
- group_name = self.cli_options.group_name or args.get('group_name', None)
- if recursive_local or (recursive_server and self.pretend):
- obj = ListGroupPolicies()
- d = obj.main(group_name=group_name)
- data['policies'] = d.PolicyNames
- obj = GetGroup()
- d = obj.main(group_name=group_name)
- data['users'] = d.Users
- if self.pretend:
- return data
- else:
- obj = RemoveUserFromGroup()
- for user in data['users']:
- obj.main(group_name=group_name, user_name=user['UserName'])
- obj = DeleteGroupPolicy()
- for policy in data['policies']:
- obj.main(group_name=group_name, policy_name=policy)
- if not self.pretend:
- return self.send(**args)
-
- def main_cli(self):
- euca2ools.utils.print_version_if_necessary()
- self.do_cli()
+ for policy in result['policies']:
+ print '\t' + policy
diff --git a/euca2ools/commands/euare/removeuserfromgroup.py b/euca2ools/commands/euare/removeuserfromgroup.py
index 0c01876..4422d79 100644
--- a/euca2ools/commands/euare/removeuserfromgroup.py
+++ b/euca2ools/commands/euare/removeuserfromgroup.py
@@ -34,15 +34,15 @@ from . import EuareRequest, DELEGATE
class RemoveUserFromGroup(EuareRequest):
DESCRIPTION = 'Remove a user from a group'
- ARGS = [Arg('-u', '--user-name', metavar='USER', action='append',
- route_to=None, required=True,
+ ARGS = [Arg('-u', '--user-name', dest='user_names', metavar='USER',
+ action='append', route_to=None, required=True,
help='user to remove from the group (required)'),
Arg('-g', '--group-name', dest='GroupName', metavar='GROUP',
required=True, help='group to remove the user from (required)'),
DELEGATE]
def main(self):
- for user in self.args['user_name']:
+ for user in self.args['user_names']:
self.params['UserName'] = user
response = self.send()
# The response doesn't actually contain anything of interest, so just
--
managing cloud instances for Eucalyptus
More information about the pkg-eucalyptus-commits
mailing list