summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Waldon <brian.waldon@rackspace.com>2011-07-14 14:23:23 -0400
committerBrian Waldon <brian.waldon@rackspace.com>2011-07-14 14:23:23 -0400
commit38233d72aff36fbdb0fd49755458b7b5100366e1 (patch)
tree29dbf1221d7c243568b46121d73b6c82b19e2c1a
parent27b8d75f9b666ce08472270b38685d8e36a612d8 (diff)
downloadnova-38233d72aff36fbdb0fd49755458b7b5100366e1.tar.gz
nova-38233d72aff36fbdb0fd49755458b7b5100366e1.tar.xz
nova-38233d72aff36fbdb0fd49755458b7b5100366e1.zip
exposing floating ips
-rw-r--r--nova/api/openstack/views/addresses.py22
-rw-r--r--nova/tests/api/openstack/test_servers.py16
2 files changed, 26 insertions, 12 deletions
diff --git a/nova/api/openstack/views/addresses.py b/nova/api/openstack/views/addresses.py
index b127ac38c..a242efa45 100644
--- a/nova/api/openstack/views/addresses.py
+++ b/nova/api/openstack/views/addresses.py
@@ -46,24 +46,26 @@ class ViewBuilderV11(ViewBuilder):
networks = {}
for interface in interfaces:
network_label = interface['network']['label']
+
if network_label not in networks:
networks[network_label] = []
- for fixed_ip in interface['fixed_ips']:
- ip = {'addr': fixed_ip['address'], 'version': 4}
- networks[network_label].append(ip)
+ networks[network_label].extend(self._extract_ipv4(interface))
+
return networks
def build_network(self, interfaces, network_label):
for interface in interfaces:
if interface['network']['label'] == network_label:
- ips = self._extract_fixed_ips(interface)
- return {network_label: ips}
+ ips = self._extract_ipv4(interface)
+ return {network_label: list(ips)}
return None
- def _extract_fixed_ips(self, interface):
- fixed_ips = []
+ def _extract_ipv4(self, interface):
for fixed_ip in interface['fixed_ips']:
- ip = {'addr': fixed_ip['address'], 'version': 4}
- fixed_ips.append(ip)
- return fixed_ips
+ yield self._build_ip_entity(fixed_ip['address'], 4)
+ for floating_ip in fixed_ip.get('floating_ips', []):
+ yield self._build_ip_entity(floating_ip['address'], 4)
+
+ def _build_ip_entity(self, address, version):
+ return {'addr': address, 'version': version}
diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py
index 7a2904520..3c48a2f81 100644
--- a/nova/tests/api/openstack/test_servers.py
+++ b/nova/tests/api/openstack/test_servers.py
@@ -484,7 +484,12 @@ class ServersTest(test.TestCase):
{
'network': {'label': 'network_2'},
'fixed_ips': [
- {'address': '172.19.0.1'},
+ {
+ 'address': '172.19.0.1',
+ 'floating_ips': [
+ {'address': '1.2.3.4'},
+ ],
+ },
{'address': '172.19.0.2'},
],
},
@@ -507,6 +512,7 @@ class ServersTest(test.TestCase):
],
'network_2': [
{'version': 4, 'addr': '172.19.0.1'},
+ {'version': 4, 'addr': '1.2.3.4'},
{'version': 4, 'addr': '172.19.0.2'},
],
},
@@ -526,7 +532,12 @@ class ServersTest(test.TestCase):
{
'network': {'label': 'network_2'},
'fixed_ips': [
- {'address': '172.19.0.1'},
+ {
+ 'address': '172.19.0.1',
+ 'floating_ips': [
+ {'address': '1.2.3.4'},
+ ],
+ },
{'address': '172.19.0.2'},
],
},
@@ -543,6 +554,7 @@ class ServersTest(test.TestCase):
expected = {
'network_2': [
{'version': 4, 'addr': '172.19.0.1'},
+ {'version': 4, 'addr': '1.2.3.4'},
{'version': 4, 'addr': '172.19.0.2'},
],
}