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


The following commit has been merged in the master branch:
commit b132ac7466cf397958276febfe36c37814284e7a
Author: Garrett Holmstrom <gholms at fedoraproject.org>
Date:   Tue May 7 12:57:22 2013 -0700

    Port euca-bundle-upload to requestbuilder
    
    Fixes TOOLS-198

diff --git a/bin/euca-bundle-upload b/bin/euca-bundle-upload
index 2f72282..c7b3494 100755
--- a/bin/euca-bundle-upload
+++ b/bin/euca-bundle-upload
@@ -1,42 +1,6 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
+#!/usr/bin/python -tt
 
-# Software License Agreement (BSD License)
-#
-# Copyright (c) 2009-2011, Eucalyptus Systems, Inc.
-# All rights reserved.
-#
-# Redistribution and use of this software in source and binary forms, with or
-# without modification, are permitted provided that the following conditions
-# are met:
-#
-#   Redistributions of source code must retain the above
-#   copyright notice, this list of conditions and the
-#   following disclaimer.
-#
-#   Redistributions in binary form must reproduce the above
-#   copyright notice, this list of conditions and the
-#   following disclaimer in the documentation and/or other
-#   materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# 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
-
-import euca2ools.commands.bundle.bundleupload
+import euca2ools.nc.commands.bundleandupload
 
 if __name__ == '__main__':
-    cmd = euca2ools.commands.bundle.bundleupload.BundleUpload()
-    cmd.main_cli()
-
+    euca2ools.nc.commands.bundleandupload.BundleAndUpload.run()
diff --git a/euca2ools/commands/bundle/__init__.py b/euca2ools/commands/bundle/__init__.py
index b86b85a..d88eb0c 100644
--- a/euca2ools/commands/bundle/__init__.py
+++ b/euca2ools/commands/bundle/__init__.py
@@ -38,6 +38,8 @@ def add_bundle_creds(args, config):
         config_cert = config.get_user_option('x509-cert')
         if 'EC2_CERT' in os.environ:
             args['cert'] = os.getenv('EC2_CERT')
+        elif 'EUCA_CERT' in os.environ:  # used by the NC
+            args['cert'] = os.getenv('EUCA_CERT')
         elif config_cert:
             args['cert'] = config_cert
     if args.get('cert'):
@@ -54,6 +56,8 @@ def add_bundle_creds(args, config):
         config_privatekey = config.get_user_option('x509-key')
         if 'EC2_PRIVATE_KEY' in os.environ:
             args['privatekey'] = os.getenv('EC2_PRIVATE_KEY')
+        if 'EUCA_PRIVATE_KEY' in os.environ:  # used by the NC
+            args['privatekey'] = os.getenv('EUCA_PRIVATE_KEY')
         elif config_privatekey:
             args['privatekey'] = config_privatekey
     if args.get('privatekey'):
diff --git a/euca2ools/commands/bundle/bundleupload.py b/euca2ools/commands/bundle/bundleupload.py
deleted file mode 100644
index fe5c85f..0000000
--- a/euca2ools/commands/bundle/bundleupload.py
+++ /dev/null
@@ -1,153 +0,0 @@
-# Software License Agreement (BSD License)
-#
-# Copyright (c) 2009-2011, Eucalyptus Systems, Inc.
-# All rights reserved.
-#
-# Redistribution and use of this software in source and binary forms, with or
-# without modification, are permitted provided that the following conditions
-# are met:
-#
-#   Redistributions of source code must retain the above
-#   copyright notice, this list of conditions and the
-#   following disclaimer.
-#
-#   Redistributions in binary form must reproduce the above
-#   copyright notice, this list of conditions and the
-#   following disclaimer in the documentation and/or other
-#   materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# 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
-
-import sys
-import os
-import euca2ools.commands.eucacommand
-from boto.roboto.param import Param
-from boto.exception import S3ResponseError, S3CreateError
-from euca2ools.commands.bundle.uploadbundle import UploadBundle
-from euca2ools.commands.bundle.bundleimage import BundleImage
-import euca2ools.bundler
-from euca2ools.exceptions import NotFoundError, CommandFailed
-
-class BundleUpload(UploadBundle, BundleImage):
-
-    Description = """Bundles an image and uploads on behalf of user.
-                     NOTE: For use by the Eucalyptus Node Controller only"""
-    
-    Options = [Param(name='bucket', short_name='b', long_name='bucket',
-                     optional=False, ptype='string',
-                     doc='Name of the bucket to upload to.'),
-               Param(name='image_path', short_name='i', long_name='image',
-                     optional=False, ptype='file',
-                     doc='The path to the image file to bundle'),
-               Param(name='user', short_name='u', long_name='user',
-                     optional=True, ptype='string',
-                     doc='ID of the user doing the bundling'),
-               Param(name='directory', short_name='d', long_name='directory',
-                     optional=True, ptype='string', default='/tmp',
-                     doc='Working directory where bundle should be generated'),
-               Param(name='policy', short_name='c', long_name='policy',
-                     optional=True, ptype='string',
-                     doc='Base64 encoded S3 upload policy'),
-               Param(name='policy_signature',
-                     long_name='policysignature',
-                     optional=True, ptype='string',
-                     doc='Signature for the upload policy'),
-               Param(name='prefix', short_name='p', long_name='prefix',
-                     optional=True, ptype='string',
-                     doc="""The prefix for the bundle image files.
-                     (default: image name)."""),
-               Param(name='kernel_id', long_name='kernel',
-                     optional=True, ptype='string',
-                     doc='ID of the kernel to be associated with the image.'),
-               Param(name='ramdisk_id', long_name='ramdisk',
-                     optional=True, ptype='string',
-                     doc='ID of the ramdisk to be associated with the image.'),
-               Param(name='product_codes', long_name='product-codes',
-                     optional=True, ptype='string',
-                     doc='Product code to be associated with the image.'),
-               Param(name='block_device_mapping',
-                     short_name='b', long_name='block-device-mapping',
-                     optional=True, ptype='string', cardinality='*',
-                     doc="""Default block device mapping for the image
-                     (comma-separated list of key=value pairs)."""),
-               Param(name='target_arch',
-                     short_name='r', long_name='arch',
-                     optional=True, ptype='string', default='x86_64',
-                     choices=['i386', 'x86_64', 'armhf'],
-                     doc='Target architecture for the image.'),
-               Param(name='acl', long_name='acl',
-                     optional=True, ptype='string', default='ec2-bundle-read',
-                     doc='Canned ACL policy')]
-
-    def main(self):
-        self.cert_path = self.get_environ('EC2_CERT')
-        self.ec2cert_path = self.get_environ('EUCALYPTUS_CERT')
-        if self.user is None:
-            self.user = self.get_environ('EC2_USER_ID')
-
-        bundler = euca2ools.bundler.Bundler(self)
-        image_size = bundler.check_image(self.image_path, self.directory)
-        if not self.prefix:
-            self.prefix = self.get_relative_filename(self.image_path)
-        try:
-            tgz_file, sha_tar_digest = bundler.tarzip_image(self.prefix,
-                                                            self.image_path,
-                                                            self.directory)
-        except (NotFoundError, CommandFailed):
-            sys.exit(1)
-
-        encrypted_file, key, iv, bundled_size = bundler.encrypt_image(tgz_file)
-        os.remove(tgz_file)
-        parts, parts_digest = bundler.split_image(encrypted_file)
-        if self.block_device_mapping:
-            self.block_device_mapping = self.get_block_devs()
-        if self.product_codes:
-            self.product_codes = self.add_product_codes(self.product_codes)
-        manifest_path = bundler.generate_manifest(self.directory,
-                                                  self.prefix,
-                                                  parts, parts_digest,
-                                                  self.image_path, key, iv,
-                                                  self.cert_path,
-                                                  self.ec2cert_path,
-                                                  None, self.target_arch,
-                                                  image_size, bundled_size,
-                                                  sha_tar_digest,
-                                                  self.user, self.kernel_id,
-                                                  self.ramdisk_id,
-                                                  self.block_device_mapping,
-                                                  self.product_codes)
-        os.remove(encrypted_file)
-            
-        bucket_instance = self.ensure_bucket(self.acl)
-        parts = self.get_parts(manifest_path)
-        manifest_directory, manifest_file = os.path.split(manifest_path)
-        if not self.directory:
-            self.directory = manifest_directory
-        # TODO: Since Walrus does not fully support S3 policies
-        #       we are going to simply ignore the policy for now.
-        self.upload_manifest(bucket_instance, manifest_path, self.acl,
-                             self.policy, self.policy_signature)
-        self.upload_parts(bucket_instance, self.directory, parts,
-                          None, self.acl, self.policy, self.policy_signature)
-        manifest_path = self.get_relative_filename(manifest_path)
-        print "Uploaded image as %s/%s" % (self.bucket, manifest_path)
-        bucket_instance.connection.make_request(bucket=self.bucket,
-                                                key=manifest_path,
-                                                action='ValidateImage')
-        print 'Validated manifest %s/%s' % (self.bucket, manifest_path)
- 
-    def main_cli(self):
-        self.main()
diff --git a/euca2ools/commands/bundle/uploadbundle.py b/euca2ools/commands/bundle/uploadbundle.py
index 63bcb4d..9c1fc2c 100644
--- a/euca2ools/commands/bundle/uploadbundle.py
+++ b/euca2ools/commands/bundle/uploadbundle.py
@@ -51,9 +51,10 @@ class UploadBundle(WalrusRequest, FileTransferProgressBarMixin):
                 help='bucket to upload the bundle to (required)'),
             Arg('-m', '--manifest', metavar='FILE', required=True,
                 help='manifest for the bundle to upload (required)'),
-            Arg('--acl', choices=('public-read', 'aws-exec-read'),
-                default='aws-exec-read', help='''canned ACL policy to apply
-                to the bundle (default: aws-exec-read)'''),
+            Arg('--acl', default='aws-exec-read',
+                choices=('public-read', 'aws-exec-read', 'ec2-bundle-read'),
+                help='''canned ACL policy to apply to the bundle (default:
+                aws-exec-read)'''),
             Arg('-d', '--directory', metavar='DIR',
                 help='''directory that contains the bundle parts (default:
                 directory that contains the manifest)'''),
diff --git a/euca2ools/nc/commands/bundleandupload.py b/euca2ools/nc/commands/bundleandupload.py
new file mode 100644
index 0000000..b237a50
--- /dev/null
+++ b/euca2ools/nc/commands/bundleandupload.py
@@ -0,0 +1,109 @@
+# Software License Agreement (BSD License)
+#
+# Copyright (c) 2009-2013, Eucalyptus Systems, Inc.
+# All rights reserved.
+#
+# Redistribution and use of this software in source and binary forms, with or
+# without modification, are permitted provided that the following conditions
+# are met:
+#
+#   Redistributions of source code must retain the above
+#   copyright notice, this list of conditions and the
+#   following disclaimer.
+#
+#   Redistributions in binary form must reproduce the above
+#   copyright notice, this list of conditions and the
+#   following disclaimer in the documentation and/or other
+#   materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# 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.
+
+import argparse
+from euca2ools.commands.bundle import add_bundle_creds
+from euca2ools.commands.bundle.bundleimage import BundleImage
+from euca2ools.commands.bundle.uploadbundle import UploadBundle
+from euca2ools.nc.auth import EucaRsaV2Auth
+from euca2ools.nc.services import NCInternalWalrus
+from requestbuilder import Arg
+import requestbuilder.command
+
+
+# FIXME:  This should actually use the policy given by the user instead of
+#         EucaRsaV2Auth.  It previously attempted to use both at the same time,
+#         leading to amusing code paths in walrus, so for the moment it uses
+#         the latter exclusively.
+
+
+class BundleAndUpload(requestbuilder.command.BaseCommand):
+    DESCRIPTION = ('[Eucalyptus NC internal] Bundle and upload an image on '
+                   'behalf of a user')
+    ARGS = [Arg('-b', '--bucket', required=True,
+                help='bucket to upload the bundle to (required)'),
+            Arg('-i', '--image', required=True,
+                help='file containing the image to bundle (required)'),
+            # --arch's default should go away when these bugs are fixed:
+            # https://eucalyptus.atlassian.net/browse/EUCA-5979
+            # https://eucalyptus.atlassian.net/browse/EUCA-5980
+            Arg('-r', '--arch', default='x86_64',
+                help='image architecture (default: x86_64)'),
+            Arg('-d', '--directory', help='''location to place the working
+                directory with temporary files'''),
+            Arg('--cert', metavar='FILE',
+                help='''file containing the X.509 certificate to use when
+                signing requests and bundling the image'''),
+            Arg('--privatekey', metavar='FILE',
+                help='''file containing the private key to use when signing
+                requests and bundling the image'''),
+            Arg('--ec2cert', metavar='FILE',
+                help="file containing the cloud's X.509 certificate"),
+            Arg('--user', metavar='ACCOUNT', help="the user's account ID"),
+            Arg('-c', '--upload-policy', metavar='POLICY',
+                help='Base64-encoded S3 upload policy'),
+            Arg('--upload-policy-signature', '--policysignature',
+                dest='upload_policy_signature', metavar='SIGNATURE',
+                route_to=None, help='''signature for the upload policy given
+                with --upload-policy'''),
+            Arg('-U', '--url', help='storage service endpoint URL'),
+            Arg('--euca-auth', action='store_true', help=argparse.SUPPRESS)]
+    # Note that this is a back end service for which region support is
+    # out of scope.  This isn't going to get tested with that.
+
+    def configure(self):
+        requestbuilder.command.BaseCommand.configure(self)
+
+        add_bundle_creds(self.args, self.config)
+
+        walrus_auth = EucaRsaV2Auth(
+            config=self.config, loglevel=self.log.level,
+            cert=self.args.get('cert'), privatekey=self.args.get('privatekey'))
+        self.__walrus = NCInternalWalrus(auth=walrus_auth, config=self.config,
+                                         loglevel=self.log.level,
+                                         url=self.args.get('url'))
+        self.__walrus.configure()
+
+
+    def main(self):
+        cmd = BundleImage(image=self.args['image'], arch=self.args['arch'],
+                          cert=self.args['cert'],
+                          privatekey=self.args['privatekey'],
+                          user=self.args['user'],
+                          destination=self.args.get('directory'),
+                          ec2cert=self.args['ec2cert'], image_type='machine',
+                          config=self.config)
+        parts, manifest = cmd.main()
+
+        cmd = UploadBundle(bucket=self.args['bucket'], manifest=manifest,
+                           acl='ec2-bundle-read', config=self.config,
+                           service=self.__walrus)
+        manifest_loc = cmd.main()
+        return manifest_loc

-- 
managing cloud instances for Eucalyptus



More information about the pkg-eucalyptus-commits mailing list