[pkg-eucalyptus-commits] [SCM] managing cloud instances for Eucalyptus branch, master, updated. 3.0.0-alpha3-257-g1da8e3a

Matt Spaulding mspaulding06 at gmail.com
Sun Jun 16 02:31:23 UTC 2013


The following commit has been merged in the master branch:
commit a09456111132af5a05019148e7250a460c65e4de
Author: Matt Spaulding <mspaulding06 at gmail.com>
Date:   Mon May 13 13:55:18 2013 -0700

    More code cleanup and removed MetadataReadError

diff --git a/euca2ools/commands/bundle/bundlevol.py b/euca2ools/commands/bundle/bundlevol.py
index 4a83fa6..bb7a25e 100644
--- a/euca2ools/commands/bundle/bundlevol.py
+++ b/euca2ools/commands/bundle/bundlevol.py
@@ -38,15 +38,16 @@ import sys
 from euca2ools.commands.argtypes import delimited_list, filesize
 from euca2ools.commands.bundle import BundleCommand
 from euca2ools.commands.bundle.bundleimage import BundleImage
-from euca2ools.commands.bundle.helpers import (get_metadata, get_metadata_dict,
+from euca2ools.commands.bundle.helpers import (check_metadata, get_metadata,
+                                               get_metadata_dict,
                                                get_metadata_list)
-from euca2ools.commands.bundle.imagecreator import ImageCreator
-from euca2ools.exceptions import AWSError, MetadataReadError
+from euca2ools.commands.bundle.imagecreator import ImageCreator, IMAGE_MAX_SIZE
 from requestbuilder import Arg, MutuallyExclusiveArgList
-from requestbuilder.mixins import FileTransferProgressBarMixin
+from requestbuilder.command import BaseCommand
+from requestbuilder.exceptions import ServerError
 
 
-IMAGE_MAX_SIZE_IN_MB = euca2ools.bundler.IMAGE_MAX_SIZE / 1024 // 1024
+IMAGE_MAX_SIZE_IN_MB = IMAGE_MAX_SIZE / 1024 // 1024
 #
 # We pass our args dict along to BundleImage so we need to remove all the
 # args that it doesn't understand.
@@ -108,6 +109,8 @@ class BundleVol(BundleCommand):
         a bundled image.
         """
         try:
+            check_metadata()
+
             if not self.args.get('ramdisk'):
                 self.args['ramdisk'] = get_metadata('ramdisk-id')
                 self.log.debug("inheriting ramdisk: {0}"
@@ -122,25 +125,30 @@ class BundleVol(BundleCommand):
                 self.log.debug("inheriting block device mappings: {0}"
                                .format(self.args.get('block_device_mappings')))
             #
-            # Product codes and ancestor AMI ids are special cases since they
-            # aren't supported by Eucalyptus yet.
+            # Product codes and ancestor ids are special cases since they
+            # aren't always there.
             #
             try:
-                self.args['productcodes'].extend(get_metadata_list('product-codes'))
-            except MetadataReadError:
-                print >> sys.stderr, 'Unable to read product codes.'
+                self.args['productcodes'].extend(
+                    get_metadata_list('product-codes'))
+            except ServerError:
+                msg = 'unable to read product codes from metadata.'
+                print sys.stderr, msg
+                self.log.warn(msg)
             try:
                 if not self.args.get('ancestor_image_ids'):
                     self.args['ancestor_image_ids'] = []
                 self.args['ancestor_image_ids'].extend(
                     get_metadata_list('ancestor-ami-ids'))
-            except MetadataReadError:
-                print >> sys.stderr, 'Unable to read ancestor ids.'
-        except MetadataReadError:
+            except ServerError:
+                msg = 'unable to read ancestor ids.'
+                print sys.stderr, msg
+                self.log.warn(msg)
+        except ServerError:
             print >> sys.stderr, 'Unable to read instance metadata.'
             print >> sys.stderr, 'Pass the --no-inherit option if you wish to', \
                 'exclude instance metadata.'
-            sys.exit(1)
+            raise
             
     def _filter_args_for_bundle_image(self):
         """Make a complete copy of args to pass along to BundleImage. We first
diff --git a/euca2ools/commands/bundle/helpers.py b/euca2ools/commands/bundle/helpers.py
index 4fb7fdd..94e388e 100644
--- a/euca2ools/commands/bundle/helpers.py
+++ b/euca2ools/commands/bundle/helpers.py
@@ -30,15 +30,16 @@
 
 from euca2ools.commands.walrus.getobject import GetObject
 from euca2ools.commands.walrus.listbucket import ListBucket
-from euca2ools.exceptions import MetadataReadError
 import os
+from requestbuilder.exceptions import ClientError, ServerError
 import requests
-import sys
+from requests.exceptions import Timeout
 from urlparse import urljoin
 from xml.dom import minidom
 
 
 METADATA_URL = 'http://169.254.169.254/latest/meta-data/'
+METADATA_TIMEOUT = 10
 
 
 def get_manifest_parts(manifest, bucket=None):
@@ -96,8 +97,9 @@ def download_files(bucket, keys, directory, **kwargs):
 
 def check_metadata():
     """Check if instance metadata is available."""
-    if not requests.get(METADATA_URL).ok:
-        raise MetadataReadError
+    response = requests.get(METADATA_URL)
+    if not response.ok:
+        raise ServerError(response)
 
 
 def get_metadata(*paths):
@@ -109,11 +111,16 @@ def get_metadata(*paths):
     url = METADATA_URL
     if paths:
         url = urljoin(url, "/".join(paths))
-    response = requests.get(url)
+
+    try:
+        response = requests.get(url)
+    except Timeout:
+        raise ClientError("timeout occurred when getting instance metadata.")
+
     if response.ok:
         return response.content
     else:
-        raise MetadataReadError
+        raise ServerError(response)
 
 
 def get_metadata_list(*paths):
diff --git a/euca2ools/commands/bundle/imagecreator.py b/euca2ools/commands/bundle/imagecreator.py
index 4d605d6..f3f717a 100644
--- a/euca2ools/commands/bundle/imagecreator.py
+++ b/euca2ools/commands/bundle/imagecreator.py
@@ -29,7 +29,7 @@
 # POSSIBILITY OF SUCH DAMAGE.
 #
 
-from euca2ools.exceptions import CopyError
+from euca2ools.exceptions import CommandFailed, UnsupportedException
 from euca2ools.utils import execute, check_command, sanitize_path
 from euca2ools.utils import mkdtemp_for_large_files as mkdtemp
 from requestbuilder.exceptions import ArgumentError
@@ -102,6 +102,7 @@ DEFAULT_FS_EXCLUDES = [
     '/proc',
     '/sys',
 ]
+IMAGE_MAX_SIZE = 10 * 1024 * 1024 * 1024 # 10GB Max Size in bytes
 
 
 class VolumeSync(object):
@@ -135,7 +136,7 @@ class VolumeSync(object):
         # the user keeps their fstab from the original volume.
         #
         if self.fstab:
-            with open(fstab, 'r') as fp:
+            with open(self.fstab, 'r') as fp:
                 self._install_fstab(fp.read())
         elif self.generate_fstab_file:
             self._install_generated_fstab()
@@ -154,7 +155,7 @@ class VolumeSync(object):
             else:
                 self.includes.append(include)
 
-    def bundle_all_dirs(self):
+    def bundle_all(self):
         self.bundle_all_dirs = True
 
     def filter_files(self):
@@ -271,11 +272,11 @@ class VolumeSync(object):
         # rsync return code 24: Partial transfer due to vanished source files
         #
         if retval in (23, 24):
-            print >> sys.stderr, 'Warning: rsync reports files partially copied:'
-            print >> sys.stderr, out
+            if self.log:
+                self.log.warn('rsync reports files partially copied.')
+            print sys.stderr, "Warning: rsync reports files partially copied."
         elif retval != 0:
-            print >> sys.stderr, 'Error: rsync failed with return code {0}'.format(retval)
-            raise CopyError
+            raise Exception('rsync failed with return code {0}.'.format(retval))
 
     def _sync_disks(self):
         execute('sync', log=self.log)
@@ -364,6 +365,8 @@ class ImageCreator(object):
                 volsync.generate_fstab()
             if self.filter:
                 volsync.filter_files()
+            if self.bundle_all_dirs:
+                volsync.bundle_all()
             volsync.exclude(self.excludes)
             volsync.include(self.includes)
             volsync.run()
diff --git a/euca2ools/exceptions.py b/euca2ools/exceptions.py
index be94282..1b0f9f9 100644
--- a/euca2ools/exceptions.py
+++ b/euca2ools/exceptions.py
@@ -30,7 +30,6 @@
 #
 # Author: Neil Soman neil at eucalyptus.com
 
-import logging
 
 class EucaError(Exception):
 
@@ -101,13 +100,6 @@ class CopyError(EucaError):
     def __init__(self):
         self._message = 'Unable to copy'
 
-class MetadataReadError(EucaError):
-
-    def __init__(self, metadata_type=None):
-        self._message = 'Unable to read metadata'
-        if metadata_type:
-            self._message += ' for {0}'.format(metadata_type)
-
 class NotFoundError(EucaError):
 
     def __init__(self):

-- 
managing cloud instances for Eucalyptus



More information about the pkg-eucalyptus-commits mailing list