libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vd...@apache.org
Subject [11/23] libcloud git commit: Move sec groups to neutron api LIBCLOUD-874
Date Tue, 04 Dec 2018 08:54:26 GMT
Move sec groups to neutron api LIBCLOUD-874


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

Branch: refs/heads/trunk
Commit: f05ff35bfcf021cc12cf613a3927fcc2d764d16d
Parents: d66638a
Author: micafer <micafer1@upv.es>
Authored: Mon Sep 24 17:13:29 2018 +0200
Committer: Rick van de Loo <rickvandeloo@gmail.com>
Committed: Tue Dec 4 09:45:48 2018 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py           | 44 +++++++++++++++++++-
 .../openstack_v1.1/_v2_0__security_group.json   | 20 +++++++++
 .../openstack_v1.1/_v2_0__security_groups.json  | 29 +++++++++++++
 libcloud/test/compute/test_openstack.py         | 13 ++++--
 4 files changed, 102 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/f05ff35b/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index df42acd..20826dc 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -1816,7 +1816,8 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver):
                 security_groups]
 
     def _to_security_group(self, obj):
-        rules = self._to_security_group_rules(obj.get('rules', []))
+        rules = self._to_security_group_rules(obj.get('security_group_rules',
+                                                      obj.get('rules', [])))
         return OpenStackSecurityGroup(id=obj['id'],
                                       tenant_id=obj['tenant_id'],
                                       name=obj['name'],
@@ -3118,6 +3119,47 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
         return resp.status == httplib.ACCEPTED
 
 
+    def ex_list_security_groups(self):
+        """
+        Get a list of Security Groups that are available.
+
+        :rtype: ``list`` of :class:`OpenStackSecurityGroup`
+        """
+        return self._to_security_groups(
+            self.network_connection.request('/v2.0/security-groups').object)
+
+    def ex_create_security_group(self, name, description):
+        """
+        Create a new Security Group
+
+        :param name: Name of the new Security Group
+        :type  name: ``str``
+
+        :param description: Description of the new Security Group
+        :type  description: ``str``
+
+        :rtype: :class:`OpenStackSecurityGroup`
+        """
+        return self._to_security_group(self.network_connection .request(
+            '/v2.0/security-groups', method='POST',
+            data={'security_group': {'name': name, 'description': description}}
+        ).object['security_group'])
+
+    def ex_delete_security_group(self, security_group):
+        """
+        Delete a Security Group.
+
+        :param security_group: Security Group should be deleted
+        :type  security_group: :class:`OpenStackSecurityGroup`
+
+        :rtype: ``bool``
+        """
+        resp = self.network_connection.request('/v2.0/security-groups/%s' %
+                                       (security_group.id),
+                                       method='DELETE')
+        return resp.status==httplib.NO_CONTENT
+
+
 class OpenStack_1_1_FloatingIpPool(object):
     """
     Floating IP Pool info.

http://git-wip-us.apache.org/repos/asf/libcloud/blob/f05ff35b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_group.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_group.json b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_group.json
new file mode 100644
index 0000000..df20ef4
--- /dev/null
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_group.json
@@ -0,0 +1,20 @@
+{
+    "security_group":
+        {
+            "description": "FTP Client-Server - Open 20-21 ports", 
+            "id": 4, 
+            "name": "ftp", 
+            "security_group_rules": [
+                {
+                    "security_group_id": "4",
+                    "direction": "ingress",
+                    "port_range_max": 21, 
+                    "port_range_min": 20, 
+                    "remote_ip_prefix": "0.0.0.0/0", 
+                    "id": 1, 
+                    "protocol": "tcp"
+                }
+            ], 
+            "tenant_id": "68"
+        }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/f05ff35b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_groups.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_groups.json b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_groups.json
new file mode 100644
index 0000000..5fd84f4
--- /dev/null
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_groups.json
@@ -0,0 +1,29 @@
+{
+    "security_groups": [
+        {
+            "description": "default", 
+            "id": 2, 
+            "name": "default", 
+            "security_group_rules": [], 
+            "tenant_id": "68"
+        }, 
+        {
+            "description": "FTP Client-Server - Open 20-21 ports", 
+            "id": 4, 
+            "name": "ftp", 
+            "security_group_rules": [
+                {
+                    "security_group_id": "4",
+                    "direction": "ingress",
+                    "port_range_max": 21, 
+                    "port_range_min": 20, 
+                    "remote_ip_prefix": "0.0.0.0/0", 
+                    "id": 1, 
+                    "protocol": "tcp"
+                }
+            ], 
+            "tenant_id": "68"
+        }
+    ]
+}
+

http://git-wip-us.apache.org/repos/asf/libcloud/blob/f05ff35b/libcloud/test/compute/test_openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py
index 9dc39ee..618b7f5 100644
--- a/libcloud/test/compute/test_openstack.py
+++ b/libcloud/test/compute/test_openstack.py
@@ -2400,7 +2400,7 @@ class OpenStack_1_1_MockHttp(MockHttp, unittest.TestCase):
     def _v2_1337_volumes(self, method, url, body, headers):
         if method == 'POST':
             body = self.fixtures.load('_v2_0__volume.json')
-            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+            return (httplib.CREATED, body, self.json_content_headers, httplib.responses[httplib.OK])
 
     def _v2_1337_volumes_cd76a3a1_c4ce_40f6_9b9f_07a61508938d(self, method, url, body, headers):
         if method == 'GET':
@@ -2417,7 +2417,7 @@ class OpenStack_1_1_MockHttp(MockHttp, unittest.TestCase):
     def _v2_1337_snapshots(self, method, url, body, headers):
         if method == 'POST':
             body = self.fixtures.load('_v2_0__snapshot.json')
-            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+            return (httplib.CREATED, body, self.json_content_headers, httplib.responses[httplib.OK])
 
     def _v2_1337_snapshots_3fbbcccf_d058_4502_8844_6feeffdf4cb5(self, method, url, body,
headers):
         if method == 'GET':
@@ -2426,7 +2426,14 @@ class OpenStack_1_1_MockHttp(MockHttp, unittest.TestCase):
         if method == 'DELETE':
             body = ''
             return (httplib.ACCEPTED, body, self.json_content_headers, httplib.responses[httplib.OK])
-    
+
+    def _v2_1337_v2_0_security_groups(self, method, url, body, headers):
+        if method == 'POST':
+            body = self.fixtures.load('_v2_0__security_group.json')
+            return (httplib.CREATED, body, self.json_content_headers, httplib.responses[httplib.OK])
+        if method == 'GET':
+            body = self.fixtures.load('_v2_0__security_group.json')
+            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
 
 # This exists because the nova compute url in devstack has v2 in there but the v1.1 fixtures
 # work fine.


Mime
View raw message