Get customer images and tests

Signed-off-by: Anthony Shaw <anthony.p.s...@gmail.com>


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

Branch: refs/heads/trunk
Commit: a543be04859640035d922e95a03347c73c39cfa0
Parents: 7235ccf
Author: Anthony Shaw <anthony.p.s...@gmail.com>
Authored: Tue Dec 8 20:57:15 2015 +1100
Committer: Anthony Shaw <anthony.p.s...@gmail.com>
Committed: Wed Dec 9 21:19:13 2015 +1100

----------------------------------------------------------------------
 libcloud/compute/drivers/dimensiondata.py       | 90 ++++++++++++--------
 ...8a_9cbc_8dabe5a7d0e4_image_customerImage.xml | 50 +++++++++++
 libcloud/test/compute/test_dimensiondata.py     | 14 +++
 3 files changed, 118 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/a543be04/libcloud/compute/drivers/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/dimensiondata.py 
b/libcloud/compute/drivers/dimensiondata.py
index 464e8f4..1221f71 100644
--- a/libcloud/compute/drivers/dimensiondata.py
+++ b/libcloud/compute/drivers/dimensiondata.py
@@ -301,42 +301,6 @@ class DimensionDataNodeDriver(NodeDriver):
             .request_with_orgId_api_1('networkWithLocation%s' % url_ext)
             .object)
 
-    def _to_base_images(self, object):
-        images = []
-        locations = self.list_locations()
-
-        for element in object.findall(fixxpath("osImage", TYPES_URN)):
-            images.append(self._to_base_image(element, locations))
-
-        return images
-
-    def _to_base_image(self, element, locations):
-        # Eventually we will probably need multiple _to_image() functions
-        # that parse <ServerImage> differently than <DeployedImage>.
-        # DeployedImages are customer snapshot images, and ServerImages are
-        # 'base' images provided by DimensionData
-        location_id = element.get('datacenterId')
-        location = list(filter(lambda x: x.id == location_id,
-                               locations))[0]
-        cpu_spec = self._to_cpu_spec(element.find(fixxpath('cpu', TYPES_URN)))
-
-        extra = {
-            'description': findtext(element, 'description', TYPES_URN),
-            'OS_type': findtext(element, 'operatingSystem/type', TYPES_URN),
-            'OS_displayName': findtext(element, 'operatingSystem/displayName',
-                                       TYPES_URN),
-            'cpu': cpu_spec,
-            'memoryGb': findtext(element, 'memoryGb', TYPES_URN),
-            'osImageKey': findtext(element, 'osImageKey', TYPES_URN),
-            'created': findtext(element, 'createTime', TYPES_URN),
-            'location': location,
-        }
-
-        return NodeImage(id=element.get('id'),
-                         name=str(findtext(element, 'name', TYPES_URN)),
-                         extra=extra,
-                         driver=self.connection.driver)
-
     def ex_start_node(self, node):
         """
         Powers on an existing deployed server
@@ -1371,6 +1335,60 @@ class DimensionDataNodeDriver(NodeDriver):
         response_code = findtext(result, 'result', GENERAL_NS)
         return response_code in ['IN_PROGRESS', 'SUCCESS']
 
+    def ex_list_customer_images(self, location=None):
+        """
+        Return a list of customer imported images
+
+        :param location: The target location
+        :type  location: :class:`NodeLocation`
+
+        :rtype: ``list`` of :class:`NodeImage`
+        """
+        params = {}
+        if location is not None:
+            params['datacenterId'] = location.id
+
+        return self._to_base_images(
+            self.connection.request_with_orgId_api_2(
+                'image/customerImage',
+                params=params)
+            .object, 'customerImage')
+
+    def _to_base_images(self, object, el_name='osImage'):
+        images = []
+        locations = self.list_locations()
+
+        for element in object.findall(fixxpath(el_name, TYPES_URN)):
+            images.append(self._to_base_image(element, locations))
+
+        return images
+
+    def _to_base_image(self, element, locations):
+        # Eventually we will probably need multiple _to_image() functions
+        # that parse <ServerImage> differently than <DeployedImage>.
+        # DeployedImages are customer snapshot images, and ServerImages are
+        # 'base' images provided by DimensionData
+        location_id = element.get('datacenterId')
+        location = list(filter(lambda x: x.id == location_id,
+                               locations))[0]
+        cpu_spec = self._to_cpu_spec(element.find(fixxpath('cpu', TYPES_URN)))
+        os_el = element.find(fixxpath('operatingSystem', TYPES_URN))
+        extra = {
+            'description': findtext(element, 'description', TYPES_URN),
+            'OS_type': os_el.get('type'),
+            'OS_displayName': os_el.get('displayName'),
+            'cpu': cpu_spec,
+            'memoryGb': findtext(element, 'memoryGb', TYPES_URN),
+            'osImageKey': findtext(element, 'osImageKey', TYPES_URN),
+            'created': findtext(element, 'createTime', TYPES_URN),
+            'location': location,
+        }
+
+        return NodeImage(id=element.get('id'),
+                         name=str(findtext(element, 'name', TYPES_URN)),
+                         extra=extra,
+                         driver=self.connection.driver)
+
     def _to_nat_rules(self, object, network_domain):
         rules = []
         for element in findall(object, 'natRule', TYPES_URN):

http://git-wip-us.apache.org/repos/asf/libcloud/blob/a543be04/libcloud/test/compute/fixtures/dimensiondata/caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_image_customerImage.xml
----------------------------------------------------------------------
diff --git 
a/libcloud/test/compute/fixtures/dimensiondata/caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_image_customerImage.xml
 
b/libcloud/test/compute/fixtures/dimensiondata/caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_image_customerImage.xml
new file mode 100644
index 0000000..4e59e18
--- /dev/null
+++ 
b/libcloud/test/compute/fixtures/dimensiondata/caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_image_customerImage.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes"?>
+<customerImages xmlns="urn:didata.com:api:cloud:types" pageNumber="1" 
pageCount="35" totalCount="35" pageSize="250">
+    <customerImage id="5234e5c7-01de-4411-8b6e-baeb8d91cf5d" 
datacenterId="NA9">
+        <name>ImportedCustomerImage</name>
+        <description />
+        <operatingSystem id="REDHAT664" displayName="REDHAT6/64" family="UNIX" 
/>
+        <cpu count="4" speed="STANDARD" coresPerSocket="1" />
+        <memoryGb>2</memoryGb>
+        <disk id="1a82316f-23ed-4fe9-b6d8-6b92ac467423" scsiId="0" sizeGb="12" 
speed="STANDARD" />
+        <createTime>2015-11-19T14:29:02.000Z</createTime>
+        <source type="IMPORT">
+        <artifact type="MF" value="ImportedCustomerImage.mf" 
date="2015-1119T14:28:54.000Z" />
+        <artifact type="OVF" value="ImportedCustomerImage.ovf" 
date="2015-1119T14:28:05.000Z" />
+        <artifact type="VMDK" value="ImportedCustomerImage-disk1.vmdk" 
date="2015-11-19T12:22:31.000Z" /></source>
+        <state>NORMAL</state>
+        <vmwareTools versionStatus="NEED_UPGRADE" runningStatus="NOT_RUNNING" 
apiVersion="8389" />
+        <virtualHardware version="vmx-10" upToDate="true" />
+    </customerImage>
+    <customerImage id="2ffa36c8-1848-49eb-b4fa-9d908775f68c" 
datacenterId="NA9">
+        <name>CustomerImageWithPricedSoftwareLabels</name>
+        <description />
+        <operatingSystem id="WIN2008S32" displayName="WIN2008S/32" 
family="WINDOWS" />
+        <cpu count="1" speed="STANDARD" coresPerSocket="1" />
+        <memoryGb>1</memoryGb>
+        <disk id="29455efc-51af-4b4d-91b3-d81ca0dff7d8" scsiId="0" sizeGb="50" 
speed="STANDARD" />
+        <softwareLabel>MSSQL2008R2S</softwareLabel>
+        <createTime>2015-11-03T15:25:34.000Z</createTime>
+        <source type="CLONE">
+            <artifact type="SERVER_ID" 
value="7c9c2551-269d-4274-a247126ba7c6215c" />
+        </source>
+        <state>NORMAL</state>
+        <vmwareTools versionStatus="CURRENT" runningStatus="NOT_RUNNING" />
+        <virtualHardware version="vmx-08" upToDate="false" />
+    </customerImage>
+    <customerImage id="1fc1844f-45d6-4364-b447-f7c7645b47de" 
datacenterId="NA9">
+        <name>CopiedCustomerImage</name>
+        <description />
+        <operatingSystem id="REDHAT664" displayName="REDHAT6/64" family="UNIX" 
/>
+        <cpu count="1" speed="STANDARD" coresPerSocket="1" />
+        <memoryGb>2</memoryGb>
+        <disk id="42b20819-c161-4dec-aa94-73ec370a6e37" scsiId="0" sizeGb="10" 
speed="STANDARD" />
+        <createTime>2015-11-11T17:17:00.000Z</createTime>
+        <source type="COPY">
+            <artifact type="IMAGE_ID" 
value="0b8357b6-f156-4b27-b4fd-b81d09c15efc" />
+        </source>
+        <state>NORMAL</state>
+        <vmwareTools versionStatus="NEED_UPGRADE" runningStatus="NOT_RUNNING" 
apiVersion="9355" />
+        <virtualHardware version="vmx-10" upToDate="true" />
+    </customerImage>
+</customerImages>

http://git-wip-us.apache.org/repos/asf/libcloud/blob/a543be04/libcloud/test/compute/test_dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_dimensiondata.py 
b/libcloud/test/compute/test_dimensiondata.py
index 49fdc82..f8f3f44 100644
--- a/libcloud/test/compute/test_dimensiondata.py
+++ b/libcloud/test/compute/test_dimensiondata.py
@@ -120,6 +120,15 @@ class DimensionDataTests(unittest.TestCase, TestCaseMixin):
         self.assertEqual(images[0].extra['cpu'].cpu_count, 2)
         self.assertEqual(images[0].extra['OS_displayName'], 'REDHAT6/64')
 
+    def test_ex_list_customer_images(self):
+        images = self.driver.ex_list_customer_images()
+        self.assertEqual(len(images), 3)
+        self.assertEqual(images[0].name, 'ImportedCustomerImage')
+        self.assertEqual(images[0].id, '5234e5c7-01de-4411-8b6e-baeb8d91cf5d')
+        self.assertEqual(images[0].extra['location'].id, 'NA9')
+        self.assertEqual(images[0].extra['cpu'].cpu_count, 4)
+        self.assertEqual(images[0].extra['OS_displayName'], 'REDHAT6/64')
+
     def test_create_node_response(self):
         rootPw = NodeAuthPassword('pass123')
         image = self.driver.list_images()[0]
@@ -933,5 +942,10 @@ class DimensionDataMockHttp(MockHttp):
             'caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_image_osImage.xml')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
+    def 
_caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_image_customerImage(self, 
method, url, body, headers):
+        body = self.fixtures.load(
+            
'caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_image_customerImage.xml')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
 if __name__ == '__main__':
     sys.exit(unittest.main())

Reply via email to