Revision 78c165cf
b/snf-cyclades-app/synnefo/api/servers.py | ||
---|---|---|
104 | 104 |
|
105 | 105 |
|
106 | 106 |
def nic_to_dict(nic): |
107 |
ip_type = "floating" if nic.is_floating_ip else "fixed" |
|
107 | 108 |
d = {'id': util.construct_nic_id(nic), |
108 | 109 |
'network_id': str(nic.network.id), |
109 | 110 |
'mac_address': nic.mac, |
110 | 111 |
'ipv4': nic.ipv4 if nic.ipv4 else None, |
111 |
'ipv6': nic.ipv6 if nic.ipv6 else None} |
|
112 |
'ipv6': nic.ipv6 if nic.ipv6 else None, |
|
113 |
'OS-EXT-IPS:type': ip_type} |
|
112 | 114 |
|
113 | 115 |
if nic.firewall_profile: |
114 | 116 |
d['firewallProfile'] = nic.firewall_profile |
115 | 117 |
return d |
116 | 118 |
|
117 | 119 |
|
118 |
def nics_to_addresses(nics):
|
|
120 |
def attachments_to_addresses(attachments):
|
|
119 | 121 |
addresses = {} |
120 |
for nic in nics:
|
|
122 |
for nic in attachments:
|
|
121 | 123 |
net_nics = [] |
122 | 124 |
net_nics.append({"version": 4, |
123 |
"addr": nic.ipv4,
|
|
124 |
"OS-EXT-IPS:type": "fixed"})
|
|
125 |
if nic.ipv6:
|
|
125 |
"addr": nic["ipv4"],
|
|
126 |
"OS-EXT-IPS:type": nic["OS-EXT-IPS:type"]})
|
|
127 |
if nic["ipv6"]:
|
|
126 | 128 |
net_nics.append({"version": 6, |
127 |
"addr": nic.ipv6,
|
|
128 |
"OS-EXT-IPS:type": "fixed"})
|
|
129 |
addresses[nic.network.id] = net_nics
|
|
129 |
"addr": nic["ipv6"],
|
|
130 |
"OS-EXT-IPS:type": nic["OS-EXT-IPS:type"]})
|
|
131 |
addresses[nic["network_id"]] = net_nics
|
|
130 | 132 |
return addresses |
131 | 133 |
|
132 | 134 |
|
... | ... | |
154 | 156 |
vm_nics = vm.nics.filter(state="ACTIVE").order_by("index") |
155 | 157 |
attachments = map(nic_to_dict, vm_nics) |
156 | 158 |
d['attachments'] = attachments |
157 |
d['addresses'] = nics_to_addresses(vm_nics)
|
|
159 |
d['addresses'] = attachments_to_addresses(attachments)
|
|
158 | 160 |
|
159 | 161 |
# include the latest vm diagnostic, if set |
160 | 162 |
diagnostic = vm.get_last_diagnostic() |
... | ... | |
432 | 434 |
log.debug('list_addresses %s', server_id) |
433 | 435 |
vm = util.get_vm(server_id, request.user_uniq) |
434 | 436 |
attachments = [nic_to_dict(nic) for nic in vm.nics.all()] |
435 |
addresses = nics_to_addresses(vm.nics.all())
|
|
437 |
addresses = attachments_to_addresses(attachments)
|
|
436 | 438 |
|
437 | 439 |
if request.serialization == 'xml': |
438 | 440 |
data = render_to_string('list_addresses.xml', {'addresses': addresses}) |
... | ... | |
456 | 458 |
machine = util.get_vm(server_id, request.user_uniq) |
457 | 459 |
network = util.get_network(network_id, request.user_uniq) |
458 | 460 |
nics = machine.nics.filter(network=network).all() |
459 |
addresses = nics_to_addresses(nics)
|
|
461 |
addresses = attachments_to_addresses(map(nic_to_dict, nics))
|
|
460 | 462 |
|
461 | 463 |
if request.serialization == 'xml': |
462 | 464 |
data = render_to_string('address.xml', {'addresses': addresses}) |
b/snf-cyclades-app/synnefo/api/test/floating_ips.py | ||
---|---|---|
300 | 300 |
ip1_after = FloatingIP.objects.get(id=ip1.id) |
301 | 301 |
self.assertEqual(ip1_after.machine, self.vm) |
302 | 302 |
self.assertTrue(ip1_after.in_use()) |
303 |
self.vm.nics.create(ipv4=ip1_after.ipv4, network=ip1_after.network, |
|
304 |
state="ACTIVE", index=0) |
|
305 |
response = self.get(SERVERS_URL + "/%s" % self.vm.id, |
|
306 |
self.vm.userid) |
|
307 |
self.assertSuccess(response) |
|
308 |
nic = json.loads(response.content)["server"]["attachments"][0] |
|
309 |
self.assertEqual(nic["OS-EXT-IPS:type"], "floating") |
|
303 | 310 |
|
304 | 311 |
@patch('synnefo.logic.rapi_pool.GanetiRapiClient') |
305 | 312 |
def test_remove_floating_ip(self, mock): |
b/snf-cyclades-app/synnefo/api/test/servers.py | ||
---|---|---|
142 | 142 |
self.assertEqual(api_nic['firewallProfile'], nic.firewall_profile) |
143 | 143 |
self.assertEqual(api_nic['ipv4'], nic.ipv4) |
144 | 144 |
self.assertEqual(api_nic['ipv6'], nic.ipv6) |
145 |
self.assertEqual(api_nic['OS-EXT-IPS:type'],"fixed") |
|
145 | 146 |
self.assertEqual(api_nic['id'], 'nic-%s-%s' % (db_vm.id, nic.index)) |
146 | 147 |
api_address = server["addresses"] |
147 | 148 |
self.assertEqual(api_address[str(net.id)], |
Also available in: Unified diff