Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenStack public ip addresses fix #235

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion libcloud/compute/drivers/openstack.py
Expand Up @@ -37,6 +37,7 @@
from libcloud.common.openstack import OpenStackBaseConnection
from libcloud.common.openstack import OpenStackDriverMixin
from libcloud.common.types import MalformedResponseError, ProviderError
from libcloud.utils.networking import is_private_subnet
from libcloud.compute.base import NodeSize, NodeImage
from libcloud.compute.base import (NodeDriver, Node, NodeLocation,
StorageVolume, VolumeSnapshot)
Expand Down Expand Up @@ -1987,7 +1988,15 @@ def _to_node(self, api_node):
if label in public_networks_labels:
public_ips.extend(ips)
else:
private_ips.extend(ips)
for ip in ips:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs a test case which tests the following scenarios:

  • Public IPv4
  • Public IPv6
  • Private IPv4
  • Private IPv6

#is_private_subnet does not check for ipv6
try:
if is_private_subnet(ip):
private_ips.append(ip)
else:
public_ips.append(ip)
except:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to catch a more specific exception.

private_ips.append(ip)

# Sometimes 'image' attribute is not present if the node is in an error
# state
Expand Down
12 changes: 8 additions & 4 deletions libcloud/test/compute/test_openstack.py
Expand Up @@ -961,11 +961,15 @@ def test_list_nodes(self):
node = nodes[0]

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])
#test public IPv4
self.assertTrue('12.16.18.28' in node.public_ips)
self.assertTrue('50.57.94.35' 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)
self.assertTrue('12.16.18.28' in node.private_ips)
#test private IPv6
self.assertTrue(
'fec0:4801:7808:52:16:3eff:fe60:187d' in node.private_ips)

Expand Down