libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [1/4] libcloud git commit: Added Billing Product for image in EC2 compute driver Closes #1024
Date Mon, 10 Apr 2017 02:10:29 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk ab59cf4a2 -> 9e864c66d


Added Billing Product for image in EC2 compute driver
Closes #1024


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

Branch: refs/heads/trunk
Commit: c68b85e3d01cce258d217462438196780dc9050d
Parents: ab59cf4
Author: Nirzari Iyer <niyer@localhost.localdomain>
Authored: Fri Feb 24 17:39:52 2017 -0500
Committer: Anthony Shaw <anthonyshaw@apache.org>
Committed: Mon Apr 10 12:02:20 2017 +1000

----------------------------------------------------------------------
 libcloud/compute/drivers/ec2.py                 | 41 +++++++++++++++++++-
 .../compute/fixtures/ec2/describe_images.xml    | 12 +++++-
 .../ec2/describe_images_ex_imageids.xml         |  7 +++-
 libcloud/test/compute/test_ec2.py               |  8 +++-
 4 files changed, 63 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/c68b85e3/libcloud/compute/drivers/ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py
index 466b802..a8cd9da 100644
--- a/libcloud/compute/drivers/ec2.py
+++ b/libcloud/compute/drivers/ec2.py
@@ -3928,7 +3928,7 @@ class BaseEC2NodeDriver(NodeDriver):
                           image_location=None, root_device_name=None,
                           block_device_mapping=None, kernel_id=None,
                           ramdisk_id=None, virtualization_type=None,
-                          ena_support=None):
+                          ena_support=None, billing_products=None):
         """
         Registers an Amazon Machine Image based off of an EBS-backed instance.
         Can also be used to create images from snapshots. More information
@@ -3972,6 +3972,9 @@ class BaseEC2NodeDriver(NodeDriver):
                                  Network Adapter for the AMI
         :type       ena_support: ``bool``
 
+        :param      billing_products: The billing product codes
+        :type       billing_products: ''list''
+
         :rtype:     :class:`NodeImage`
         """
 
@@ -4006,6 +4009,10 @@ class BaseEC2NodeDriver(NodeDriver):
         if ena_support is not None:
             params['EnaSupport'] = ena_support
 
+        if billing_products is not None:
+            params.update(self._get_billing_product_params(
+                          billing_products))
+
         image = self._to_image(
             self.connection.request(self.path, params=params).object
         )
@@ -5944,6 +5951,13 @@ class BaseEC2NodeDriver(NodeDriver):
         # Build block device mapping
         block_device_mapping = self._to_device_mappings(element)
 
+        billing_products = []
+        for p in findall(element=element,
+                         xpath="billingProducts/item/billingProduct",
+                         namespace=NAMESPACE):
+
+            billing_products.append(p.text)
+
         # Get our tags
         tags = self._get_resource_tags(element)
 
@@ -5954,7 +5968,7 @@ class BaseEC2NodeDriver(NodeDriver):
         # Add our tags and block device mapping
         extra['tags'] = tags
         extra['block_device_mapping'] = block_device_mapping
-
+        extra['billing_products'] = billing_products
         return NodeImage(id=id, name=name, driver=self, extra=extra)
 
     def _to_volume(self, element, name=None):
@@ -6696,6 +6710,29 @@ class BaseEC2NodeDriver(NodeDriver):
                                % (idx, k, key)] = str(value)
         return params
 
+    def _get_billing_product_params(self, billing_products):
+        """
+        Return a list of dictionaries with valid param for billing product.
+
+        :param      billing_product: List of billing code values(str)
+        :type       billing product: ``list``
+
+        :return:    Dictionary representation of the billing product codes
+        :rtype:     ``dict``
+        """
+
+        if not isinstance(billing_products, (list, tuple)):
+            raise AttributeError(
+                'billing_products not list or tuple')
+
+        params = {}
+
+        for idx, v in enumerate(billing_products):
+            idx += 1  # We want 1-based indexes
+            params['BillingProduct.%d' % (idx)] = str(v)
+
+        return params
+
     def _get_common_security_group_params(self, group_id, protocol,
                                           from_port, to_port, cidr_ips,
                                           group_pairs):

http://git-wip-us.apache.org/repos/asf/libcloud/blob/c68b85e3/libcloud/test/compute/fixtures/ec2/describe_images.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/ec2/describe_images.xml b/libcloud/test/compute/fixtures/ec2/describe_images.xml
index d541a38..167015a 100644
--- a/libcloud/test/compute/fixtures/ec2/describe_images.xml
+++ b/libcloud/test/compute/fixtures/ec2/describe_images.xml
@@ -14,6 +14,11 @@
             <description>Testing Stuff</description>
             <rootDeviceType>ebs</rootDeviceType>
             <rootDeviceName>/dev/sda1</rootDeviceName>
+            <billingProducts>
+                <item>
+                    <billingProduct>ab-5dh78019</billingProduct>
+                </item>
+            </billingProducts>
             <blockDeviceMapping>
                 <item>
                     <deviceName>/dev/sda1</deviceName>
@@ -44,6 +49,11 @@
             <name>Test Image 2</name>
             <rootDeviceType>ebs</rootDeviceType>
             <rootDeviceName>/dev/sda1</rootDeviceName>
+            <billingProducts>
+                <item>
+                    <billingProduct>as-6dr90319</billingProduct>
+                </item>
+            </billingProducts>
             <blockDeviceMapping>
                 <item>
                     <deviceName>/dev/sda1</deviceName>
@@ -59,4 +69,4 @@
             <hypervisor>xen</hypervisor>
         </item>
     </imagesSet>
-</DescribeImagesResponse>
\ No newline at end of file
+</DescribeImagesResponse>

http://git-wip-us.apache.org/repos/asf/libcloud/blob/c68b85e3/libcloud/test/compute/fixtures/ec2/describe_images_ex_imageids.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/ec2/describe_images_ex_imageids.xml b/libcloud/test/compute/fixtures/ec2/describe_images_ex_imageids.xml
index b73b866..f16092d 100644
--- a/libcloud/test/compute/fixtures/ec2/describe_images_ex_imageids.xml
+++ b/libcloud/test/compute/fixtures/ec2/describe_images_ex_imageids.xml
@@ -14,6 +14,11 @@
             <description>Testing Stuff</description>
             <rootDeviceType>ebs</rootDeviceType>
             <rootDeviceName>/dev/sda1</rootDeviceName>
+            <billingProducts>
+                <item>
+                    <billingProduct>ab-5dh78019</billingProduct>
+                </item>
+            </billingProducts>
             <blockDeviceMapping>
                 <item>
                     <deviceName>/dev/sda1</deviceName>
@@ -33,4 +38,4 @@
             <hypervisor>xen</hypervisor>
         </item>
     </imagesSet>
-</DescribeImagesResponse>
\ No newline at end of file
+</DescribeImagesResponse>

http://git-wip-us.apache.org/repos/asf/libcloud/blob/c68b85e3/libcloud/test/compute/test_ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_ec2.py b/libcloud/test/compute/test_ec2.py
index 7702d82..e51cf42 100644
--- a/libcloud/test/compute/test_ec2.py
+++ b/libcloud/test/compute/test_ec2.py
@@ -486,6 +486,8 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin):
         self.assertEqual(len(images[0].extra['block_device_mapping']), 2)
         ephemeral = images[0].extra['block_device_mapping'][1]['virtual_name']
         self.assertEqual(ephemeral, 'ephemeral0')
+        billing_product1 = images[0].extra['billing_products'][0]
+        self.assertEqual(billing_product1, 'ab-5dh78019')
 
         location = '123456788908/Test Image 2'
         self.assertEqual(images[1].id, 'ami-85b2a8ae')
@@ -493,6 +495,8 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin):
         self.assertEqual(images[1].extra['image_location'], location)
         self.assertEqual(images[1].extra['architecture'], 'x86_64')
         size = images[1].extra['block_device_mapping'][0]['ebs']['volume_size']
+        billing_product2 = images[1].extra['billing_products'][0]
+        self.assertEqual(billing_product2, 'as-6dr90319')
         self.assertEqual(size, 20)
 
     def test_list_images_with_image_ids(self):
@@ -513,6 +517,7 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin):
         self.assertEqual(image.name, 'Test Image')
         self.assertEqual(image.extra['architecture'], 'x86_64')
         self.assertEqual(len(image.extra['block_device_mapping']), 2)
+        self.assertEqual(image.extra['billing_products'][0], 'ab-5dh78019')
 
     def test_copy_image(self):
         image = self.driver.list_images()[0]
@@ -559,7 +564,8 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin):
                                               description='My Image',
                                               architecture='x86_64',
                                               block_device_mapping=mapping,
-                                              ena_support=True)
+                                              ena_support=True,
+                                              billing_products=['ab-5dh78019'])
         self.assertEqual(image.id, 'ami-57c2fb3e')
 
     def test_ex_list_availability_zones(self):


Mime
View raw message