libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [1/2] git commit: LIBCLOUD-508: Add support for registering Amazon Machine Images using S3 manifests or Snapshots. New tests are also included.
Date Sun, 02 Feb 2014 18:28:02 GMT
Updated Branches:
  refs/heads/trunk 45a7e94fa -> aa7e59e25


LIBCLOUD-508: Add support for registering Amazon Machine Images using S3 manifests or Snapshots.
New tests are also included.

Closes #241

Signed-off-by: Tomaz Muraus <tomaz@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/834a9ead
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/834a9ead
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/834a9ead

Branch: refs/heads/trunk
Commit: 834a9eadf02c99b9e08c664fa57685f345007167
Parents: 45a7e94
Author: Chris DeRamus <chris@divvycloud.com>
Authored: Sun Feb 2 11:15:44 2014 -0500
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Sun Feb 2 19:08:29 2014 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/ec2.py                 | 71 ++++++++++++++++++++
 .../compute/fixtures/ec2/register_image.xml     |  4 ++
 libcloud/test/compute/test_ec2.py               | 14 ++++
 3 files changed, 89 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/834a9ead/libcloud/compute/drivers/ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py
index f138f3d..98d4663 100644
--- a/libcloud/compute/drivers/ec2.py
+++ b/libcloud/compute/drivers/ec2.py
@@ -1682,6 +1682,77 @@ class BaseEC2NodeDriver(NodeDriver):
         response = self.connection.request(self.path, params=params).object
         return self._get_boolean(response)
 
+    def ex_register_image(self, name, description=None, architecture=None,
+                          image_location=None, root_device_name=None,
+                          block_device_mapping=None, kernel_id=None,
+                          ramdisk_id=None):
+        """
+        Registers an Amazon Machine Image based off of an EBS-backed instance.
+        Can also be used to create images from snapshots. More information
+        can be found at http://goo.gl/hqZq0a.
+
+        :param      name:  The name for the AMI being registered
+        :type       name: ``str``
+
+        :param      description: The description of the AMI (optional)
+        :type       description: ``str``
+
+        :param      architecture: The architecture of the AMI (i386/x86_64)
+                                  (optional)
+        :type       architecture: ``str``
+
+        :param      image_location: The location of the AMI within Amazon S3
+                                    Required if registering an instance
+                                    store-backed AMI
+        :type       image_location: ``str``
+
+        :param      root_device_name: The device name for the root device
+                                      Required if registering a EBS-backed AMI
+        :type       root_device_name: ``str``
+
+        :param      block_device_mapping: A dictionary of the disk layout
+                                          (optional)
+        :type       block_device_mapping: ``dict``
+
+        :param      kernel_id: Kernel id for AMI (optional)
+        :type       kernel_id: ``str``
+
+        :param      ramdisk_id: RAM disk for AMI (optional)
+        :type       ramdisk_id: ``str``
+
+        :rtype:     :class:`NodeImage`
+        """
+
+        params = {'Action': 'RegisterImage',
+                  'Name': name}
+
+        if description is not None:
+            params['Description'] = description
+
+        if architecture is not None:
+            params['Architecture'] = architecture
+
+        if image_location is not None:
+            params['ImageLocation'] = image_location
+
+        if root_device_name is not None:
+            params['RootDeviceName'] = root_device_name
+
+        if block_device_mapping is not None:
+            params.update(self._get_block_device_mapping_params(
+                          block_device_mapping))
+
+        if kernel_id is not None:
+            params['KernelId'] = kernel_id
+
+        if ramdisk_id is not None:
+            params['RamDiskId'] = ramdisk_id
+
+        image = self._to_image(
+            self.connection.request(self.path, params=params).object
+        )
+        return image
+
     def ex_list_networks(self):
         """
         Return a list of :class:`EC2Network` objects for the

http://git-wip-us.apache.org/repos/asf/libcloud/blob/834a9ead/libcloud/test/compute/fixtures/ec2/register_image.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/ec2/register_image.xml b/libcloud/test/compute/fixtures/ec2/register_image.xml
new file mode 100644
index 0000000..ebaeb08
--- /dev/null
+++ b/libcloud/test/compute/fixtures/ec2/register_image.xml
@@ -0,0 +1,4 @@
+<RegisterImageResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/">
+    <requestId>6d858ea7-053e-4751-9fae-b891019fc8d2</requestId>
+    <imageId>ami-57c2fb3e</imageId>
+</RegisterImageResponse>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/834a9ead/libcloud/test/compute/test_ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_ec2.py b/libcloud/test/compute/test_ec2.py
index 4d28faa..4a0d038 100644
--- a/libcloud/test/compute/test_ec2.py
+++ b/libcloud/test/compute/test_ec2.py
@@ -474,6 +474,16 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin):
         resp = self.driver.ex_destroy_image(image)
         self.assertTrue(resp)
 
+    def ex_register_image(self):
+        mapping = [{'DeviceName': '/dev/sda1',
+                    'Ebs': {'SnapshotId': 'snap-5ade3e4e'}}]
+        image = self.driver.ex_register_image(name='Test Image',
+                                              root_device_name='/dev/sda1',
+                                              description='My Image',
+                                              architecture='x86_64',
+                                              block_device_mapping=mapping)
+        self.assertEqual(image.id, 'ami-57c2fb3e')
+
     def test_ex_list_availability_zones(self):
         availability_zones = self.driver.ex_list_availability_zones()
         availability_zone = availability_zones[0]
@@ -1095,6 +1105,10 @@ class EC2MockHttp(MockHttpTestCase):
         body = self.fixtures.load('describe_images.xml')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
+    def _RegisterImages(self, method, url, body, headers):
+        body = self.fixtures.load('register_image.xml')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
     def _ex_imageids_DescribeImages(self, method, url, body, headers):
         body = self.fixtures.load('describe_images_ex_imageids.xml')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])


Mime
View raw message