libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [01/10] libcloud git commit: Completed network domain functions (get, list, create, edit and delete) with unit tests.
Date Thu, 08 Oct 2015 12:19:19 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk 637ff0353 -> 1a871fba7


Completed network domain functions (get, list, create, edit and delete) with unit tests.

Closes #593


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

Branch: refs/heads/trunk
Commit: 44c4cd6c985ac1938287b197b713e17022562204
Parents: 637ff03
Author: Anthony Shaw <anthony.p.shaw@gmail.com>
Authored: Tue Oct 6 11:01:40 2015 +1100
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Thu Oct 8 14:11:57 2015 +0200

----------------------------------------------------------------------
 libcloud/common/dimensiondata.py                |  7 +-
 libcloud/compute/drivers/dimensiondata.py       | 80 +++++++++++++++++++-
 ...8dabe5a7d0e4_network_deleteNetworkDomain.xml |  8 ++
 ...8dabe5a7d0e4_network_deployNetworkDomain.xml |  8 ++
 ...c_8dabe5a7d0e4_network_editNetworkDomain.xml |  7 ++
 ...ain_8cdfd607_f429_4df6_9352_162cfc0891be.xml |  9 +++
 libcloud/test/compute/test_dimensiondata.py     | 48 ++++++++++++
 7 files changed, 163 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/44c4cd6c/libcloud/common/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/common/dimensiondata.py b/libcloud/common/dimensiondata.py
index 5a023b3..5010fd8 100644
--- a/libcloud/common/dimensiondata.py
+++ b/libcloud/common/dimensiondata.py
@@ -79,6 +79,10 @@ API_ENDPOINTS = {
 # Default API end-point for the base connection class.
 DEFAULT_REGION = 'dd-na'
 
+# Service plans
+class NetworkDomainServicePlan(object):
+    ESSENTIALS = "ESSENTIALS"
+    ADVANCED = "ADVANCED"
 
 class DimensionDataResponse(XmlResponse):
     def parse_error(self):
@@ -282,12 +286,13 @@ class DimensionDataNetworkDomain(object):
     DimensionData network domain with location.
     """
 
-    def __init__(self, id, name, description, location, status):
+    def __init__(self, id, name, description, location, status, plan):
         self.id = str(id)
         self.name = name
         self.description = description
         self.location = location
         self.status = status
+        self.plan = plan
 
     def __repr__(self):
         return (('<DimensionDataNetworkDomain: id=%s, name=%s,'

http://git-wip-us.apache.org/repos/asf/libcloud/blob/44c4cd6c/libcloud/compute/drivers/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/dimensiondata.py b/libcloud/compute/drivers/dimensiondata.py
index e1ce7a8..5774372 100644
--- a/libcloud/compute/drivers/dimensiondata.py
+++ b/libcloud/compute/drivers/dimensiondata.py
@@ -28,6 +28,7 @@ from libcloud.common.dimensiondata import (DimensionDataConnection,
 from libcloud.common.dimensiondata import DimensionDataNetwork
 from libcloud.common.dimensiondata import DimensionDataNetworkDomain
 from libcloud.common.dimensiondata import DimensionDataVlan
+from libcloud.common.dimensiondata import NetworkDomainServicePlan
 from libcloud.common.dimensiondata import API_ENDPOINTS
 from libcloud.common.dimensiondata import DEFAULT_REGION
 from libcloud.common.dimensiondata import TYPES_URN
@@ -388,6 +389,12 @@ class DimensionDataNodeDriver(NodeDriver):
                                       params=params).object
         return self._to_networks(response)
 
+    def ex_get_network_domain(self, network_domain_id):
+        locations = self.list_locations()
+        net = self.connection.request_with_orgId_api_2(
+            'network/networkDomain/%s' % network_domain_id).object
+        return self._to_network_domain(net, locations)
+
     def ex_list_network_domains(self, location=None):
         """
         List networks deployed across all data center locations for your
@@ -405,6 +412,69 @@ class DimensionDataNodeDriver(NodeDriver):
                                       params=params).object
         return self._to_network_domains(response)
 
+    def ex_create_network_domain(self, location, name, description=None,
+                                 service_plan=
+                                 NetworkDomainServicePlan.ADVANCED):
+        """
+        Deploy a new network domain to a data center
+        """
+        create_node = ET.Element('deployNetworkDomain', {'xmlns': TYPES_URN})
+        ET.SubElement(create_node, "datacenterId").text = location.id
+        ET.SubElement(create_node, "name").text = name
+        if description is not None:
+            ET.SubElement(create_node, "description").text = description
+        ET.SubElement(create_node, "type").text = service_plan
+
+        response = self.connection.request_with_orgId_api_2(
+            'network/deployNetworkDomain',
+            method='POST',
+            data=ET.tostring(create_node)).object
+
+        network_domain_id = None
+
+        for info in findall(response, 'info', TYPES_URN):
+            if info.get('name') == 'networkDomainId"':
+                network_domain_id = info.get('value')
+
+        return DimensionDataNetworkDomain(
+            id=network_domain_id,
+            name=name,
+            description=description,
+            location=location,
+            status=NodeState.RUNNING,
+            plan=service_plan
+        )
+
+    def ex_update_network_domain(self, network_domain):
+        """
+        Update the properties of a network domain
+        """
+        edit_node = ET.Element('editNetworkDomain', {'xmlns': TYPES_URN})
+        edit_node.set('id', network_domain.id)
+        ET.SubElement(edit_node, "name").text = network_domain.name
+        if network_domain.description is not None:
+            ET.SubElement(edit_node, "description").text \
+                = network_domain.description
+        ET.SubElement(edit_node, "type").text = network_domain.plan
+
+        response = self.connection.request_with_orgId_api_2(
+            'network/editNetworkDomain',
+            method='POST',
+            data=ET.tostring(edit_node)).object
+
+        return network_domain
+
+    def ex_delete_network_domain(self, network_domain):
+        delete_node = ET.Element('deleteNetworkDomain', {'xmlns': TYPES_URN})
+        delete_node.set('id', network_domain.id)
+        result = self.connection.request_with_orgId_api_2(
+            'network/deleteNetworkDomain',
+            method='POST',
+            data=ET.tostring(delete_node)).object
+
+        responseCode = findtext(result, 'responseCode', TYPES_URN)
+        return responseCode == 'IN_PROGRESS'
+
     def ex_list_vlans(self, location=None, network_domain=None):
         """
         List VLANs available in a given networkDomain
@@ -486,12 +556,16 @@ class DimensionDataNodeDriver(NodeDriver):
         location_id = element.get('datacenterId')
         location = list(filter(lambda x: x.id == location_id,
                                locations))[0]
-
+        plan = findtext(element, 'type', TYPES_URN)
+        if plan is 'ESSENTIALS':
+            plan_type = NetworkDomainServicePlan.ESSENTIALS
+        else:
+            plan_type = NetworkDomainServicePlan.ADVANCED
         return DimensionDataNetworkDomain(
             id=element.get('id'),
             name=findtext(element, 'name', TYPES_URN),
-            description=findtext(element, 'description',
-                                 TYPES_URN),
+            description=findtext(element, 'description', TYPES_URN),
+            plan=plan_type,
             location=location,
             status=status)
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/44c4cd6c/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_deleteNetworkDomain.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_deleteNetworkDomain.xml
b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_deleteNetworkDomain.xml
new file mode 100644
index 0000000..a3cca2e
--- /dev/null
+++ b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_deleteNetworkDomain.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<response
+xmlns="urn:didata.com:api:cloud:types" requestId="NA9/2015-02-24T10:19:41.471-05:00/27083502-a2ea-4331-b0cb-c2a11bb044b0">
+<operation>DELETE_NETWORK_DOMAIN</operation>
+<responseCode>IN_PROGRESS</responseCode>
+<message>Request to Delete Network Domain (Id: 8cdfd607-f429-4df6-9352-
+162cfc0891be) has been accepted and is being processed</message>
+</response>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/44c4cd6c/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_deployNetworkDomain.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_deployNetworkDomain.xml
b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_deployNetworkDomain.xml
new file mode 100644
index 0000000..4269840
--- /dev/null
+++ b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_deployNetworkDomain.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<response requestId="na/2015-01-14T13:37:20/62f06368-c3fb-11e3-b29c-001517c4643e" xmlns="urn:didata.com:api:cloud:types">
+<operation>DEPLOY_NETWORK_DOMAIN</operation>
+<responseCode>IN_PROGRESS</responseCode>
+<message>Request to Deploy Network Domain 'A Network Domain' has been
+accepted and is being processed</message>
+<info name="networkDomainId" value="f14a871f-9a25-470c-aef8-51e13202e1aa"/>
+</response>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/44c4cd6c/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_editNetworkDomain.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_editNetworkDomain.xml
b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_editNetworkDomain.xml
new file mode 100644
index 0000000..07d55e5
--- /dev/null
+++ b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_editNetworkDomain.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<response xmlns="urn:didata.com:api:cloud:types" requestId="NA9/2015-02-24T09:05:41.790-05:00/b24cbc7d-0648-4070-889f-7ab97bf21941">
+<operation>EDIT_NETWORK_DOMAIN</operation>
+<responseCode>OK</responseCode>
+<message>Network Domain 'Development Network Domain' was edited
+successfully.</message>
+</response>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/44c4cd6c/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_networkDomain_8cdfd607_f429_4df6_9352_162cfc0891be.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_networkDomain_8cdfd607_f429_4df6_9352_162cfc0891be.xml
b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_networkDomain_8cdfd607_f429_4df6_9352_162cfc0891be.xml
new file mode 100644
index 0000000..bdd1c6b
--- /dev/null
+++ b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_networkDomain_8cdfd607_f429_4df6_9352_162cfc0891be.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<networkDomain xmlns="urn:didata.com:api:cloud:types" id="8cdfd607-f429-4df6-9352-162cfc0891be"
datacenterId="NA12">
+    <name>test</name>
+    <description>test2</description>
+    <type>ESSENTIALS</type>
+    <snatIpv4Address>168.128.26.20</snatIpv4Address>
+    <createTime>2015-07-15T03:36:00.000Z</createTime>
+    <state>NORMAL</state>
+</networkDomain>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/44c4cd6c/libcloud/test/compute/test_dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_dimensiondata.py b/libcloud/test/compute/test_dimensiondata.py
index b5d481d..8ec4d13 100644
--- a/libcloud/test/compute/test_dimensiondata.py
+++ b/libcloud/test/compute/test_dimensiondata.py
@@ -201,6 +201,34 @@ class DimensionDataTests(unittest.TestCase, TestCaseMixin):
         self.assertEqual(nets[0].name, 'test-net1')
         self.assertTrue(isinstance(nets[0].location, NodeLocation))
 
+    def test_create_network_domain(self):
+        location = self.driver.ex_get_location_by_id('NA9')
+        net = self.driver.ex_create_network_domain(location=location,
+                                                   name='test',
+                                                   description='test')
+        self.assertEqual(net.name, 'test')
+        self.assertTrue(net.id, 'f14a871f-9a25-470c-aef8-51e13202e1aa')
+
+    def test_get_network_domain(self):
+        location = self.driver.ex_get_location_by_id('NA9')
+        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
+        self.assertEqual(net.id, '8cdfd607-f429-4df6-9352-162cfc0891be')
+        self.assertEqual(net.description, 'test2')
+        self.assertEqual(net.name, 'test')
+
+    def test_update_network_domain(self):
+        location = self.driver.ex_get_location_by_id('NA9')
+        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
+        net.name = 'new name'
+        net2 = self.driver.ex_update_network_domain(net)
+        self.assertEqual(net2.name, 'new name')
+
+    def test_delete_network_domain(self):
+        location = self.driver.ex_get_location_by_id('NA9')
+        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
+        result = self.driver.ex_delete_network_domain(net)
+        self.assertTrue(result)
+
     def test_ex_list_networks(self):
         nets = self.driver.ex_list_networks()
         self.assertEqual(nets[0].name, 'test-net1')
@@ -398,5 +426,25 @@ class DimensionDataMockHttp(MockHttp):
             'caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server_e75ead52_692f_4314_8725_c8a4f4d13a87.xml')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
+    def _caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_deployNetworkDomain(self,
method, url, body, headers):
+        body = self.fixtures.load(
+            'caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_deployNetworkDomain.xml')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_networkDomain_8cdfd607_f429_4df6_9352_162cfc0891be(self,
method, url, body, headers):
+        body = self.fixtures.load(
+            'caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_networkDomain_8cdfd607_f429_4df6_9352_162cfc0891be.xml')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_editNetworkDomain(self, method,
url, body, headers):
+        body = self.fixtures.load(
+            'caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_editNetworkDomain.xml')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_deleteNetworkDomain(self,
method, url, body, headers):
+        body = self.fixtures.load(
+            'caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_deleteNetworkDomain.xml')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
 if __name__ == '__main__':
     sys.exit(unittest.main())


Mime
View raw message