libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [02/10] libcloud git commit: Added functionality for VLANs, create, edit, deploy, get and expand
Date Thu, 08 Oct 2015 12:19:20 GMT
Added functionality for VLANs, create, edit, deploy, get and expand

Closes #593


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

Branch: refs/heads/trunk
Commit: f3e7d51f423c3c1bfa678fb0bd105339917c6384
Parents: 44c4cd6
Author: Anthony Shaw <anthony.p.shaw@gmail.com>
Authored: Tue Oct 6 11:42:00 2015 +1100
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Thu Oct 8 14:12:02 2015 +0200

----------------------------------------------------------------------
 libcloud/common/dimensiondata.py                |   7 +-
 libcloud/compute/drivers/dimensiondata.py       | 101 +++++++++++++++++++
 ...d8a_9cbc_8dabe5a7d0e4_network_deleteVlan.xml |   8 ++
 ...d8a_9cbc_8dabe5a7d0e4_network_deployVlan.xml |   9 ++
 ..._4d8a_9cbc_8dabe5a7d0e4_network_editVlan.xml |   7 ++
 ...d8a_9cbc_8dabe5a7d0e4_network_expandVlan.xml |   8 ++
 ...lan_0e56433f_d808_4669_821d_812769517ff8.xml |  14 +++
 libcloud/test/compute/test_dimensiondata.py     |  70 +++++++++++--
 8 files changed, 215 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/f3e7d51f/libcloud/common/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/common/dimensiondata.py b/libcloud/common/dimensiondata.py
index 5010fd8..722ea5d 100644
--- a/libcloud/common/dimensiondata.py
+++ b/libcloud/common/dimensiondata.py
@@ -306,15 +306,18 @@ class DimensionDataVlan(object):
     DimensionData VLAN.
     """
 
-    def __init__(self, id, name, description, location, status):
+    def __init__(self, id, name, description, location, status,
+                 private_ipv4_range_address, private_ipv4_range_size):
         self.id = str(id)
         self.name = name
         self.location = location
         self.description = description
         self.status = status
+        self.private_ipv4_range_address = private_ipv4_range_address
+        self.private_ipv4_range_size = private_ipv4_range_size
 
     def __repr__(self):
-        return (('<DimensionDataNetworkDomain: id=%s, name=%s, '
+        return (('<DimensionDataVlan: id=%s, name=%s, '
                  'description=%s, location=%s, status=%s>')
                 % (self.id, self.name, self.description,
                    self.location, self.status))

http://git-wip-us.apache.org/repos/asf/libcloud/blob/f3e7d51f/libcloud/compute/drivers/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/dimensiondata.py b/libcloud/compute/drivers/dimensiondata.py
index 5774372..be22fb7 100644
--- a/libcloud/compute/drivers/dimensiondata.py
+++ b/libcloud/compute/drivers/dimensiondata.py
@@ -475,6 +475,101 @@ class DimensionDataNodeDriver(NodeDriver):
         responseCode = findtext(result, 'responseCode', TYPES_URN)
         return responseCode == 'IN_PROGRESS'
 
+    def ex_create_vlan(self,
+                       network_domain,
+                       name,
+                       private_ipv4_base_address,
+                       description=None,
+                       private_ipv4_prefix_size='24'):
+        """
+        Deploy a new VLAN to a network domain
+        """
+        create_node = ET.Element('deployVlan', {'xmlns': TYPES_URN})
+        ET.SubElement(create_node, "networkDomainId").text = network_domain.id
+        ET.SubElement(create_node, "name").text = name
+        if description is not None:
+            ET.SubElement(create_node, "description").text = description
+        ET.SubElement(create_node, "privateIpv4BaseAddress").text = \
+            private_ipv4_base_address
+        ET.SubElement(create_node, "privateIpv4PrefixSize").text = \
+            private_ipv4_prefix_size
+
+        response = self.connection.request_with_orgId_api_2(
+            'network/deployVlan',
+            method='POST',
+            data=ET.tostring(create_node)).object
+
+        vlan_id = None
+
+        for info in findall(response, 'info', TYPES_URN):
+            if info.get('name') == 'vlanId':
+                vlan_id = info.get('value')
+
+        return DimensionDataVlan(
+            id=vlan_id,
+            name=name,
+            description=description,
+            location=network_domain.location,
+            status=NodeState.RUNNING,
+            private_ipv4_range_address=private_ipv4_base_address,
+            private_ipv4_range_size=private_ipv4_prefix_size
+        )
+
+    def ex_get_vlan(self, vlan_id):
+        locations = self.list_locations()
+        vlan = self.connection.request_with_orgId_api_2(
+            'network/vlan/%s' % vlan_id).object
+        return self._to_vlan(vlan, locations)
+
+    def ex_update_vlan(self, vlan):
+        """
+        Updates the properties of the given VLAN
+        Only name and description are updated
+        """
+        edit_node = ET.Element('editVlan', {'xmlns': TYPES_URN})
+        edit_node.set('id', vlan.id)
+        ET.SubElement(edit_node, "name").text = vlan.name
+        if vlan.description is not None:
+            ET.SubElement(edit_node, "description").text \
+                = vlan.description
+
+        response = self.connection.request_with_orgId_api_2(
+            'network/editVlan',
+            method='POST',
+            data=ET.tostring(edit_node)).object
+
+        return vlan
+
+    def ex_expand_vlan(self, vlan):
+        """
+        Expands the VLAN to the prefix size in private_ipv4_range_size
+        The expansion will
+        not be permitted if the proposed IP space overlaps with an
+        already deployed VLANs IP space.
+        """
+        edit_node = ET.Element('expandVlan', {'xmlns': TYPES_URN})
+        edit_node.set('id', vlan.id)
+        ET.SubElement(edit_node, "privateIpv4PrefixSize").text =\
+            vlan.private_ipv4_range_size
+
+        response = self.connection.request_with_orgId_api_2(
+            'network/expandVlan',
+            method='POST',
+            data=ET.tostring(edit_node)).object
+
+        return vlan
+
+    def ex_delete_vlan(self, vlan):
+        delete_node = ET.Element('deleteVlan', {'xmlns': TYPES_URN})
+        delete_node.set('id', vlan.id)
+        result = self.connection.request_with_orgId_api_2(
+            'network/deleteVlan',
+            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
@@ -589,6 +684,12 @@ class DimensionDataNodeDriver(NodeDriver):
             name=findtext(element, 'name', TYPES_URN),
             description=findtext(element, 'description',
                                  TYPES_URN),
+            private_ipv4_range_address= \
+                element.find(fixxpath('privateIpv4Range', TYPES_URN)) \
+                    .get('address'),
+            private_ipv4_range_size= \
+                element.find(fixxpath('privateIpv4Range', TYPES_URN)) \
+                    .get('prefixSize'),
             location=location,
             status=status)
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/f3e7d51f/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_deleteVlan.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_deleteVlan.xml
b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_deleteVlan.xml
new file mode 100644
index 0000000..9eae809
--- /dev/null
+++ b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_deleteVlan.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<response requestId="NA9/2014-04-14T13:37:20/62f06368-c3fb-11e3-b29c-001517c4643e"
+xmlns="urn:didata.com:api:cloud:types">
+<operation>DELETE_VLAN</operation>
+<responseCode>IN_PROGRESS</responseCode>
+<message>Request to Delete VLAN (Id:0e56433f-d808-4669-821d-812769517ff8)
+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/f3e7d51f/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_deployVlan.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_deployVlan.xml
b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_deployVlan.xml
new file mode 100644
index 0000000..eb37402
--- /dev/null
+++ b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_deployVlan.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<response
+xmlns="urn:didata.com:api:cloud:types" requestId="NA9/2015-02-13T05:58:00.905-05:00/04a82e12-2d51-420e-84f5-bf2630c5a5e5">
+<operation>DEPLOY_VLAN</operation>
+<responseCode>IN_PROGRESS</responseCode>
+<message>Request to deploy VLAN 'Production VLAN' has been accepted and is
+being processed.</message>
+<info name="vlanId" value="cee8df03-9117-44cc-baaa-631ffa099683"/>
+</response>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/f3e7d51f/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_editVlan.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_editVlan.xml
b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_editVlan.xml
new file mode 100644
index 0000000..10d0010
--- /dev/null
+++ b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_editVlan.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-25T06:55:10.939-05:00/0593b9af-6b0c-4e5b-8e74-57b0e752f2bf">
+<operation>EDIT_VLAN</operation>
+<responseCode>OK</responseCode>
+<message>VLAN 'test' was edited successfully</message>
+</response>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/f3e7d51f/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_expandVlan.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_expandVlan.xml
b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_expandVlan.xml
new file mode 100644
index 0000000..03f9112
--- /dev/null
+++ b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_expandVlan.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-13T05:58:00.905-05:00/04a82e12-2d51-420e-84f5-bf2630c5a5e5">
+<operation>EXPAND_VLAN</operation>
+<responseCode>IN_PROGRESS</responseCode>
+<message>Request to expand VLAN 'Production VLAN' 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/f3e7d51f/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_vlan_0e56433f_d808_4669_821d_812769517ff8.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_vlan_0e56433f_d808_4669_821d_812769517ff8.xml
b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_vlan_0e56433f_d808_4669_821d_812769517ff8.xml
new file mode 100644
index 0000000..1b64756
--- /dev/null
+++ b/libcloud/test/compute/fixtures/dimensiondata/caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_vlan_0e56433f_d808_4669_821d_812769517ff8.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<vlan
+xmlns="urn:didata.com:api:cloud:types" id="0e56433f-d808-4669-821d-812769517ff8" datacenterId="NA9">
+<networkDomain id="484174a2-ae74-4658-9e56-50fc90e086cf" name="Production
+Network Domain"/>
+<name>Production VLAN</name>
+<description>test2</description>
+<privateIpv4Range address="10.0.3.0" prefixSize="24"/>
+<ipv4GatewayAddress>10.0.3.1</ipv4GatewayAddress>
+<ipv6Range address="2607:f480:1111:1153:0:0:0:0" prefixSize="64"/>
+<ipv6GatewayAddress>2607:f480:1111:1153:0:0:0:1</ipv6GatewayAddress>
+<createTime>2015-02-13T10:56:44.000Z</createTime>
+<state>NORMAL</state>
+</vlan>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/f3e7d51f/libcloud/test/compute/test_dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_dimensiondata.py b/libcloud/test/compute/test_dimensiondata.py
index 8ec4d13..fcddcdc 100644
--- a/libcloud/test/compute/test_dimensiondata.py
+++ b/libcloud/test/compute/test_dimensiondata.py
@@ -201,7 +201,7 @@ 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):
+    def test_ex_create_network_domain(self):
         location = self.driver.ex_get_location_by_id('NA9')
         net = self.driver.ex_create_network_domain(location=location,
                                                    name='test',
@@ -209,22 +209,19 @@ class DimensionDataTests(unittest.TestCase, TestCaseMixin):
         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')
+    def test_ex_get_network_domain(self):
         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')
+    def test_ex_update_network_domain(self):
         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')
+    def test_ex_delete_network_domain(self):
         net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
         result = self.driver.ex_delete_network_domain(net)
         self.assertTrue(result)
@@ -243,6 +240,39 @@ class DimensionDataTests(unittest.TestCase, TestCaseMixin):
         vlans = self.driver.ex_list_vlans()
         self.assertEqual(vlans[0].name, "Primary")
 
+    def test_ex_create_vlan(self,):
+        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
+        vlan = self.driver.ex_create_vlan(network_domain=net,
+                                          name='test',
+                                          private_ipv4_base_address='10.3.4.0',
+                                          private_ipv4_prefix_size='24')
+        self.assertEqual(vlan.id, 'cee8df03-9117-44cc-baaa-631ffa099683')
+
+    def test_ex_get_vlan(self):
+        vlan = self.driver.ex_get_vlan('0e56433f-d808-4669-821d-812769517ff8')
+        self.assertEqual(vlan.id, '0e56433f-d808-4669-821d-812769517ff8')
+        self.assertEqual(vlan.description, 'test2')
+        self.assertEqual(vlan.name, 'Production VLAN')
+        self.assertEqual(vlan.private_ipv4_range_address, '10.0.3.0')
+        self.assertEqual(vlan.private_ipv4_range_size, '24')
+
+    def test_ex_update_vlan(self):
+        vlan = self.driver.ex_get_vlan('0e56433f-d808-4669-821d-812769517ff8')
+        vlan.name = 'new name'
+        vlan2 = self.driver.ex_update_vlan(vlan)
+        self.assertEqual(vlan2.name, 'new name')
+
+    def test_ex_delete_vlan(self):
+        vlan = self.driver.ex_get_vlan('0e56433f-d808-4669-821d-812769517ff8')
+        result = self.driver.ex_delete_vlan(vlan)
+        self.assertTrue(result)
+
+    def test_ex_expand_vlan(self):
+        vlan = self.driver.ex_get_vlan('0e56433f-d808-4669-821d-812769517ff8')
+        vlan.private_ipv4_range_size = '23'
+        result = self.driver.ex_expand_vlan(vlan)
+        self.assertEqual(vlan.private_ipv4_range_size, '23')
+
 
 class DimensionDataMockHttp(MockHttp):
 
@@ -446,5 +476,31 @@ class DimensionDataMockHttp(MockHttp):
             'caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_deleteNetworkDomain.xml')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
+    def _caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_deployVlan(self, method, url,
body, headers):
+        body = self.fixtures.load(
+            'caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_deployVlan.xml')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_vlan_0e56433f_d808_4669_821d_812769517ff8(self,
method, url, body, headers):
+        body = self.fixtures.load(
+            'caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_vlan_0e56433f_d808_4669_821d_812769517ff8.xml')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_editVlan(self, method, url,
body, headers):
+        body = self.fixtures.load(
+            'caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_editVlan.xml')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_deleteVlan(self, method, url,
body, headers):
+        body = self.fixtures.load(
+            'caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_deleteVlan.xml')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_expandVlan(self, method, url,
body, headers):
+        body = self.fixtures.load(
+            'caas_2_0_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_expandVlan.xml')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+
 if __name__ == '__main__':
     sys.exit(unittest.main())


Mime
View raw message