libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r1447256 - in /libcloud/trunk: CHANGES libcloud/compute/drivers/openstack.py libcloud/test/compute/fixtures/openstack_v1.1/_servers_detail.json libcloud/test/compute/test_openstack.py
Date Mon, 18 Feb 2013 13:45:50 GMT
Author: tomaz
Date: Mon Feb 18 13:45:49 2013
New Revision: 1447256

URL: http://svn.apache.org/r1447256
Log:
Improve public and private IP address handling in OpenStack 1.1 driver. Assume
every IP address which doesn't have a label "public" or "internet" is private.

Part of LIBCLOUD-297.

Modified:
    libcloud/trunk/CHANGES
    libcloud/trunk/libcloud/compute/drivers/openstack.py
    libcloud/trunk/libcloud/test/compute/fixtures/openstack_v1.1/_servers_detail.json
    libcloud/trunk/libcloud/test/compute/test_openstack.py

Modified: libcloud/trunk/CHANGES
URL: http://svn.apache.org/viewvc/libcloud/trunk/CHANGES?rev=1447256&r1=1447255&r2=1447256&view=diff
==============================================================================
--- libcloud/trunk/CHANGES (original)
+++ libcloud/trunk/CHANGES Mon Feb 18 13:45:49 2013
@@ -166,6 +166,11 @@ Changes with Apache Libcloud in developm
    - Add support for OpenNebula 3.8. (LIBCLOUD-295)
      [Guillaume ZITTA]
 
+   -  Improve public and private IP address handling in OpenStack 1.1 driver.
+      Assume every IP address which doesn't have a label "public" or "internet"
+      is private. (LIBCLOUD-297)
+      [Grischa Meyer, Tomaz Muraus]
+
   *) Storage
 
     - Add a new local storage driver.

Modified: libcloud/trunk/libcloud/compute/drivers/openstack.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/drivers/openstack.py?rev=1447256&r1=1447255&r2=1447256&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/drivers/openstack.py (original)
+++ libcloud/trunk/libcloud/compute/drivers/openstack.py Mon Feb 18 13:45:49 2013
@@ -1596,16 +1596,25 @@ class OpenStack_1_1_NodeDriver(OpenStack
         return self._to_node(obj['server'])
 
     def _to_node(self, api_node):
+        public_networks_labels = ['public', 'internet']
+
+        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:
+                private_ips.extend(ips)
+
         return Node(
             id=api_node['id'],
             name=api_node['name'],
             state=self.NODE_STATE_MAP.get(api_node['status'],
                                           NodeState.UNKNOWN),
-            public_ips=[addr_desc['addr'] for addr_desc in
-                        chain(api_node['addresses'].get('public', []),
-                              api_node['addresses'].get('internet', []))],
-            private_ips=[addr_desc['addr'] for addr_desc in
-                         api_node['addresses'].get('private', [])],
+            public_ips=public_ips,
+            private_ips=private_ips,
             driver=self,
             extra=dict(
                 hostId=api_node['hostId'],

Modified: libcloud/trunk/libcloud/test/compute/fixtures/openstack_v1.1/_servers_detail.json
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/compute/fixtures/openstack_v1.1/_servers_detail.json?rev=1447256&r1=1447255&r2=1447256&view=diff
==============================================================================
--- libcloud/trunk/libcloud/test/compute/fixtures/openstack_v1.1/_servers_detail.json (original)
+++ libcloud/trunk/libcloud/test/compute/fixtures/openstack_v1.1/_servers_detail.json Mon
Feb 18 13:45:49 2013
@@ -1 +1 @@
-{"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"}]}, "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, "pro
 gress": 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": {}}, {"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:87
 74/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": {}}]}
\ No newline at end of file
+{"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",
"acc
 essIPv4": "", "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": {}}, {"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": {}}]}

Modified: libcloud/trunk/libcloud/test/compute/test_openstack.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/compute/test_openstack.py?rev=1447256&r1=1447255&r2=1447256&view=diff
==============================================================================
--- libcloud/trunk/libcloud/test/compute/test_openstack.py (original)
+++ libcloud/trunk/libcloud/test/compute/test_openstack.py Mon Feb 18 13:45:49 2013
@@ -161,7 +161,7 @@ class OpenStack_1_0_Tests(unittest.TestC
         self.assertEqual(len(ret), 1)
         node = ret[0]
         self.assertEqual('67.23.21.33', node.public_ips[0])
-        self.assertEqual('10.176.168.218', node.private_ips[0])
+        self.assertTrue('10.176.168.218' in node.private_ips)
         self.assertEqual(node.extra.get('flavorId'), '1')
         self.assertEqual(node.extra.get('imageId'), '11')
         self.assertEqual(type(node.extra.get('metadata')), type(dict()))
@@ -654,8 +654,9 @@ class OpenStack_1_1_Tests(unittest.TestC
         self.assertEqual('12065', node.id)
         self.assertEqual('50.57.94.35', node.public_ips[0])
         self.assertEqual('2001:4801:7808:52:16:3eff:fe47:788a', node.public_ips[1])
-        self.assertEqual('10.182.64.34', node.private_ips[0])
-        self.assertEqual('fec0:4801:7808:52:16:3eff:fe60:187d', node.private_ips[1])
+        self.assertTrue('10.182.64.34' in  node.private_ips)
+        self.assertTrue('12.16.18.28' in node.private_ips)
+        self.assertTrue('fec0:4801:7808:52:16:3eff:fe60:187d' in node.private_ips)
 
         self.assertEqual(node.extra.get('flavorId'), '2')
         self.assertEqual(node.extra.get('imageId'), '7')



Mime
View raw message