[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:17 UTC 2013
The following commit has been merged in the master branch:
commit 3620a05f3c064358a91e05e57c99005577be2c02
Author: Garrett Holmstrom <gholms at fedoraproject.org>
Date: Tue Feb 19 14:04:24 2013 -0800
Port euare-groupaddpolicy
diff --git a/bin/euare-groupaddpolicy b/bin/euare-groupaddpolicy
index eb45c45..2a7ccf0 100755
--- a/bin/euare-groupaddpolicy
+++ b/bin/euare-groupaddpolicy
@@ -1,7 +1,6 @@
-#!/usr/bin/python
+#!/usr/bin/python -tt
import euca2ools.commands.euare.addgrouppolicy
if __name__ == '__main__':
- r = euca2ools.commands.euare.addgrouppolicy.AddGroupPolicy()
- r.main_cli()
+ euca2ools.commands.euare.addgrouppolicy.AddGroupPolicy.run()
diff --git a/euca2ools/commands/euare/addgrouppolicy.py b/euca2ools/commands/euare/addgrouppolicy.py
index b9274af..9a3333b 100644
--- a/euca2ools/commands/euare/addgrouppolicy.py
+++ b/euca2ools/commands/euare/addgrouppolicy.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,101 +27,50 @@
# 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 datetime
import euca2ools.commands.euare.putgrouppolicy
-import euca2ools.utils
-
-
-class AddGroupPolicy(AWSQueryRequest):
+import json
+from requestbuilder import Arg
+from . import EuareRequest, DELEGATE
- ServiceClass = euca2ools.commands.euare.Euare
- Description = 'Add a new policy to a group'
- Params = [
- Param(name='GroupName',
- short_name='g',
- long_name='group-name',
- ptype='string',
- optional=False,
- request_param=False,
- doc=""" Name of the group to associate the policy with. """),
- Param(name='PolicyName',
- short_name='p',
- long_name='policy-name',
- ptype='string',
- optional=False,
- request_param=False,
- doc=""" Name of the policy document. """),
- Param(name='Effect',
- short_name='e',
- long_name='effect',
- ptype='enum',
- choices=['Allow', 'Deny'],
- optional=False,
- request_param=False,
- doc="The value for the policy's Effect element."),
- Param(name='Action',
- short_name='a',
- long_name='action',
- ptype='string',
- optional=True,
- request_param=False,
- doc="The value for the policy's Action element"),
- Param(name='Resource',
- short_name='r',
- long_name='resource',
- ptype='string',
- optional=True,
- request_param=False,
- doc="The value for the policy's Resource element."),
- Param(name='output',
- short_name='o',
- long_name='output',
- ptype='boolean',
- optional=True,
- doc='Causes the output to include the JSON policy document created for you'),
- 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.""")]
+class AddGroupPolicy(EuareRequest):
+ DESCRIPTION = ('Add a new policy to a group. To add more complex policies '
+ 'than this tool supports, see euare-groupuploadpolicy.')
+ ARGS = [Arg('-g', '--group-name', metavar='GROUP', required=True,
+ help='group to attach the policy to (required)'),
+ Arg('-p', '--policy-name', metavar='POLICY', required=True,
+ help='name of the new policy (required)'),
+ Arg('-e', '--effect', choices=('Allow', 'Deny'), required=True,
+ help='whether the new policy should Allow or Deny (required)'),
+ Arg('-a', '--action', required=True,
+ help='action the policy should apply to (required)'),
+ Arg('-r', '--resource', required=True,
+ help='resource the policy should apply to (required)'),
+ Arg('-o', '--output', action='store_true',
+ help='display the newly-created policy'),
+ DELEGATE]
def build_policy(self):
- s = '{"Effect":"%s", "Action":["%s"], "Resource":["%s"]}' % (self.effect,
- self.action,
- self.resource)
- p = '{"Version":"2008-10-17","Statement":[%s]}' % s
- return p
+ stmt = {'Sid': datetime.datetime.utcnow().strftime('%Y%m%d%H%M%S%f'),
+ 'Effect': self.args['effect'],
+ 'Action': self.args['action'],
+ 'Resource': self.args['resource']}
+ return {'Statement': [stmt]}
- def cli_formatter(self, data):
- if self.cli_options.output:
- print self.policy
- def main(self, **args):
- self.process_args()
- self.group_name = self.cli_options.group_name
- self.policy_name = self.cli_options.policy_name
- self.effect = self.cli_options.effect
- if self.cli_options.action:
- self.action = self.cli_options.action
- else:
- self.action = '*'
- if self.cli_options.resource:
- self.resource = self.cli_options.resource
- else:
- self.resource = '*'
- self.policy = self.build_policy()
- obj = euca2ools.commands.euare.putgrouppolicy.PutGroupPolicy()
- return obj.main(group_name=self.group_name, policy_name=self.policy_name,
- policy_document=self.policy)
+ def main(self):
+ policy_doc = json.dumps(self.build_policy())
+ req = euca2ools.commands.euare.putgrouppolicy.PutGroupPolicy(
+ service=self.service, GroupName=self.args['group_name'],
+ PolicyName=self.args['policy_name'],
+ PolicyDocument=policy_doc,
+ DelegateAccount=self.args['DelegateAccount'])
+ response = req.main()
+ response['PolicyDocument'] = policy_doc
+ return response
- def main_cli(self):
- euca2ools.utils.print_version_if_necessary()
- self.do_cli()
+ def print_result(self, result):
+ if self.args['output']:
+ print result['PolicyDocument']
--
managing cloud instances for Eucalyptus
More information about the pkg-eucalyptus-commits
mailing list