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


The following commit has been merged in the master branch:
commit 4dc2888957953b7f7bf674b861a4c94c0bb48980
Author: Garrett Holmstrom <gholms at fedoraproject.org>
Date:   Sat Apr 28 21:45:57 2012 -0700

    Rewrite RegisterImage

diff --git a/bin/euca-register b/bin/euca-register
index c284870..43fb9e3 100755
--- a/bin/euca-register
+++ b/bin/euca-register
@@ -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.euca.register
+import euca2ools.commands.euca.registerimage
 
 if __name__ == '__main__':
-    cmd = euca2ools.commands.euca.register.Register()
-    cmd.main_cli()
-
+    euca2ools.commands.euca.registerimage.RegisterImage().do_cli()
diff --git a/euca2ools/commands/euca/argtypes.py b/euca2ools/commands/euca/argtypes.py
index 97fa739..e0742ab 100644
--- a/euca2ools/commands/euca/argtypes.py
+++ b/euca2ools/commands/euca/argtypes.py
@@ -41,10 +41,11 @@ def block_device_mapping(map_as_str):
     except ValueError:
         raise argparse.ArgumentTypeError(
                 'block device mapping "{0}" must have form '
-                'DEVICE=[SNAP-ID]:[SIZE]:[true|false]'.format(map_as_str))
-    map_dict = {}
+                'DEVICE=MAPPED'.format(map_as_str))
+    map_dict = {'DeviceName': device}
     if mapping.lower() == 'none':
-        map_dict['Ebs'] = {'NoDevice': EMPTY}
+        ## FIXME:  EC2 does not accept this, despite its documentation
+        map_dict['Ebs'] = {'NoDevice': 'true'}
     elif mapping.startswith('ephemeral'):
         map_dict['VirtualName'] = mapping
     elif (mapping.startswith('snap-') or mapping.startswith('vol-') or
@@ -75,9 +76,19 @@ def block_device_mapping(map_as_str):
                         '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()
+        if not map_dict['Ebs']:
+            raise argparse.ArgumentTypeError(
+                    'EBS block device mapping "{0}" must specify at least one '
+                    'element.  Use "{1}=none" to specify that no device '
+                    'should be mapped.'.format(map_as_str, device))
+    elif not mapping:
+        raise argparse.ArgumentTypeError(
+                'invalid block device mapping "{0}".  Use "{1}=none" to '
+                'specify that no device should be mapped.'.format(map_as_str,
+                                                                  device))
     else:
         raise argparse.ArgumentTypeError(
-                'unrecognized block device mapping "{0}"'.format(map_as_str))
+                'invalid block device mapping "{0}"'.format(map_as_str))
     return map_dict
 
 def file_contents(filename):
diff --git a/euca2ools/commands/euca/register.py b/euca2ools/commands/euca/register.py
deleted file mode 100644
index 5894b24..0000000
--- a/euca2ools/commands/euca/register.py
+++ /dev/null
@@ -1,97 +0,0 @@
-# Software License Agreement (BSD License)
-#
-# Copyright (c) 20092011, 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.eucacommand
-from boto.roboto.param import Param
-
-class Register(euca2ools.commands.eucacommand.EucaCommand):
-
-    Description = 'Registers a manifest for use with the cloud.'
-    Options = [Param(name='block_device_mapping',
-                     short_name='b', long_name='block-device-mapping',
-                     optional=True, ptype='string', cardinality='*',
-                     doc="""Block device mapping for the instance(s).
-                     Option may be used multiple times."""),
-               Param(name='description',
-                     short_name='d', long_name='description',
-                     optional=True, ptype='string',
-                     doc='Description of the image.'),
-               Param(name='name', short_name='n', long_name='name',
-                     optional=True, ptype='string',
-                     doc='Name of the image.'),
-               Param(name='architecture',
-                     short_name='a', long_name='architecture',
-                     optional=True, ptype='string', default='i386',
-                     choices=['i386', 'x86_64'],
-                     doc='The architecture of the image.'),
-               Param(name='kernel', long_name='kernel',
-                     optional=True, ptype='string',
-                     doc='The ID of the kernel associated with the image.'),
-               Param(name='ramdisk', long_name='ramdisk',
-                     optional=True, ptype='string',
-                     doc='The ID of the ramdisk associated with the image.'),
-               Param(name='root_device_name', long_name='root-device-name',
-                     optional=True, ptype='string',
-                     doc='The root device name (e.g., /dev/sda1, or xvda).'),
-               Param(name='snapshot', short_name='s', long_name='snapshot',
-                     optional=True, ptype='string',
-                     doc='The snapshot ID to use as the root device.')]
-    Args = [Param(name='image_location',
-                  optional=True, ptype='string',
-                  doc="""Path to the uploaded image (bucket/manifest).
-                         Required if registering an S3-based image""")]
-               
-    def main(self):
-        if self.snapshot:
-            if not self.root_device_name:
-                self.root_device_name = '/dev/sda1'
-            self.block_device_mapping.append('%s=%s' % (self.root_device_name,
-                                                    self.snapshot))
-        if self.block_device_mapping:
-            self.block_device_mapping = self.parse_block_device_args(self.block_device_mapping)
-        conn = self.make_connection_cli()
-        return self.make_request_cli(conn, 'register_image',
-                                     name=self.name,
-                                     description=self.description,
-                                     image_location=self.image_location,
-                                     architecture=self.architecture,
-                                     kernel_id=self.kernel,
-                                     ramdisk_id=self.ramdisk,
-                                     root_device_name=self.root_device_name,
-                                     block_device_map=self.block_device_mapping)
-
-    def main_cli(self):
-        image_id = self.main()
-        if image_id:
-            print 'IMAGE\t%s' % image_id
diff --git a/euca2ools/commands/euca/registerimage.py b/euca2ools/commands/euca/registerimage.py
new file mode 100644
index 0000000..7fcab7a
--- /dev/null
+++ b/euca2ools/commands/euca/registerimage.py
@@ -0,0 +1,102 @@
+# Software License Agreement (BSD License)
+#
+# Copyright (c) 2009-2012, 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.
+
+from requestbuilder import Arg
+from . import EucalyptusRequest
+from .argtypes import block_device_mapping
+
+class RegisterImage(EucalyptusRequest):
+    Description = 'Register a new image'
+    Args = [Arg('ImageLocation', metavar='MANIFEST', nargs='?',
+                help='''location of the image manifest in S3 storage
+                (required for instance-store images)'''),
+            Arg('-n', '--name', dest='Name', required=True,
+                help='name of the new image (required)'),
+            Arg('-d', '--description', dest='Description',
+                help='description of the new image'),
+            Arg('-a', '--architecture', dest='Architecture',
+                choices=('i386', 'x86_64'),
+                help='CPU architecture of the new image'),
+            Arg('--kernel', dest='KernelId', metavar='KERNEL',
+                help='kernel to associate with the new image'),
+            Arg('--ramdisk', dest='RamdiskId', metavar='RAMDISK',
+                help='ramdisk to associate with the new image'),
+            Arg('--root-device-name', dest='RootDeviceName', metavar='DEVICE',
+                help='root device name (default: /dev/sda1)'),
+                # ^ default is added by main()
+            Arg('--snapshot', route_to=None,
+                help='snapshot to use for the root device'),
+            Arg('-b', '--block-device-mapping', metavar='DEVICE=MAPPED',
+                dest='BlockDeviceMapping', action='append',
+                type=block_device_mapping, default=[],
+                help='''define a block device mapping for the image, in the
+                form DEVICE=MAPPED, where "MAPPED" is "none", "ephemeral(0-3)",
+                or "[SNAP-ID]:[SIZE]:[true|false]"''')]
+
+    def main(self):
+        if self.args.get('ImageLocation'):
+            # instance-store image
+            if self.args.get('RootDeviceName'):
+                self._cli_parser.error('argument --root-device-name: not '
+                        'allowed with argument MANIFEST')
+            if self.args.get('snapshot'):
+                self._cli_parser.error('argument --snapshot: not allowed '
+                        'with argument MANIFEST')
+        else:
+            # Try for an EBS image
+            if not self.args.get('RootDeviceName'):
+                self.args['RootDeviceName'] = '/dev/sda1'
+            snapshot = self.args.get('snapshot')
+            # Look for a mapping for the root device
+            for mapping in self.args['BlockDeviceMapping']:
+                if mapping.get('DeviceName') == self.args['RootDeviceName']:
+                    if (snapshot and
+                        snapshot != mapping.get('Ebs', {}).get('SnapshotId')):
+                        # The mapping's snapshot differs or doesn't exist
+                        self._cli_parser.error('value supplied with '
+                                '--snapshot conflicts with block device '
+                                'mapping for root device ' +
+                                mapping['DeviceName'])
+                    else:
+                        # No need to apply --snapshot since the mapping is
+                        # already there
+                        break
+            else:
+                if snapshot:
+                    self.args['BlockDeviceMapping'].append(
+                            {'DeviceName': self.args['RootDeviceName'],
+                             'Ebs':        {'SnapshotId': snapshot}})
+                else:
+                    self._cli_parser.error('either a manifest location or a '
+                            'root device snapshot mapping must be specified')
+        return self.send()
+
+    def print_result(self, result):
+        print self.tabify(('IMAGE', result.get('imageId')))

-- 
managing cloud instances for Eucalyptus



More information about the pkg-eucalyptus-commits mailing list