You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by an...@apache.org on 2016/04/16 07:36:39 UTC

[4/8] libcloud git commit: Added support for port lists

Added support for port lists


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

Branch: refs/heads/trunk
Commit: f3365320de2dbe65c1b6a5eb8ee1bef133da8edd
Parents: 40f7a68
Author: anthony-shaw <an...@apache.org>
Authored: Fri Apr 15 16:33:28 2016 +1000
Committer: anthony-shaw <an...@apache.org>
Committed: Sat Apr 16 15:36:03 2016 +1000

----------------------------------------------------------------------
 libcloud/compute/drivers/dimensiondata.py   | 32 +++++++++++++++---------
 libcloud/test/compute/test_dimensiondata.py |  7 ++++++
 2 files changed, 27 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/f3365320/libcloud/compute/drivers/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/dimensiondata.py b/libcloud/compute/drivers/dimensiondata.py
index fed4791..670fefc 100644
--- a/libcloud/compute/drivers/dimensiondata.py
+++ b/libcloud/compute/drivers/dimensiondata.py
@@ -1367,7 +1367,7 @@ class DimensionDataNodeDriver(NodeDriver):
         source = ET.SubElement(create_node, "source")
         if rule.source.address_list_id is not None:
             source_ip = ET.SubElement(source, 'ipAddressListId')
-            source_ip.set('id', rule.source.address_list_id)
+            source_ip.text = rule.source.address_list_id
         else:
             source_ip = ET.SubElement(source, 'ip')
             if rule.source.any_ip:
@@ -1376,16 +1376,20 @@ class DimensionDataNodeDriver(NodeDriver):
                 source_ip.set('address', rule.source.ip_address)
                 if rule.source.ip_prefix_size is not None:
                     source_ip.set('prefixSize', str(rule.source.ip_prefix_size))
-                if rule.source.port_begin is not None:
-                    source_port = ET.SubElement(source, 'port')
-                    source_port.set('begin', rule.source.port_begin)
-                if rule.source.port_end is not None:
-                    source_port.set('end', rule.source.port_end)
+        if rule.source.port_list_id is not None:
+            source_port = ET.SubElement(source, 'portListId')
+            source_port.text = rule.source.port_list_id
+        else:
+            if rule.source.port_begin is not None:
+                source_port = ET.SubElement(source, 'port')
+                source_port.set('begin', rule.source.port_begin)
+            if rule.source.port_end is not None:
+                source_port.set('end', rule.source.port_end)
         # Setup destination port rule
         dest = ET.SubElement(create_node, "destination")
         if rule.destination.address_list_id is not None:
             dest_ip = ET.SubElement(dest, 'ipAddressListId')
-            dest_ip.set('id', rule.destination.address_list_id)
+            dest_ip.text = rule.destination.address_list_id
         else:
             dest_ip = ET.SubElement(dest, 'ip')
             if rule.destination.any_ip:
@@ -1394,11 +1398,15 @@ class DimensionDataNodeDriver(NodeDriver):
                 dest_ip.set('address', rule.destination.ip_address)
                 if rule.destination.ip_prefix_size is not None:
                     dest_ip.set('prefixSize', rule.destination.ip_prefix_size)
-                if rule.destination.port_begin is not None:
-                    dest_port = ET.SubElement(dest, 'port')
-                    dest_port.set('begin', rule.destination.port_begin)
-                if rule.destination.port_end is not None:
-                    dest_port.set('end', rule.destination.port_end)
+        if rule.destination.port_list_id is not None:
+            dest_port = ET.SubElement(dest, 'portListId')
+            dest_port.text = rule.destination.port_list_id
+        else:
+            if rule.destination.port_begin is not None:
+                dest_port = ET.SubElement(dest, 'port')
+                dest_port.set('begin', rule.destination.port_begin)
+            if rule.destination.port_end is not None:
+                dest_port.set('end', rule.destination.port_end)
         # Set up positioning of rule
         ET.SubElement(create_node, "enabled").text = str(rule.enabled).lower()
         placement = ET.SubElement(create_node, "placement")

http://git-wip-us.apache.org/repos/asf/libcloud/blob/f3365320/libcloud/test/compute/test_dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_dimensiondata.py b/libcloud/test/compute/test_dimensiondata.py
index 89e1b09..1e1fa2a 100644
--- a/libcloud/test/compute/test_dimensiondata.py
+++ b/libcloud/test/compute/test_dimensiondata.py
@@ -711,6 +711,13 @@ class DimensionDataTests(unittest.TestCase, TestCaseMixin):
         rule.destination.address_list_id = '12345'
         self.driver.ex_create_firewall_rule(net, rule, 'LAST')
 
+    def test_ex_create_firewall_rule_port_list(self):
+        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
+        rule = self.driver.ex_list_firewall_rules(net)[0]
+        rule.source.port_list_id = '12345'
+        rule.destination.port_list_id = '12345'
+        self.driver.ex_create_firewall_rule(net, rule, 'LAST')
+
     def test_ex_create_firewall_rule_ALL_VALUES(self):
         net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
         rules = self.driver.ex_list_firewall_rules(net)