[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:31:09 UTC 2013


The following commit has been merged in the master branch:
commit 4da931a3fdc40facb28bc13e487d382d70b3c4ab
Author: Garrett Holmstrom <gholms at fedoraproject.org>
Date:   Fri Apr 26 00:19:42 2013 -0700

    Fix base64-encoding of user data
    
    Fixes TOOLS-309

diff --git a/euca2ools/commands/autoscaling/createlaunchconfiguration.py b/euca2ools/commands/autoscaling/createlaunchconfiguration.py
index 91eed7d..3ead691 100644
--- a/euca2ools/commands/autoscaling/createlaunchconfiguration.py
+++ b/euca2ools/commands/autoscaling/createlaunchconfiguration.py
@@ -28,8 +28,9 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 
+import base64
 from euca2ools.commands.argtypes import (delimited_list,
-                                         ec2_block_device_mapping)
+    ec2_block_device_mapping)
 from euca2ools.commands.autoscaling import AutoScalingRequest
 from requestbuilder import Arg, MutuallyExclusiveArgList
 
@@ -76,11 +77,34 @@ class CreateLaunchConfiguration(AutoScalingRequest):
             Arg('--spot-price', dest='SpotPrice', metavar='PRICE',
                 help='maximum hourly price for any spot instances launched'),
             MutuallyExclusiveArgList(
-                Arg('--user-data', dest='UserData', metavar='DATA',
-                    help='data to make available to instances'),
-                Arg('--user-data-file', dest='UserData', metavar='FILE',
-                    type=open, help='''file containing data to make available
-                    to instances'''))]
+                Arg('-d', '--user-data', metavar='DATA', route_to=None,
+                    help='user data to make available to instances'),
+                Arg('--user-data-force', metavar='DATA', route_to=None,
+                    help='''same as -d/--user-data, but without checking if a
+                    file by that name exists first'''),
+                Arg('-f', '--user-data-file', metavar='FILE', route_to=None,
+                    help='''file containing user data to make available to
+                    instances''')),
+
+    def configure(self):
+        AutoScalingRequest.configure(self)
+        if self.args.get('user_data'):
+            if os.path.isfile(self.args['user_data']):
+                raise ArgumentError(
+                    'argument -d/--user-data: to pass the contents of a file '
+                    'as user data, use -f/--user-data-file.  To pass the '
+                    "literal value '{0}' as user data even though it matches "
+                    'the name of a file, use --user-data-force.')
+            else:
+                self.params['UserData'] = base64.b64encode(
+                    self.args['user_data'])
+        elif self.args.get('user_data_force'):
+            self.params['UserData'] = base64.b64encode(
+                self.args['user_data_force'])
+        elif self.args.get('user_data_file'):
+            with open(self.args['user_data_file']) as user_data_file:
+                self.params['UserData'] = base64.b64encode(
+                    user_data_file.read())
 
     def preprocess(self):
         if self.args.get('block_device_mapping'):
diff --git a/euca2ools/commands/euca/runinstances.py b/euca2ools/commands/euca/runinstances.py
index 5c1a066..7867215 100644
--- a/euca2ools/commands/euca/runinstances.py
+++ b/euca2ools/commands/euca/runinstances.py
@@ -30,8 +30,8 @@
 
 import argparse
 import base64
-from euca2ools.commands.argtypes import (b64encoded_file_contents,
-    ec2_block_device_mapping, vpc_interface)
+from euca2ools.commands.argtypes import (ec2_block_device_mapping,
+    vpc_interface)
 from euca2ools.commands.euca import EucalyptusRequest
 import os.path
 from requestbuilder import Arg, MutuallyExclusiveArgList
@@ -55,17 +55,15 @@ class RunInstances(EucalyptusRequest):
             Arg('-k', '--key', dest='KeyName', metavar='KEYPAIR',
                 help='name of the key pair to use'),
             MutuallyExclusiveArgList(
-                Arg('-d', '--user-data', dest='UserData', metavar='DATA',
-                    type=base64.b64encode,
+                Arg('-d', '--user-data', metavar='DATA', route_to=None,
                     help='''user data to make available to instances in this
                             reservation'''),
-                Arg('--user-data-force', dest='UserData',
-                    type=base64.b64encode, help=argparse.SUPPRESS),
-                    # ^ deprecated  ## TODO:  decide if that should remain the case
-                Arg('-f', '--user-data-file', dest='UserData',
-                    metavar='DATA-FILE', type=b64encoded_file_contents,
+                Arg('--user-data-force', metavar='DATA', route_to=None,
+                    help='''same as -d/--user-data, but without checking if a
+                    file by that name exists first'''),
+                Arg('-f', '--user-data-file', metavar='FILE', route_to=None,
                     help='''file containing user data to make available to the
-                            instances in this reservation''')),
+                    instances in this reservation''')),
             Arg('--addressing', dest='AddressingType',
                 choices=('public', 'private'), help='''[Eucalyptus only]
                 addressing scheme to launch the instance with.  Use "private"
@@ -146,6 +144,26 @@ class RunInstances(EucalyptusRequest):
                  'blockDeviceMapping', 'productCodes', 'networkInterfaceSet',
                  'attachment', 'association', 'privateIpAddressesSet']
 
+    def configure(self):
+        EucalyptusRequest.configure(self)
+        if self.args.get('user_data'):
+            if os.path.isfile(self.args['user_data']):
+                raise ArgumentError(
+                    'argument -d/--user-data: to pass the contents of a file '
+                    'as user data, use -f/--user-data-file.  To pass the '
+                    "literal value '{0}' as user data even though it matches "
+                    'the name of a file, use --user-data-force.')
+            else:
+                self.params['UserData'] = base64.b64encode(
+                    self.args['user_data'])
+        elif self.args.get('user_data_force'):
+            self.params['UserData'] = base64.b64encode(
+                self.args['user_data_force'])
+        elif self.args.get('user_data_file'):
+            with open(self.args['user_data_file']) as user_data_file:
+                self.params['UserData'] = base64.b64encode(
+                    user_data_file.read())
+
     def preprocess(self):
         counts = self.args['count'].split('-')
         if len(counts) == 1:

-- 
managing cloud instances for Eucalyptus



More information about the pkg-eucalyptus-commits mailing list