Commit 5d599f0c authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Export OS-EXT-IPS:type for floating IPs.

Cyclades API should return "floating" for the OS-EXT-IPS:type attribute.
parent 9f6b9834
......@@ -104,29 +104,31 @@ def metadata_item_demux(request, server_id, key):
def nic_to_dict(nic):
ip_type = "floating" if nic.is_floating_ip else "fixed"
d = {'id': util.construct_nic_id(nic),
'network_id': str(nic.network.id),
'mac_address': nic.mac,
'ipv4': nic.ipv4 if nic.ipv4 else None,
'ipv6': nic.ipv6 if nic.ipv6 else None}
'ipv6': nic.ipv6 if nic.ipv6 else None,
'OS-EXT-IPS:type': ip_type}
if nic.firewall_profile:
d['firewallProfile'] = nic.firewall_profile
return d
def nics_to_addresses(nics):
def attachments_to_addresses(attachments):
addresses = {}
for nic in nics:
for nic in attachments:
net_nics = []
net_nics.append({"version": 4,
"addr": nic.ipv4,
"OS-EXT-IPS:type": "fixed"})
if nic.ipv6:
"addr": nic["ipv4"],
"OS-EXT-IPS:type": nic["OS-EXT-IPS:type"]})
if nic["ipv6"]:
net_nics.append({"version": 6,
"addr": nic.ipv6,
"OS-EXT-IPS:type": "fixed"})
addresses[nic.network.id] = net_nics
"addr": nic["ipv6"],
"OS-EXT-IPS:type": nic["OS-EXT-IPS:type"]})
addresses[nic["network_id"]] = net_nics
return addresses
......@@ -154,7 +156,7 @@ def vm_to_dict(vm, detail=False):
vm_nics = vm.nics.filter(state="ACTIVE").order_by("index")
attachments = map(nic_to_dict, vm_nics)
d['attachments'] = attachments
d['addresses'] = nics_to_addresses(vm_nics)
d['addresses'] = attachments_to_addresses(attachments)
# include the latest vm diagnostic, if set
diagnostic = vm.get_last_diagnostic()
......@@ -432,7 +434,7 @@ def list_addresses(request, server_id):
log.debug('list_addresses %s', server_id)
vm = util.get_vm(server_id, request.user_uniq)
attachments = [nic_to_dict(nic) for nic in vm.nics.all()]
addresses = nics_to_addresses(vm.nics.all())
addresses = attachments_to_addresses(attachments)
if request.serialization == 'xml':
data = render_to_string('list_addresses.xml', {'addresses': addresses})
......@@ -456,7 +458,7 @@ def list_addresses_by_network(request, server_id, network_id):
machine = util.get_vm(server_id, request.user_uniq)
network = util.get_network(network_id, request.user_uniq)
nics = machine.nics.filter(network=network).all()
addresses = nics_to_addresses(nics)
addresses = attachments_to_addresses(map(nic_to_dict, nics))
if request.serialization == 'xml':
data = render_to_string('address.xml', {'addresses': addresses})
......
......@@ -300,6 +300,13 @@ class FloatingIPActionsTest(BaseAPITest):
ip1_after = FloatingIP.objects.get(id=ip1.id)
self.assertEqual(ip1_after.machine, self.vm)
self.assertTrue(ip1_after.in_use())
self.vm.nics.create(ipv4=ip1_after.ipv4, network=ip1_after.network,
state="ACTIVE", index=0)
response = self.get(SERVERS_URL + "/%s" % self.vm.id,
self.vm.userid)
self.assertSuccess(response)
nic = json.loads(response.content)["server"]["attachments"][0]
self.assertEqual(nic["OS-EXT-IPS:type"], "floating")
@patch('synnefo.logic.rapi_pool.GanetiRapiClient')
def test_remove_floating_ip(self, mock):
......
......@@ -142,6 +142,7 @@ class ServerAPITest(ComputeAPITest):
self.assertEqual(api_nic['firewallProfile'], nic.firewall_profile)
self.assertEqual(api_nic['ipv4'], nic.ipv4)
self.assertEqual(api_nic['ipv6'], nic.ipv6)
self.assertEqual(api_nic['OS-EXT-IPS:type'],"fixed")
self.assertEqual(api_nic['id'], 'nic-%s-%s' % (db_vm.id, nic.index))
api_address = server["addresses"]
self.assertEqual(api_address[str(net.id)],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment