libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject git commit: Correctly categorize node public and private IP addresses when dealing with OpenStack floating IPs.
Date Tue, 02 Sep 2014 15:38:14 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk f007edaaf -> 65e0bfbc1


Correctly categorize node public and private IP addresses when dealing with
OpenStack floating IPs.

Patch by Andrew Mann and Tomaz (tests).


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

Branch: refs/heads/trunk
Commit: 65e0bfbc1de05f77ccdd659acafa5d19858bfb32
Parents: f007eda
Author: Tomaz Muraus <tomaz@apache.org>
Authored: Tue Sep 2 15:45:49 2014 +0200
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Tue Sep 2 16:24:42 2014 +0200

----------------------------------------------------------------------
 CHANGES.rst                                     |   4 +
 libcloud/compute/drivers/openstack.py           |  46 ++++--
 .../openstack_v1.1/_servers_detail.json         | 163 ++++++++++++++++++-
 libcloud/test/compute/test_openstack.py         |  10 ++
 4 files changed, 207 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/65e0bfbc/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index 69ab399..e1253d4 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -82,6 +82,10 @@ Compute
   (GITHUB-321, GITHUB-354)
   [Itxaka Serrano]
 
+- Correctly categorize node IP addresses into public and private when dealing
+  with OpenStack floating IPs.
+  [Andrew Mann]
+
 Storage
 ~~~~~~~
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/65e0bfbc/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index c836109..01fadee 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -39,7 +39,7 @@ from libcloud.common.openstack import OpenStackBaseConnection
 from libcloud.common.openstack import OpenStackDriverMixin
 from libcloud.common.openstack import OpenStackException
 from libcloud.common.openstack import OpenStackResponse
-from libcloud.utils.networking import is_private_subnet
+from libcloud.utils.networking import is_public_subnet
 from libcloud.compute.base import NodeSize, NodeImage
 from libcloud.compute.base import (NodeDriver, Node, NodeLocation,
                                    StorageVolume, VolumeSnapshot)
@@ -1942,20 +1942,36 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver):
         public_ips, private_ips = [], []
 
         for label, values in api_node['addresses'].items():
-            ips = [v['addr'] for v in values]
-
-            if label in public_networks_labels:
-                public_ips.extend(ips)
-            else:
-                for ip in ips:
-                    # is_private_subnet does not check for ipv6
-                    try:
-                        if is_private_subnet(ip):
-                            private_ips.append(ip)
-                        else:
-                            public_ips.append(ip)
-                    except:
-                        private_ips.append(ip)
+            for value in values:
+                ip = value['addr']
+
+                is_public_ip = False
+
+                try:
+                    public_subnet = is_public_subnet(ip)
+                except:
+                    # IPv6
+                    public_subnet = False
+
+                # Openstack Icehouse sets 'OS-EXT-IPS:type' to 'floating' for
+                # public and 'fixed' for private
+                explicit_ip_type = value.get('OS-EXT-IPS:type', None)
+
+                if explicit_ip_type == 'floating':
+                    is_public_ip = True
+                elif explicit_ip_type == 'fixed':
+                    is_public_ip = False
+                elif label in public_networks_labels:
+                    # Try label next
+                    is_public_ip = True
+                elif public_subnet:
+                    # Check for public subnet
+                    is_public_ip = True
+
+                if is_public_ip:
+                    public_ips.append(ip)
+                else:
+                    private_ips.append(ip)
 
         # Sometimes 'image' attribute is not present if the node is in an error
         # state

http://git-wip-us.apache.org/repos/asf/libcloud/blob/65e0bfbc/libcloud/test/compute/fixtures/openstack_v1.1/_servers_detail.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_servers_detail.json b/libcloud/test/compute/fixtures/openstack_v1.1/_servers_detail.json
index 35d9085..b2dfe18 100644
--- a/libcloud/test/compute/fixtures/openstack_v1.1/_servers_detail.json
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_servers_detail.json
@@ -1 +1,162 @@
-{"servers": [{"status": "BUILD", "updated": "2011-10-11T00:50:04Z", "hostId": "912566d83a13fbb357ea3f13c629363d9f7e1ba3f925b49f3d2ab725",
"user_id": "rs-reach", "name": "lc-test-2", "links": [{"href": "http://alpha.ord.servers.api.rackspacecloud.com:8774/v1.1/rs-reach-project/servers/12065",
"rel": "self"}, {"href": "http://alpha.ord.servers.api.rackspacecloud.com:8774/rs-reach-project/servers/12065",
"rel": "bookmark"}], "addresses": {"public": [{"version": 4, "addr": "50.57.94.35"}, {"version":
6, "addr": "2001:4801:7808:52:16:3eff:fe47:788a"}], "private": [{"version": 4, "addr": "10.182.64.34"},
{"version": 6, "addr": "fec0:4801:7808:52:16:3eff:fe60:187d"}], "mynetwork": [{"version":
4, "addr": "12.16.18.28"}]}, "tenant_id": "rs-reach-project", "image": {"id": "7", "links":
[{"href": "http://alpha.ord.servers.api.rackspacecloud.com:8774/rs-reach-project/images/7",
"rel": "bookmark"}]}, "created": "2011-10-11T00:51:39Z", "uuid": "02786501-714e-40af-8342-9c17eccb166d",
"accessIPv4"
 : "", "accessIPv6": "", "key_name": null, "progress": 25, "flavor": {"id": "2", "links":
[{"href": "http://alpha.ord.servers.api.rackspacecloud.com:8774/rs-reach-project/flavors/2",
"rel": "bookmark"}]}, "config_drive": "", "id": 12065, "metadata": {}, "OS-DCF:diskConfig":
"AUTO"}, {"status": "ACTIVE", "updated": "2011-10-11T00:44:20Z", "hostId": "a024053a6201e6c6c12660aab3d8fd879e332e663a5e1fdbc02a0307",
"user_id": "rs-reach", "name": "lc-test", "links": [{"href": "http://alpha.ord.servers.api.rackspacecloud.com:8774/v1.1/rs-reach-project/servers/12064",
"rel": "self"}, {"href": "http://alpha.ord.servers.api.rackspacecloud.com:8774/rs-reach-project/servers/12064",
"rel": "bookmark"}], "addresses": {"public": [{"version": 4, "addr": "50.57.94.30"}, {"version":
6, "addr": "2001:4801:7808:52:16:3eff:fe77:32e3"}], "private": [{"version": 4, "addr": "10.182.64.29"},
{"version": 6, "addr": "fec0:4801:7808:52:16:3eff:fe6e:b7e2"}]}, "tenant_id": "rs-reach-project",
"image": {"id": "7", "li
 nks": [{"href": "http://alpha.ord.servers.api.rackspacecloud.com:8774/rs-reach-project/images/7",
"rel": "bookmark"}]}, "created": "2011-10-11T00:45:02Z", "uuid": "ec53630b-e4fb-442a-a748-c376f5c4345b",
"accessIPv4": "", "accessIPv6": "", "key_name": null, "progress": 100, "flavor": {"id": "2",
"links": [{"href": "http://alpha.ord.servers.api.rackspacecloud.com:8774/rs-reach-project/flavors/2",
"rel": "bookmark"}]}, "config_drive": "", "id": 12064, "metadata": {}, "OS-DCF:diskConfig":
"AUTO"}]}
+{
+    "servers": [
+        {
+            "status": "BUILD",
+            "updated": "2011-10-11T00:50:04Z",
+            "hostId": "912566d83a13fbb357ea3f13c629363d9f7e1ba3f925b49f3d2ab725",
+            "user_id": "rs-reach",
+            "name": "lc-test-2",
+            "links": [
+                {
+                    "href": "http://alpha.ord.servers.api.rackspacecloud.com:8774/v1.1/rs-reach-project/servers/12065",
+                    "rel": "self"
+                },
+                {
+                    "href": "http://alpha.ord.servers.api.rackspacecloud.com:8774/rs-reach-project/servers/12065",
+                    "rel": "bookmark"
+                }
+            ],
+            "addresses": {
+                "public": [
+                    {
+                        "version": 4,
+                        "addr": "50.57.94.35"
+                    },
+                    {
+                        "version": 6,
+                        "addr": "2001:4801:7808:52:16:3eff:fe47:788a"
+                    }
+                ],
+                "private": [
+                    {
+                        "version": 4,
+                        "addr": "10.182.64.34"
+                    },
+                    {
+                        "version": 6,
+                        "addr": "fec0:4801:7808:52:16:3eff:fe60:187d"
+                    }
+                ],
+                "mynetwork": [
+                    {
+                        "version": 4,
+                        "addr": "12.16.18.28"
+                    }
+                ],
+                "mynetwork_public": [
+                    {
+                        "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:79:90:aa",
+                        "OS-EXT-IPS:type": "floating",
+                        "addr": "192.168.3.3",
+                        "version": 4
+                    }
+                ],
+                "mynetwork_private": [
+                    {
+                        "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:79:90:aa",
+                        "OS-EXT-IPS:type": "fixed",
+                        "addr": "10.3.3.3",
+                        "version": 4
+                    }
+                ]
+            },
+            "tenant_id": "rs-reach-project",
+            "image": {
+                "id": "7",
+                "links": [
+                    {
+                        "href": "http://alpha.ord.servers.api.rackspacecloud.com:8774/rs-reach-project/images/7",
+                        "rel": "bookmark"
+                    }
+                ]
+            },
+            "created": "2011-10-11T00:51:39Z",
+            "uuid": "02786501-714e-40af-8342-9c17eccb166d",
+            "accessIPv4": "",
+            "accessIPv6": "",
+            "key_name": null,
+            "progress": 25,
+            "flavor": {
+                "id": "2",
+                "links": [
+                    {
+                        "href": "http://alpha.ord.servers.api.rackspacecloud.com:8774/rs-reach-project/flavors/2",
+                        "rel": "bookmark"
+                    }
+                ]
+            },
+            "config_drive": "",
+            "id": 12065,
+            "metadata": {},
+            "OS-DCF:diskConfig": "AUTO"
+        },
+        {
+            "status": "ACTIVE",
+            "updated": "2011-10-11T00:44:20Z",
+            "hostId": "a024053a6201e6c6c12660aab3d8fd879e332e663a5e1fdbc02a0307",
+            "user_id": "rs-reach",
+            "name": "lc-test",
+            "links": [
+                {
+                    "href": "http://alpha.ord.servers.api.rackspacecloud.com:8774/v1.1/rs-reach-project/servers/12064",
+                    "rel": "self"
+                },
+                {
+                    "href": "http://alpha.ord.servers.api.rackspacecloud.com:8774/rs-reach-project/servers/12064",
+                    "rel": "bookmark"
+                }
+            ],
+            "addresses": {
+                "public": [
+                    {
+                        "version": 4,
+                        "addr": "50.57.94.30"
+                    },
+                    {
+                        "version": 6,
+                        "addr": "2001:4801:7808:52:16:3eff:fe77:32e3"
+                    }
+                ],
+                "private": [
+                    {
+                        "version": 4,
+                        "addr": "10.182.64.29"
+                    },
+                    {
+                        "version": 6,
+                        "addr": "fec0:4801:7808:52:16:3eff:fe6e:b7e2"
+                    }
+                ]
+            },
+            "tenant_id": "rs-reach-project",
+            "image": {
+                "id": "7",
+                "links": [
+                    {
+                        "href": "http://alpha.ord.servers.api.rackspacecloud.com:8774/rs-reach-project/images/7",
+                        "rel": "bookmark"
+                    }
+                ]
+            },
+            "created": "2011-10-11T00:45:02Z",
+            "uuid": "ec53630b-e4fb-442a-a748-c376f5c4345b",
+            "accessIPv4": "",
+            "accessIPv6": "",
+            "key_name": null,
+            "progress": 100,
+            "flavor": {
+                "id": "2",
+                "links": [
+                    {
+                        "href": "http://alpha.ord.servers.api.rackspacecloud.com:8774/rs-reach-project/flavors/2",
+                        "rel": "bookmark"
+                    }
+                ]
+            },
+            "config_drive": "",
+            "id": 12064,
+            "metadata": {},
+            "OS-DCF:diskConfig": "AUTO"
+        }
+    ]
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/65e0bfbc/libcloud/test/compute/test_openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py
index 642b7a8..e52c6d9 100644
--- a/libcloud/test/compute/test_openstack.py
+++ b/libcloud/test/compute/test_openstack.py
@@ -750,14 +750,24 @@ class OpenStack_1_1_Tests(unittest.TestCase, TestCaseMixin):
         node = nodes[0]
 
         self.assertEqual('12065', node.id)
+
         # test public IPv4
         self.assertTrue('12.16.18.28' in node.public_ips)
         self.assertTrue('50.57.94.35' in node.public_ips)
+
+        # floating ip
+        self.assertTrue('192.168.3.3' in node.public_ips)
+
         # test public IPv6
         self.assertTrue(
             '2001:4801:7808:52:16:3eff:fe47:788a' in node.public_ips)
+
         # test private IPv4
         self.assertTrue('10.182.64.34' in node.private_ips)
+
+        # floating ip
+        self.assertTrue('10.3.3.3' in node.private_ips)
+
         # test private IPv6
         self.assertTrue(
             'fec0:4801:7808:52:16:3eff:fe60:187d' in node.private_ips)


Mime
View raw message