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


The following commit has been merged in the master branch:
commit da7573b6b8579633964e93804c95d95d76461e30
Author: Garrett Holmstrom <gholms at fedoraproject.org>
Date:   Sat Apr 21 22:27:07 2012 -0700

    Move block device mapping parser type

diff --git a/euca2ools/commands/euca/__init__.py b/euca2ools/commands/euca/__init__.py
index 04063b9..45c58a4 100644
--- a/euca2ools/commands/euca/__init__.py
+++ b/euca2ools/commands/euca/__init__.py
@@ -233,47 +233,6 @@ class EucalyptusRequest(Euca2oolsRequest, TabifyingCommand):
                            task.get('startTime'), task.get('updateTime'),
                            task.get('state')])
 
-## TODO:  test this
-class BlockDeviceMapping(dict):
-    '''
-    A block device mapping as given on the image registration command line
-    '''
-    def __init__(self, map_as_str):
-        dict.__init__(self)
-        try:
-            (device, mapping) = map_as_str.split('=')
-        except ValueError:
-            raise argparse.ArgumentTypeError('block device mapping {0} must '
-                    'have form KEY=VALUE'.format(map_as_str))
-            if mapping.lower() == 'none':
-                ## FIXME:  NoDevice should be an empty element
-                self['Ebs'] = {'NoDevice': 'true'}
-            elif mapping.startswith('ephemeral'):
-                self['VirtualName'] = mapping
-            elif (mapping.startswith('snap-') or mapping.startswith('vol-') or
-                  mapping.startswith(':')):
-                map_bits = mapping.split(':')
-                if len(map_bits) == 1:
-                    map_bits.append(None)
-                if len(map_bits) == 2:
-                    map_bits.append('true')
-                if len(map_bits) != 3:
-                    raise argparse.ArgumentTypeError(
-                            'EBS block device mapping {0} must have form '
-                            '[snap-id]:[size]:[true|false]'.format(map_as_str))
-                try:
-                    int(map_bits[1])
-                except TypeError:
-                    raise argparse.ArgumentTypeError(
-                            'second element of EBS block device mapping {0} '
-                            'must be an integer')
-                if map_bits[2] not in ('true', 'false'):
-                    raise argparse.ArgumentTypeError(
-                            'third element of EBS block device mapping {0} '
-                            "must be 'true' or 'false'".format(map_as_str))
-                self['Ebs'] = {'SnapshotId':          map_bits[0],
-                               'VolumeSize':          map_bits[1],
-                               'DeleteOnTermination': map_bits[2]}
 
 def _find_args_by_parg(arglike, parg):
     if isinstance(arglike, Arg):
diff --git a/euca2ools/commands/euca/argtypes.py b/euca2ools/commands/euca/argtypes.py
index 95e1082..c7820d7 100644
--- a/euca2ools/commands/euca/argtypes.py
+++ b/euca2ools/commands/euca/argtypes.py
@@ -28,8 +28,57 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 
+import argparse
 from requestbuilder import EMPTY
 
+def block_device_mapping(map_as_str):
+    '''
+    Parse a block device mapping from an image registration command line.
+    '''
+    try:
+        (device, mapping) = map_as_str.split('=')
+    except ValueError:
+        raise argparse.ArgumentTypeError(
+                'block device mapping "{0}" must have form '
+                'DEVICE=[SNAP-ID]:[SIZE]:[true|false]'.format(map_as_str))
+    map_dict = {}
+    if mapping.lower() == 'none':
+        map_dict['Ebs'] = {'NoDevice': EMPTY}
+    elif mapping.startswith('ephemeral'):
+        map_dict['VirtualName'] = mapping
+    elif (mapping.startswith('snap-') or mapping.startswith('vol-') or
+          mapping.startswith(':')):
+        map_bits = mapping.split(':')
+        if len(map_bits) == 1:
+            map_bits.append(None)
+        if len(map_bits) == 2:
+            map_bits.append(None)
+        if len(map_bits) != 3:
+            raise argparse.ArgumentTypeError(
+                    'EBS block device mapping "{0}" must have form '
+                    'DEVICE=[SNAP-ID]:[SIZE]:[true|false]'.format(map_as_str))
+
+        map_dict['Ebs'] = {}
+        if map_bits[0]:
+            map_dict['Ebs']['SnapshotId'] = map_bits[0]
+        if map_bits[1]:
+            try:
+                map_dict['Ebs']['VolumeSize'] = int(map_bits[1])
+            except ValueError:
+                raise argparse.ArgumentTypeError(
+                        'second element of EBS block device mapping "{0}" '
+                        'must be an integer'.format(map_as_str))
+        if map_bits[2]:
+            if map_bits[2].lower() not in ('true', 'false'):
+                raise argparse.ArgumentTypeError(
+                        'third element of EBS block device mapping "{0}" must '
+                        'be "true" or "false"'.format(map_as_str))
+            map_dict['Ebs']['DeleteOnTermination'] = map_bits[2].lower()
+    else:
+        raise argparse.ArgumentTypeError(
+                'unrecognized block device mapping "{0}"'.format(map_as_str))
+    return map_dict
+
 def binary_tag_def(tag_str):
     '''
     Parse a tag definition from the command line.  Return a dict that depends

-- 
managing cloud instances for Eucalyptus



More information about the pkg-eucalyptus-commits mailing list