[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:29:40 UTC 2013


The following commit has been merged in the master branch:
commit bd5e11b0716c231c865cfcd4a940eddf8c1a1a64
Author: Garrett Holmstrom <gholms at fedoraproject.org>
Date:   Sat Apr 14 13:52:20 2012 -0700

    Rewrite CreateUser

diff --git a/bin/euare-usercreate b/bin/euare-usercreate
index 045b648..3a66ac7 100755
--- a/bin/euare-usercreate
+++ b/bin/euare-usercreate
@@ -1,7 +1,6 @@
-#!/usr/bin/python
+#!/usr/bin/python -tt
 
 import euca2ools.commands.euare.createuser
 
 if __name__ == '__main__':
-    r = euca2ools.commands.euare.createuser.CreateUser()
-    r.main_cli()
+    euca2ools.commands.euare.createuser.CreateUser().do_cli()
diff --git a/euca2ools/commands/euare/createuser.py b/euca2ools/commands/euare/createuser.py
index 48e9403..7120f52 100644
--- a/euca2ools/commands/euare/createuser.py
+++ b/euca2ools/commands/euare/createuser.py
@@ -1,6 +1,6 @@
 # Software License Agreement (BSD License)
 #
-# Copyright (c) 2009-2011, Eucalyptus Systems, Inc.
+# Copyright (c) 2009-2012, Eucalyptus Systems, Inc.
 # All rights reserved.
 #
 # Redistribution and use of this software in source and binary forms, with or
@@ -27,90 +27,45 @@
 # 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.commands.euare.addusertogroup
-import euca2ools.commands.euare.createaccesskey
-import euca2ools.utils
-
-
-class CreateUser(AWSQueryRequest):
-
-    ServiceClass = euca2ools.commands.euare.Euare
 
-    Description = """CreateUser"""
-    Params = [
-        Param(name='Path',
-              short_name='p',
-              long_name='path',
-              ptype='string',
-              optional=True,
-              doc=""" The path for the User name. For more information about paths, see Identifiers for IAM Entities in Using AWS Identity and Access Management.  This parameter is optional. If it is not included, it defaults to a slash (/). """),
-        Param(name='UserName',
-              short_name='u',
-              long_name='user-name',
-              ptype='string',
-              optional=False,
-              doc=""" Name of the User to create. """),
-        Param(name='group_name',
-              short_name='g',
-              long_name='group-name',
-              ptype='string',
-              optional=True,
-              cardinality='*',
-              request_param=False,
-              doc="Name of a group you want to add the User to."),
-        Param(name='create_accesskey',
-              short_name='k',
-              long_name='create-accesskey',
-              ptype='boolean',
-              optional=True,
-              default=False,
-              request_param=False,
-              doc="Creates an access key for the User."),
-        Param(name='verbose',
-              short_name='v',
-              long_name='verbose',
-              ptype='boolean',
-              optional=True,
-              default=False,
-              request_param=False,
-              doc="causes the response to include the newly created User's ARN and GUID"),
-        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. """)]
+from requestbuilder import Arg
+from . import EuareRequest, DELEGATE
+from .addusertogroup import AddUserToGroup
+from .createaccesskey import CreateAccessKey
 
-    def cli_formatter(self, data):
-        if self.cli_options.verbose:
-            print data['user_data'].Arn
-            print data['user_data'].UserId
-        if self.cli_options.create_accesskey:
-            print data['access_key'].AccessKey['AccessKeyId']
-            print data['access_key'].AccessKey['SecretAccessKey']
+class CreateUser(EuareRequest):
+    Description = '''Create a new user and optionally add the user to a group
+                     or generate an access key for the user'''
+    Args = [Arg('-u', '--user-name', dest='UserName', required=True,
+                help='name of the new user'),
+            Arg('-p', '--path', dest='Path',
+                help='path for the new user (default: "/")'),
+            Arg('-g', '--group-name', route_to=None,
+                help='add the new user to a group'),
+            Arg('-k', '--create-accesskey', action='store_true', route_to=None,
+                help='''create an access key for the new user and print it to
+                        standard out'''),
+            Arg('-v', '--verbose', action='store_true', route_to=None,
+                help="print the new user's ARN and GUID"),
+            DELEGATE]
 
-    def main(self, **args):
-        data = {}
-        data['user_data']  = self.send(**args)
-        if self.cli_options.group_name:
-            obj = euca2ools.commands.euare.addusertogroup.AddUserToGroup()
-            for group_name in self.cli_options.group_name:
-                data['group_name'] = obj.main(group_name=group_name,
-                                              user_name=self.request_params['UserName'],
-                                              delegate=self.request_params.get('DelegateAccount'))
-        if self.cli_options.create_accesskey:
-            obj = euca2ools.commands.euare.createaccesskey.CreateAccessKey()
-            data['access_key'] = obj.main(user_name=self.request_params['UserName'],
-                                          delegate=self.request_params.get('DelegateAccount'))
-        return data
+    def main(self):
+        user_data = self.send()
+        if self.args.get('group_name'):
+            obj = AddUserToGroup(UserName=self.args['UserName'],
+                    GroupName=self.args['group_name'],
+                    DelegateAccount=self.args.get('DelegateAccount'))
+            obj.main()
+        if self.args.get('create_accesskey'):
+            obj = CreateAccessKey(UserName=self.args['UserName'],
+                    DelegateAccount=self.args.get('DelegateAccount'))
+            self.keyresponse = obj.main()
+        return user_data
 
-    def main_cli(self):
-        euca2ools.utils.print_version_if_necessary()
-        self.do_cli()
+    def print_result(self, result):
+        if self.args['verbose']:
+            print result['User']['Arn']
+            print result['User']['UserId']
+        if 'keyresponse' in dir(self):
+            print self.keyresponse['AccessKey']['AccessKeyId']
+            print self.keyresponse['AccessKey']['SecretAccessKey']

-- 
managing cloud instances for Eucalyptus



More information about the pkg-eucalyptus-commits mailing list