libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject libcloud git commit: DimensionData: Adding in ex_location filter and paginated queries to list_nodes Closes #690
Date Sat, 06 Feb 2016 02:07:23 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk 663f507d7 -> 4864e14e8


DimensionData: Adding in ex_location filter and paginated queries to list_nodes
Closes #690


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

Branch: refs/heads/trunk
Commit: 4864e14e843a456fadbfd0bbf60555456e133445
Parents: 663f507
Author: Jeffrey Dunham <jeffrey.a.dunham@gmail.com>
Authored: Fri Feb 5 20:03:30 2016 -0500
Committer: anthony-shaw <anthony.p.shaw@gmail.com>
Committed: Sat Feb 6 13:06:51 2016 +1100

----------------------------------------------------------------------
 libcloud/compute/drivers/dimensiondata.py       | 45 +++++++++++++++---
 ...4d8a_9cbc_8dabe5a7d0e4_server_server_NA3.xml | 50 ++++++++++++++++++++
 ...cbc_8dabe5a7d0e4_server_server_paginated.xml | 50 ++++++++++++++++++++
 libcloud/test/compute/test_dimensiondata.py     | 46 ++++++++++++++++--
 4 files changed, 181 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/4864e14e/libcloud/compute/drivers/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/dimensiondata.py b/libcloud/compute/drivers/dimensiondata.py
index 3a9bd02..08fba95 100644
--- a/libcloud/compute/drivers/dimensiondata.py
+++ b/libcloud/compute/drivers/dimensiondata.py
@@ -242,18 +242,22 @@ class DimensionDataNodeDriver(NodeDriver):
         response_code = findtext(body, 'responseCode', TYPES_URN)
         return response_code in ['IN_PROGRESS', 'OK']
 
-    def list_nodes(self):
+    def list_nodes(self, ex_location=None):
         """
-        List nodes deployed across all data center locations for your
-        organization.
+        List nodes deployed for your organization.
+
+        :keyword ex_location: The location filter
+        :type    location: :class:`NodeLocation` or ``str``
 
         :return: a list of `Node` objects
         :rtype: ``list`` of :class:`Node`
         """
-        nodes = self._to_nodes(
-            self.connection.request_with_orgId_api_2('server/server').object)
 
-        return nodes
+        node_list = []
+        for nodes in self.ex_list_nodes_paginated(location=ex_location):
+            node_list.extend(nodes)
+
+        return node_list
 
     def list_images(self, location=None):
         """
@@ -323,6 +327,31 @@ class DimensionDataNodeDriver(NodeDriver):
             .request_with_orgId_api_1('networkWithLocation%s' % url_ext)
             .object)
 
+    def ex_list_nodes_paginated(self, location=None):
+        """
+        Return a generator which yields node lists in pages
+
+        :keyword ex_location: The location filter
+        :type    location: :class:`NodeLocation` or ``str``
+
+        :return: a list of `Node` objects
+        :rtype: ``generator`` of `list` of :class:`Node`
+        """
+
+        params = {}
+        if location is not None:
+            if isinstance(location, NodeLocation):
+                params['datacenterId'] = location.id
+            else:
+                params['datacenterId'] = location
+
+        nodes_obj = self._list_nodes_single_page(params)
+        yield self._to_nodes(nodes_obj)
+        while nodes_obj.get('pageCount') >= nodes_obj.get('pageSize'):
+            params['pageNumber'] = int(nodes_obj.get('pageNumber')) + 1
+            nodes_obj = self._list_nodes_single_page(params)
+            yield self._to_nodes(nodes_obj)
+
     def ex_start_node(self, node):
         """
         Powers on an existing deployed server
@@ -1414,6 +1443,10 @@ class DimensionDataNodeDriver(NodeDriver):
                 params=params)
             .object, 'customerImage')
 
+    def _list_nodes_single_page(self, params={}):
+        return self.connection.request_with_orgId_api_2(
+            'server/server', params=params).object
+
     def _to_base_images(self, object, el_name='osImage'):
         images = []
         locations = self.list_locations()

http://git-wip-us.apache.org/repos/asf/libcloud/blob/4864e14e/libcloud/test/compute/fixtures/dimensiondata/caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server_NA3.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/dimensiondata/caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server_NA3.xml
b/libcloud/test/compute/fixtures/dimensiondata/caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server_NA3.xml
new file mode 100644
index 0000000..80b6273
--- /dev/null
+++ b/libcloud/test/compute/fixtures/dimensiondata/caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server_NA3.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes"?>
+<servers xmlns="urn:didata.com:api:cloud:types" pageNumber="1" pageCount="2" totalCount="2"
pageSize="250">
+    <!-- MCP 1.0 Server -->
+    <server id="e75ead52-692f-4314-8725-c8a4f4d13a87" datacenterId="NA3">
+        <name>Production Web Server MCP 1</name>
+        <description>nopassword0</description>
+        <operatingSystem id="REDHAT632" displayName="REDHAT6/32" family="UNIX" />
+        <cpu count="4" speed="STANDARD" coresPerSocket="1" />
+        <memoryGb>2</memoryGb>
+        <disk id="74f81c56-96cc-4cca-b4d7-a88f641a6ea2" scsiId="0" sizeGb="10" speed="STANDARD"
state="NORMAL" />
+        <nic id="43b24e9e-c1c9-4d53-965b-89bcaa725103" privateIpv4="10.160.117.25" networkId="c550be0e-65c1-11e4-811f-005056806999"
networkName="Test1" state="NORMAL" />
+        <backup assetId="5579f3a7-4c32-4cf5-8a7e-b45c36a35c10" servicePlan="Enterprise"
state="NORMAL" />
+        <monitoring monitoringId="11049" servicePlan="ESSENTIALS" state="NORMAL" />
+        <sourceImageId>e9ec6eb4-4634-49de-b914-01eb74da5fb9</sourceImageId>
+        <createTime>2015-08-11T16:51:05.000Z</createTime>
+        <deployed>true</deployed>
+        <started>true</started>
+        <state>NORMAL</state>
+        <vmwareTools versionStatus="NEED_UPGRADE" runningStatus="RUNNING" apiVersion="8389"
/>
+        <virtualHardware version="vmx-08" upToDate="false" />
+    </server>
+    <!-- MCP 2.0 Server -->
+    <server id="5a32d6e4-9707-4813-a269-56ab4d989f4d" datacenterId="NA3">
+        <name>Production Web Server MCP 2</name>
+        <description>Server to host our main web application.</description>
+        <operatingSystem id="WIN2008S32" displayName="WIN2008S/32" family="WINDOWS" />
+        <cpu count="2" speed="STANDARD" coresPerSocket="1" />
+        <memoryGb>4</memoryGb>
+        <disk id="c2e1f199-116e-4dbc-9960-68720b832b0a" scsiId="0" sizeGb="50" speed="STANDARD"
state="NORMAL" />
+        <networkInfo networkDomainId="553f26b6-2a73-42c3-a78b-6116f11291d0">
+            <primaryNic id="5e869800-df7b-4626-bcbf-8643b8be11fd" privateIpv4="10.0.4.8"
ipv6="2607:f480:1111:1282:2960:fb72:7154:6160" vlanId="bc529e20-dc6f-42ba-be20-0ffe44d1993f"
vlanName="Production VLAN" state="NORMAL" />
+        </networkInfo>
+        <backup assetId="91002e08-8dc1-47a1-ad33-04f501c06f87" servicePlan="Advanced"
state="NORMAL" />
+        <monitoring monitoringId="11039" servicePlan="ESSENTIALS" state="NORMAL" />
+        <softwareLabel>MSSQL2008R2S</softwareLabel>
+        <sourceImageId>3ebf3c0f-90fe-4a8b-8585-6e65b316592c</sourceImageId>
+        <createTime>2015-12-02T10:31:33.000Z</createTime>
+        <deployed>true</deployed>
+        <started>true</started>
+        <state>PENDING_CHANGE</state>
+        <progress>
+            <action>SHUTDOWN_SERVER</action>
+            <requestTime>2015-12-02T11:07:40.000Z</requestTime>
+            <userName>devuser1</userName>
+        </progress>
+        <vmwareTools versionStatus="CURRENT" runningStatus="RUNNING" apiVersion="9354"
/>
+        <virtualHardware version="vmx-08" upToDate="false" />
+    </server>
+</servers>
+

http://git-wip-us.apache.org/repos/asf/libcloud/blob/4864e14e/libcloud/test/compute/fixtures/dimensiondata/caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server_paginated.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/dimensiondata/caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server_paginated.xml
b/libcloud/test/compute/fixtures/dimensiondata/caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server_paginated.xml
new file mode 100644
index 0000000..027c9c0
--- /dev/null
+++ b/libcloud/test/compute/fixtures/dimensiondata/caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server_paginated.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes"?>
+<servers xmlns="urn:didata.com:api:cloud:types" pageNumber="1" pageCount="2" totalCount="2"
pageSize="2">
+    <!-- MCP 1.0 Server -->
+    <server id="e75ead52-692f-4314-8725-c8a4f4d13a87" datacenterId="NA1">
+        <name>Production Web Server MCP 1</name>
+        <description>nopassword0</description>
+        <operatingSystem id="REDHAT632" displayName="REDHAT6/32" family="UNIX" />
+        <cpu count="4" speed="STANDARD" coresPerSocket="1" />
+        <memoryGb>2</memoryGb>
+        <disk id="74f81c56-96cc-4cca-b4d7-a88f641a6ea2" scsiId="0" sizeGb="10" speed="STANDARD"
state="NORMAL" />
+        <nic id="43b24e9e-c1c9-4d53-965b-89bcaa725103" privateIpv4="10.160.117.25" networkId="c550be0e-65c1-11e4-811f-005056806999"
networkName="Test1" state="NORMAL" />
+        <backup assetId="5579f3a7-4c32-4cf5-8a7e-b45c36a35c10" servicePlan="Enterprise"
state="NORMAL" />
+        <monitoring monitoringId="11049" servicePlan="ESSENTIALS" state="NORMAL" />
+        <sourceImageId>e9ec6eb4-4634-49de-b914-01eb74da5fb9</sourceImageId>
+        <createTime>2015-08-11T16:51:05.000Z</createTime>
+        <deployed>true</deployed>
+        <started>true</started>
+        <state>NORMAL</state>
+        <vmwareTools versionStatus="NEED_UPGRADE" runningStatus="RUNNING" apiVersion="8389"
/>
+        <virtualHardware version="vmx-08" upToDate="false" />
+    </server>
+    <!-- MCP 2.0 Server -->
+    <server id="5a32d6e4-9707-4813-a269-56ab4d989f4d" datacenterId="NA9">
+        <name>Production Web Server MCP 2</name>
+        <description>Server to host our main web application.</description>
+        <operatingSystem id="WIN2008S32" displayName="WIN2008S/32" family="WINDOWS" />
+        <cpu count="2" speed="STANDARD" coresPerSocket="1" />
+        <memoryGb>4</memoryGb>
+        <disk id="c2e1f199-116e-4dbc-9960-68720b832b0a" scsiId="0" sizeGb="50" speed="STANDARD"
state="NORMAL" />
+        <networkInfo networkDomainId="553f26b6-2a73-42c3-a78b-6116f11291d0">
+            <primaryNic id="5e869800-df7b-4626-bcbf-8643b8be11fd" privateIpv4="10.0.4.8"
ipv6="2607:f480:1111:1282:2960:fb72:7154:6160" vlanId="bc529e20-dc6f-42ba-be20-0ffe44d1993f"
vlanName="Production VLAN" state="NORMAL" />
+        </networkInfo>
+        <backup assetId="91002e08-8dc1-47a1-ad33-04f501c06f87" servicePlan="Advanced"
state="NORMAL" />
+        <monitoring monitoringId="11039" servicePlan="ESSENTIALS" state="NORMAL" />
+        <softwareLabel>MSSQL2008R2S</softwareLabel>
+        <sourceImageId>3ebf3c0f-90fe-4a8b-8585-6e65b316592c</sourceImageId>
+        <createTime>2015-12-02T10:31:33.000Z</createTime>
+        <deployed>true</deployed>
+        <started>true</started>
+        <state>PENDING_CHANGE</state>
+        <progress>
+            <action>SHUTDOWN_SERVER</action>
+            <requestTime>2015-12-02T11:07:40.000Z</requestTime>
+            <userName>devuser1</userName>
+        </progress>
+        <vmwareTools versionStatus="CURRENT" runningStatus="RUNNING" apiVersion="9354"
/>
+        <virtualHardware version="vmx-08" upToDate="false" />
+    </server>
+</servers>
+

http://git-wip-us.apache.org/repos/asf/libcloud/blob/4864e14e/libcloud/test/compute/test_dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_dimensiondata.py b/libcloud/test/compute/test_dimensiondata.py
index efe8a25..557b3ac 100644
--- a/libcloud/test/compute/test_dimensiondata.py
+++ b/libcloud/test/compute/test_dimensiondata.py
@@ -53,16 +53,35 @@ class DimensionDataTests(unittest.TestCase, TestCaseMixin):
         DimensionDataMockHttp.type = None
         ret = self.driver.list_locations()
         self.assertEqual(len(ret), 5)
-        first_node = ret[0]
-        self.assertEqual(first_node.id, 'NA3')
-        self.assertEqual(first_node.name, 'US - West')
-        self.assertEqual(first_node.country, 'US')
+        first_loc = ret[0]
+        self.assertEqual(first_loc.id, 'NA3')
+        self.assertEqual(first_loc.name, 'US - West')
+        self.assertEqual(first_loc.country, 'US')
 
     def test_list_nodes_response(self):
         DimensionDataMockHttp.type = None
         ret = self.driver.list_nodes()
         self.assertEqual(len(ret), 2)
 
+    def test_list_nodes_response_PAGINATED(self):
+        DimensionDataMockHttp.type = 'PAGINATED'
+        ret = self.driver.list_nodes()
+        self.assertEqual(len(ret), 4)
+
+    def test_list_nodes_response_LOCATION(self):
+        DimensionDataMockHttp.type = None
+        ret = self.driver.list_locations()
+        first_loc = ret[0]
+        ret = self.driver.list_nodes(ex_location=first_loc)
+        for node in ret:
+            self.assertEqual(node.extra['datacenterId'], 'NA3')
+
+    def test_list_nodes_response_LOCATION_STR(self):
+        DimensionDataMockHttp.type = None
+        ret = self.driver.list_nodes(ex_location='NA3')
+        for node in ret:
+            self.assertEqual(node.extra['datacenterId'], 'NA3')
+
     def test_list_sizes_response(self):
         DimensionDataMockHttp.type = None
         ret = self.driver.list_sizes()
@@ -481,6 +500,10 @@ class DimensionDataMockHttp(MockHttp):
         body = self.fixtures.load('oec_0_9_myaccount.xml')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
+    def _oec_0_9_myaccount_PAGINATED(self, method, url, body, headers):
+        body = self.fixtures.load('oec_0_9_myaccount.xml')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
     def _oec_0_9_base_image(self, method, url, body, headers):
         body = self.fixtures.load('oec_0_9_base_image.xml')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
@@ -633,10 +656,25 @@ class DimensionDataMockHttp(MockHttp):
         return (httplib.BAD_REQUEST, body, {}, httplib.responses[httplib.OK])
 
     def _caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server(self, method, url, body,
headers):
+        if url.endswith('datacenterId=NA3'):
+            body = self.fixtures.load(
+                'caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server_NA3.xml')
+            return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
         body = self.fixtures.load(
             'caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server.xml')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
+    def _caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server_PAGINATED(self, method,
url, body, headers):
+        if url.endswith('pageNumber=2'):
+            body = self.fixtures.load(
+                'caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server.xml')
+            return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+        else:
+            body = self.fixtures.load(
+                'caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server_paginated.xml')
+            return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
     def _caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_infrastructure_datacenter(self, method,
url, body, headers):
         body = self.fixtures.load(
             'caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_infrastructure_datacenter.xml')


Mime
View raw message