Revision 326c3ec8
b/snf-cyclades-app/synnefo/api/floating_ips.py | ||
---|---|---|
40 | 40 |
from snf_django.lib.api import faults, utils |
41 | 41 |
from synnefo.api import util |
42 | 42 |
from synnefo import quotas |
43 |
from synnefo.db.models import Network, FloatingIP, NetworkInterface
|
|
43 |
from synnefo.db.models import Network, IPAddress, NetworkInterface
|
|
44 | 44 |
|
45 | 45 |
|
46 | 46 |
from logging import getLogger |
... | ... | |
92 | 92 |
log.debug("list_floating_ips") |
93 | 93 |
|
94 | 94 |
userid = request.user_uniq |
95 |
floating_ips = FloatingIP.objects.filter(userid=userid).order_by("id")
|
|
95 |
floating_ips = IPAddress.objects.filter(userid=userid).order_by("id")
|
|
96 | 96 |
floating_ips = utils.filter_modified_since(request, objects=floating_ips) |
97 | 97 |
|
98 | 98 |
floating_ips = map(ip_to_dict, floating_ips) |
... | ... | |
109 | 109 |
"""Return information for a floating IP.""" |
110 | 110 |
userid = request.user_uniq |
111 | 111 |
try: |
112 |
floating_ip = FloatingIP.objects.get(id=floating_ip_id,
|
|
112 |
floating_ip = IPAddress.objects.get(id=floating_ip_id,
|
|
113 | 113 |
deleted=False, |
114 | 114 |
userid=userid) |
115 |
except FloatingIP.DoesNotExist:
|
|
115 |
except IPAddress.DoesNotExist:
|
|
116 | 116 |
raise faults.ItemNotFound("Floating IP '%s' does not exist" % |
117 | 117 |
floating_ip_id) |
118 | 118 |
request.serialization = "json" |
... | ... | |
155 | 155 |
else: |
156 | 156 |
# User specified an IP address. Check that it is not a used |
157 | 157 |
# floating IP |
158 |
if FloatingIP.objects.filter(network=network,
|
|
158 |
if IPAddress.objects.filter(network=network,
|
|
159 | 159 |
deleted=False, |
160 | 160 |
ipv4=address).exists(): |
161 | 161 |
msg = "Floating IP '%s' is reserved" % address |
... | ... | |
178 | 178 |
except NetworkInterface.DoesNotExist: |
179 | 179 |
msg = "Address '%s' is already in use" % address |
180 | 180 |
raise faults.Conflict(msg) |
181 |
floating_ip = FloatingIP.objects.create(ipv4=address, network=network,
|
|
181 |
floating_ip = IPAddress.objects.create(ipv4=address, network=network,
|
|
182 | 182 |
userid=userid, machine=machine) |
183 | 183 |
quotas.issue_and_accept_commission(floating_ip) |
184 | 184 |
except: |
... | ... | |
202 | 202 |
userid = request.user_uniq |
203 | 203 |
log.info("release_floating_ip '%s'. User '%s'.", floating_ip_id, userid) |
204 | 204 |
try: |
205 |
floating_ip = FloatingIP.objects.select_for_update()\
|
|
205 |
floating_ip = IPAddress.objects.select_for_update()\
|
|
206 | 206 |
.get(id=floating_ip_id, |
207 | 207 |
deleted=False, |
208 | 208 |
userid=userid) |
209 |
except FloatingIP.DoesNotExist:
|
|
209 |
except IPAddress.DoesNotExist:
|
|
210 | 210 |
raise faults.ItemNotFound("Floating IP '%s' does not exist" % |
211 | 211 |
floating_ip_id) |
212 | 212 |
|
b/snf-cyclades-app/synnefo/api/tests/floating_ips.py | ||
---|---|---|
34 | 34 |
import json |
35 | 35 |
|
36 | 36 |
from snf_django.utils.testing import BaseAPITest, mocked_quotaholder |
37 |
from synnefo.db.models import FloatingIP
|
|
38 |
from synnefo.db.models_factory import (FloatingIPFactory, NetworkFactory,
|
|
37 |
from synnefo.db.models import IPAddress
|
|
38 |
from synnefo.db.models_factory import (IPAddressFactory, NetworkFactory,
|
|
39 | 39 |
VirtualMachineFactory, |
40 | 40 |
NetworkInterfaceFactory, |
41 | 41 |
BackendNetworkFactory) |
... | ... | |
52 | 52 |
NETWORKS_URL = join_urls(compute_path, "networks") |
53 | 53 |
SERVERS_URL = join_urls(compute_path, "servers") |
54 | 54 |
|
55 |
FloatingIPPoolFactory = partial(NetworkFactory, public=True, deleted=False,
|
|
55 |
IPAddressPoolFactory = partial(NetworkFactory, public=True, deleted=False,
|
|
56 | 56 |
floating_ip_pool=True) |
57 | 57 |
|
58 | 58 |
|
59 |
class FloatingIPAPITest(BaseAPITest):
|
|
59 |
class IPAddressAPITest(BaseAPITest):
|
|
60 | 60 |
def test_no_floating_ip(self): |
61 | 61 |
response = self.get(URL) |
62 | 62 |
self.assertSuccess(response) |
63 | 63 |
self.assertEqual(json.loads(response.content)["floating_ips"], []) |
64 | 64 |
|
65 | 65 |
def test_list_ips(self): |
66 |
ip = FloatingIPFactory(userid="user1")
|
|
67 |
FloatingIPFactory(userid="user1", deleted=True)
|
|
66 |
ip = IPAddressFactory(userid="user1")
|
|
67 |
IPAddressFactory(userid="user1", deleted=True)
|
|
68 | 68 |
with mocked_quotaholder(): |
69 | 69 |
response = self.get(URL, "user1") |
70 | 70 |
self.assertSuccess(response) |
... | ... | |
75 | 75 |
str(ip.network.id)}) |
76 | 76 |
|
77 | 77 |
def test_get_ip(self): |
78 |
ip = FloatingIPFactory(userid="user1")
|
|
78 |
ip = IPAddressFactory(userid="user1")
|
|
79 | 79 |
with mocked_quotaholder(): |
80 | 80 |
response = self.get(URL + "/%s" % ip.id, "user1") |
81 | 81 |
self.assertSuccess(response) |
... | ... | |
86 | 86 |
str(ip.network.id)}) |
87 | 87 |
|
88 | 88 |
def test_wrong_user(self): |
89 |
ip = FloatingIPFactory(userid="user1")
|
|
89 |
ip = IPAddressFactory(userid="user1")
|
|
90 | 90 |
with mocked_quotaholder(): |
91 | 91 |
response = self.delete(URL + "/%s" % ip.id, "user2") |
92 | 92 |
self.assertItemNotFound(response) |
93 | 93 |
|
94 | 94 |
def test_deleted_ip(self): |
95 |
ip = FloatingIPFactory(userid="user1", deleted=True)
|
|
95 |
ip = IPAddressFactory(userid="user1", deleted=True)
|
|
96 | 96 |
with mocked_quotaholder(): |
97 | 97 |
response = self.delete(URL + "/%s" % ip.id, "user1") |
98 | 98 |
self.assertItemNotFound(response) |
99 | 99 |
|
100 | 100 |
def test_reserve(self): |
101 |
net = FloatingIPPoolFactory(userid="test_user",
|
|
101 |
net = IPAddressPoolFactory(userid="test_user",
|
|
102 | 102 |
subnet="192.168.2.0/24", |
103 | 103 |
gateway=None) |
104 | 104 |
request = {'pool': net.id} |
105 | 105 |
with mocked_quotaholder(): |
106 | 106 |
response = self.post(URL, "test_user", json.dumps(request), "json") |
107 | 107 |
self.assertSuccess(response) |
108 |
ip = FloatingIP.objects.get()
|
|
108 |
ip = IPAddress.objects.get()
|
|
109 | 109 |
self.assertEqual(ip.ipv4, "192.168.2.1") |
110 | 110 |
self.assertEqual(ip.machine, None) |
111 | 111 |
self.assertEqual(ip.network, net) |
... | ... | |
120 | 120 |
response = self.post(URL, "test_user", json.dumps({}), "json") |
121 | 121 |
self.assertFault(response, 413, "overLimit") |
122 | 122 |
# Full network |
123 |
FloatingIPPoolFactory(userid="test_user",
|
|
123 |
IPAddressPoolFactory(userid="test_user",
|
|
124 | 124 |
subnet="192.168.2.0/32", |
125 | 125 |
gateway=None) |
126 | 126 |
with mocked_quotaholder(): |
127 | 127 |
response = self.post(URL, "test_user", json.dumps({}), "json") |
128 | 128 |
self.assertFault(response, 413, "overLimit") |
129 | 129 |
# Success |
130 |
net2 = FloatingIPPoolFactory(userid="test_user",
|
|
130 |
net2 = IPAddressPoolFactory(userid="test_user",
|
|
131 | 131 |
subnet="192.168.2.0/24", |
132 | 132 |
gateway=None) |
133 | 133 |
with mocked_quotaholder(): |
134 | 134 |
response = self.post(URL, "test_user", json.dumps({}), "json") |
135 | 135 |
self.assertSuccess(response) |
136 |
ip = FloatingIP.objects.get()
|
|
136 |
ip = IPAddress.objects.get()
|
|
137 | 137 |
self.assertEqual(json.loads(response.content)["floating_ip"], |
138 | 138 |
{"instance_id": None, "ip": "192.168.2.1", |
139 | 139 |
"fixed_ip": None, "id": str(ip.id), |
140 | 140 |
"pool": str(net2.id)}) |
141 | 141 |
|
142 | 142 |
def test_reserve_full(self): |
143 |
net = FloatingIPPoolFactory(userid="test_user",
|
|
143 |
net = IPAddressPoolFactory(userid="test_user",
|
|
144 | 144 |
subnet="192.168.2.0/32") |
145 | 145 |
request = {'pool': net.id} |
146 | 146 |
with mocked_quotaholder(): |
... | ... | |
148 | 148 |
self.assertEqual(response.status_code, 413) |
149 | 149 |
|
150 | 150 |
def test_reserve_with_address(self): |
151 |
net = FloatingIPPoolFactory(userid="test_user",
|
|
151 |
net = IPAddressPoolFactory(userid="test_user",
|
|
152 | 152 |
subnet="192.168.2.0/24") |
153 | 153 |
request = {'pool': net.id, "address": "192.168.2.10"} |
154 | 154 |
with mocked_quotaholder(): |
155 | 155 |
response = self.post(URL, "test_user", json.dumps(request), "json") |
156 | 156 |
self.assertSuccess(response) |
157 |
ip = FloatingIP.objects.get()
|
|
157 |
ip = IPAddress.objects.get()
|
|
158 | 158 |
self.assertEqual(json.loads(response.content)["floating_ip"], |
159 | 159 |
{"instance_id": None, "ip": "192.168.2.10", |
160 | 160 |
"fixed_ip": None, "id": str(ip.id), "pool": |
161 | 161 |
str(net.id)}) |
162 | 162 |
|
163 | 163 |
# Already reserved |
164 |
FloatingIPFactory(network=net, ipv4="192.168.2.3")
|
|
164 |
IPAddressFactory(network=net, ipv4="192.168.2.3")
|
|
165 | 165 |
request = {'pool': net.id, "address": "192.168.2.3"} |
166 | 166 |
with mocked_quotaholder(): |
167 | 167 |
response = self.post(URL, "test_user", json.dumps(request), "json") |
... | ... | |
194 | 194 |
self.assertBadRequest(response) |
195 | 195 |
|
196 | 196 |
def test_release_in_use(self): |
197 |
ip = FloatingIPFactory()
|
|
197 |
ip = IPAddressFactory()
|
|
198 | 198 |
vm = ip.machine |
199 | 199 |
vm.operstate = "ACTIVE" |
200 | 200 |
vm.userid = ip.userid |
... | ... | |
218 | 218 |
self.assertFault(response, 409, "conflict") |
219 | 219 |
|
220 | 220 |
def test_release(self): |
221 |
ip = FloatingIPFactory(machine=None)
|
|
221 |
ip = IPAddressFactory(machine=None)
|
|
222 | 222 |
with mocked_quotaholder(): |
223 | 223 |
response = self.delete(URL + "/%s" % ip.id, ip.userid) |
224 | 224 |
self.assertSuccess(response) |
225 |
ips_after = FloatingIP.objects.filter(id=ip.id)
|
|
225 |
ips_after = IPAddress.objects.filter(id=ip.id)
|
|
226 | 226 |
self.assertEqual(len(ips_after), 0) |
227 | 227 |
|
228 | 228 |
@patch("synnefo.logic.backend", Mock()) |
229 | 229 |
def test_delete_network_with_floating_ips(self): |
230 |
ip = FloatingIPFactory(machine=None, network__flavor="IP_LESS_ROUTED")
|
|
230 |
ip = IPAddressFactory(machine=None, network__flavor="IP_LESS_ROUTED")
|
|
231 | 231 |
net = ip.network |
232 | 232 |
# Can not remove network with floating IPs |
233 | 233 |
with mocked_quotaholder(): |
... | ... | |
246 | 246 |
POOLS_URL = join_urls(compute_path, "os-floating-ip-pools") |
247 | 247 |
|
248 | 248 |
|
249 |
class FloatingIPPoolsAPITest(BaseAPITest):
|
|
249 |
class IPAddressPoolsAPITest(BaseAPITest):
|
|
250 | 250 |
def test_no_pool(self): |
251 | 251 |
response = self.get(POOLS_URL) |
252 | 252 |
self.assertSuccess(response) |
253 | 253 |
self.assertEqual(json.loads(response.content)["floating_ip_pools"], []) |
254 | 254 |
|
255 | 255 |
def test_list_pools(self): |
256 |
net = FloatingIPPoolFactory(subnet="192.168.0.0/30",
|
|
256 |
net = IPAddressPoolFactory(subnet="192.168.0.0/30",
|
|
257 | 257 |
gateway="192.168.0.1") |
258 | 258 |
NetworkFactory(public=True, deleted=True) |
259 | 259 |
NetworkFactory(public=False, deleted=False) |
... | ... | |
264 | 264 |
[{"name": str(net.id), "size": 4, "free": 1}]) |
265 | 265 |
|
266 | 266 |
|
267 |
class FloatingIPActionsTest(BaseAPITest):
|
|
267 |
class IPAddressActionsTest(BaseAPITest):
|
|
268 | 268 |
def setUp(self): |
269 | 269 |
vm = VirtualMachineFactory() |
270 | 270 |
vm.operstate = "ACTIVE" |
... | ... | |
289 | 289 |
self.assertItemNotFound(response) |
290 | 290 |
# In use |
291 | 291 |
vm1 = VirtualMachineFactory() |
292 |
ip1 = FloatingIPFactory(userid=self.vm.userid, machine=vm1)
|
|
292 |
ip1 = IPAddressFactory(userid=self.vm.userid, machine=vm1)
|
|
293 | 293 |
BackendNetworkFactory(network=ip1.network, backend=vm1.backend, |
294 | 294 |
operstate='ACTIVE') |
295 | 295 |
request = {"addFloatingIp": {"address": ip1.ipv4}} |
296 | 296 |
response = self.post(url, self.vm.userid, json.dumps(request), "json") |
297 | 297 |
self.assertFault(response, 409, "conflict") |
298 | 298 |
# Success |
299 |
ip1 = FloatingIPFactory(userid=self.vm.userid, machine=None)
|
|
299 |
ip1 = IPAddressFactory(userid=self.vm.userid, machine=None)
|
|
300 | 300 |
BackendNetworkFactory(network=ip1.network, backend=self.vm.backend, |
301 | 301 |
operstate='ACTIVE') |
302 | 302 |
request = {"addFloatingIp": {"address": ip1.ipv4}} |
303 | 303 |
mock().ModifyInstance.return_value = 1 |
304 | 304 |
response = self.post(url, self.vm.userid, json.dumps(request), "json") |
305 | 305 |
self.assertEqual(response.status_code, 202) |
306 |
ip1_after = FloatingIP.objects.get(id=ip1.id)
|
|
306 |
ip1_after = IPAddress.objects.get(id=ip1.id)
|
|
307 | 307 |
self.assertEqual(ip1_after.machine, self.vm) |
308 | 308 |
self.assertTrue(ip1_after.in_use()) |
309 | 309 |
nic = self.vm.nics.get(ipv4=ip1_after.ipv4) |
... | ... | |
323 | 323 |
response = self.post(url, self.vm.userid, json.dumps(request), "json") |
324 | 324 |
self.assertItemNotFound(response) |
325 | 325 |
# Not In Use |
326 |
ip1 = FloatingIPFactory(userid=self.vm.userid, machine=None)
|
|
326 |
ip1 = IPAddressFactory(userid=self.vm.userid, machine=None)
|
|
327 | 327 |
request = {"removeFloatingIp": {"address": ip1.ipv4}} |
328 | 328 |
response = self.post(url, self.vm.userid, json.dumps(request), "json") |
329 | 329 |
self.assertItemNotFound(response) |
330 | 330 |
# Success |
331 |
ip1 = FloatingIPFactory(userid=self.vm.userid, machine=self.vm)
|
|
331 |
ip1 = IPAddressFactory(userid=self.vm.userid, machine=self.vm)
|
|
332 | 332 |
NetworkInterfaceFactory(machine=self.vm, ipv4=ip1.ipv4) |
333 | 333 |
request = {"removeFloatingIp": {"address": ip1.ipv4}} |
334 | 334 |
mock().ModifyInstance.return_value = 2 |
335 | 335 |
response = self.post(url, self.vm.userid, json.dumps(request), "json") |
336 | 336 |
self.assertEqual(response.status_code, 202) |
337 | 337 |
# Yet used. Wait for the callbacks |
338 |
ip1_after = FloatingIP.objects.get(id=ip1.id)
|
|
338 |
ip1_after = IPAddress.objects.get(id=ip1.id)
|
|
339 | 339 |
self.assertEqual(ip1_after.machine, self.vm) |
340 | 340 |
self.assertTrue(ip1_after.in_use()) |
b/snf-cyclades-app/synnefo/api/tests/servers.py | ||
---|---|---|
37 | 37 |
from snf_django.utils.testing import (BaseAPITest, mocked_quotaholder, |
38 | 38 |
override_settings) |
39 | 39 |
from synnefo.db.models import (VirtualMachine, VirtualMachineMetadata, |
40 |
FloatingIP)
|
|
40 |
IPAddress)
|
|
41 | 41 |
from synnefo.db import models_factory as mfactory |
42 | 42 |
from synnefo.logic.utils import get_rsapi_state |
43 | 43 |
from synnefo.cyclades_settings import cyclades_services |
... | ... | |
468 | 468 |
mfactory.BackendNetworkFactory(network=network, |
469 | 469 |
backend=self.backend, |
470 | 470 |
operstate="ACTIVE") |
471 |
fp1 = mfactory.FloatingIPFactory(ipv4="10.0.0.2",
|
|
471 |
fp1 = mfactory.IPAddressFactory(ipv4="10.0.0.2",
|
|
472 | 472 |
userid="test_user", |
473 | 473 |
network=network, machine=None) |
474 |
fp2 = mfactory.FloatingIPFactory(ipv4="10.0.0.3", network=network,
|
|
474 |
fp2 = mfactory.IPAddressFactory(ipv4="10.0.0.3", network=network,
|
|
475 | 475 |
userid="test_user", |
476 | 476 |
machine=None) |
477 | 477 |
request["server"]["floating_ips"] = [fp1.ipv4, fp2.ipv4] |
... | ... | |
483 | 483 |
self.assertEqual(response.status_code, 202) |
484 | 484 |
api_server = json.loads(response.content)['server'] |
485 | 485 |
vm = VirtualMachine.objects.get(id=api_server["id"]) |
486 |
fp1 = FloatingIP.objects.get(id=fp1.id)
|
|
487 |
fp2 = FloatingIP.objects.get(id=fp2.id)
|
|
486 |
fp1 = IPAddress.objects.get(id=fp1.id)
|
|
487 |
fp2 = IPAddress.objects.get(id=fp2.id)
|
|
488 | 488 |
self.assertEqual(fp1.machine, vm) |
489 | 489 |
self.assertEqual(fp2.machine, vm) |
490 | 490 |
name, args, kwargs = mrapi().CreateInstance.mock_calls[2] |
b/snf-cyclades-app/synnefo/api/util.py | ||
---|---|---|
49 | 49 |
from synnefo.db.models import (Flavor, VirtualMachine, VirtualMachineMetadata, |
50 | 50 |
Network, BackendNetwork, NetworkInterface, |
51 | 51 |
BridgePoolTable, MacPrefixPoolTable, Backend, |
52 |
FloatingIP)
|
|
52 |
IPAddress)
|
|
53 | 53 |
from synnefo.db.pools import EmptyPool |
54 | 54 |
|
55 | 55 |
from synnefo.plankton.utils import image_backend |
... | ... | |
226 | 226 |
|
227 | 227 |
def get_floating_ip(user_id, ipv4, for_update=False): |
228 | 228 |
try: |
229 |
objects = FloatingIP.objects
|
|
229 |
objects = IPAddress.objects
|
|
230 | 230 |
if for_update: |
231 | 231 |
objects = objects.select_for_update() |
232 | 232 |
return objects.get(userid=user_id, ipv4=ipv4, deleted=False) |
233 |
except FloatingIP.DoesNotExist:
|
|
233 |
except IPAddress.DoesNotExist:
|
|
234 | 234 |
raise faults.ItemNotFound("Floating IP does not exist.") |
235 | 235 |
|
236 | 236 |
|
b/snf-cyclades-app/synnefo/logic/backend.py | ||
---|---|---|
35 | 35 |
from datetime import datetime, timedelta |
36 | 36 |
|
37 | 37 |
from synnefo.db.models import (Backend, VirtualMachine, Network, |
38 |
IPAddress, |
|
38 | 39 |
BackendNetwork, BACKEND_STATUSES, |
39 | 40 |
pooled_rapi_client, VirtualMachineDiagnostic, |
40 |
Flavor, FloatingIP)
|
|
41 |
Flavor) |
|
41 | 42 |
from synnefo.logic import utils |
42 | 43 |
from synnefo import quotas |
43 | 44 |
from synnefo.api.util import release_resource |
... | ... | |
339 | 340 |
|
340 | 341 |
if nic.ipv4: |
341 | 342 |
if nic.ip_type == "FLOATING": |
342 |
FloatingIP.objects.filter(machine=nic.machine_id,
|
|
343 |
network=nic.network_id,
|
|
344 |
ipv4=nic.ipv4).update(machine=None)
|
|
343 |
IPAddress.objects.filter(machine=nic.machine_id,
|
|
344 |
network=nic.network_id, |
|
345 |
ipv4=nic.ipv4).update(machine=None) |
|
345 | 346 |
else: |
346 | 347 |
nic.network.release_address(nic.ipv4) |
347 | 348 |
|
b/snf-cyclades-app/synnefo/logic/management/commands/floating-ip-list.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 |
from synnefo.db.models import FloatingIP
|
|
34 |
from synnefo.db.models import IPAddress
|
|
35 | 35 |
from snf_django.management.commands import ListCommand |
36 | 36 |
from synnefo.settings import CYCLADES_SERVICE_TOKEN, ASTAKOS_BASE_URL |
37 | 37 |
from logging import getLogger |
... | ... | |
40 | 40 |
|
41 | 41 |
class Command(ListCommand): |
42 | 42 |
help = "List Floating IPs" |
43 |
object_class = FloatingIP
|
|
43 |
object_class = IPAddress
|
|
44 | 44 |
deleted_field = "deleted" |
45 | 45 |
user_uuid_field = "userid" |
46 | 46 |
astakos_url = ASTAKOS_BASE_URL |
b/snf-cyclades-app/synnefo/logic/servers.py | ||
---|---|---|
13 | 13 |
from synnefo.logic import backend |
14 | 14 |
from synnefo.logic.backend_allocator import BackendAllocator |
15 | 15 |
from synnefo.db.models import (NetworkInterface, VirtualMachine, Network, |
16 |
VirtualMachineMetadata, FloatingIP)
|
|
16 |
VirtualMachineMetadata, IPAddress)
|
|
17 | 17 |
|
18 | 18 |
from vncauthproxy.client import request_forwarding as request_vnc_forwarding |
19 | 19 |
|
... | ... | |
441 | 441 |
def add_floating_ip_to_vm(vm, address): |
442 | 442 |
"""Get a floating IP by it's address and add it to VirtualMachine. |
443 | 443 |
|
444 |
Helper function for looking up a FloatingIP by it's address and associating
|
|
444 |
Helper function for looking up a IPAddress by it's address and associating
|
|
445 | 445 |
it with a VirtualMachine object (without adding the NIC in the Ganeti |
446 | 446 |
backend!). This function also checks if the floating IP is currently used |
447 | 447 |
by any instance and if it is available in the Backend that hosts the VM. |
... | ... | |
451 | 451 |
try: |
452 | 452 |
# Get lock in VM, to guarantee that floating IP will only by assigned |
453 | 453 |
# once |
454 |
floating_ip = FloatingIP.objects.select_for_update()\
|
|
454 |
floating_ip = IPAddress.objects.select_for_update()\
|
|
455 | 455 |
.get(userid=user_id, ipv4=address, |
456 | 456 |
deleted=False) |
457 |
except FloatingIP.DoesNotExist:
|
|
457 |
except IPAddress.DoesNotExist:
|
|
458 | 458 |
raise faults.ItemNotFound("Floating IP '%s' does not exist" % address) |
459 | 459 |
|
460 | 460 |
if floating_ip.in_use(): |
... | ... | |
476 | 476 |
def remove_floating_ip(vm, address): |
477 | 477 |
user_id = vm.userid |
478 | 478 |
try: |
479 |
floating_ip = FloatingIP.objects.select_for_update()\
|
|
479 |
floating_ip = IPAddress.objects.select_for_update()\
|
|
480 | 480 |
.get(userid=user_id, ipv4=address, |
481 | 481 |
deleted=False, machine=vm) |
482 |
except FloatingIP.DoesNotExist:
|
|
482 |
except IPAddress.DoesNotExist:
|
|
483 | 483 |
raise faults.ItemNotFound("Floating IP '%s' does not exist" % address) |
484 | 484 |
|
485 | 485 |
try: |
b/snf-cyclades-app/synnefo/logic/tests/callbacks.py | ||
---|---|---|
34 | 34 |
|
35 | 35 |
from django.test import TestCase |
36 | 36 |
|
37 |
from synnefo.db.models import (VirtualMachine, FloatingIP, BackendNetwork,
|
|
37 |
from synnefo.db.models import (VirtualMachine, IPAddress, BackendNetwork,
|
|
38 | 38 |
Network, BridgePoolTable, MacPrefixPoolTable) |
39 | 39 |
from synnefo.db import models_factory as mfactory |
40 | 40 |
from synnefo.lib.utils import split_time |
... | ... | |
151 | 151 |
self.assertTrue(nic.network.get_pool().is_available(nic.ipv4)) |
152 | 152 |
vm2 = mfactory.VirtualMachineFactory() |
153 | 153 |
network = mfactory.NetworkFactory(floating_ip_pool=True) |
154 |
fp1 = mfactory.FloatingIPFactory(machine=vm2, network=network)
|
|
155 |
fp2 = mfactory.FloatingIPFactory(machine=vm2, network=network)
|
|
154 |
fp1 = mfactory.IPAddressFactory(machine=vm2, network=network)
|
|
155 |
fp2 = mfactory.IPAddressFactory(machine=vm2, network=network)
|
|
156 | 156 |
mfactory.NetworkInterfaceFactory(machine=vm2, network=network, |
157 | 157 |
ipv4=fp1.ipv4) |
158 | 158 |
mfactory.NetworkInterfaceFactory(machine=vm2, network=network, |
... | ... | |
169 | 169 |
db_vm = VirtualMachine.objects.get(id=vm.id) |
170 | 170 |
self.assertEqual(db_vm.operstate, 'DESTROYED') |
171 | 171 |
self.assertTrue(db_vm.deleted) |
172 |
self.assertEqual(FloatingIP.objects.get(id=fp1.id).machine, None)
|
|
173 |
self.assertEqual(FloatingIP.objects.get(id=fp2.id).machine, None)
|
|
172 |
self.assertEqual(IPAddress.objects.get(id=fp1.id).machine, None)
|
|
173 |
self.assertEqual(IPAddress.objects.get(id=fp2.id).machine, None)
|
|
174 | 174 |
pool = network.get_pool() |
175 | 175 |
# Test that floating ips are not released |
176 | 176 |
self.assertFalse(pool.is_available(fp1.ipv4)) |
b/snf-cyclades-app/synnefo/quotas/__init__.py | ||
---|---|---|
32 | 32 |
|
33 | 33 |
from snf_django.lib.api import faults |
34 | 34 |
from synnefo.db.models import (QuotaHolderSerial, VirtualMachine, Network, |
35 |
FloatingIP)
|
|
35 |
IPAddress)
|
|
36 | 36 |
|
37 | 37 |
from synnefo.settings import (CYCLADES_SERVICE_TOKEN as ASTAKOS_TOKEN, |
38 | 38 |
ASTAKOS_BASE_URL) |
... | ... | |
297 | 297 |
'cyclades.active_ram': 1048576 * flavor.ram} |
298 | 298 |
elif isinstance(resource, Network): |
299 | 299 |
return {"cyclades.network.private": 1} |
300 |
elif isinstance(resource, FloatingIP):
|
|
300 |
elif isinstance(resource, IPAddress):
|
|
301 | 301 |
return {"cyclades.floating_ip": 1} |
302 | 302 |
else: |
303 | 303 |
raise ValueError("Unknown Resource '%s'" % resource) |
b/snf-cyclades-app/synnefo/quotas/tests.py | ||
---|---|---|
97 | 97 |
self.assertEqual(holdings["user2"], user_holdings["user2"]) |
98 | 98 |
|
99 | 99 |
def test_floating_ip_holdings(self): |
100 |
mfactory.FloatingIPFactory(userid="user1")
|
|
101 |
mfactory.FloatingIPFactory(userid="user1")
|
|
102 |
mfactory.FloatingIPFactory(userid="user2")
|
|
103 |
mfactory.FloatingIPFactory(userid="user3")
|
|
100 |
mfactory.IPAddressFactory(userid="user1")
|
|
101 |
mfactory.IPAddressFactory(userid="user1")
|
|
102 |
mfactory.IPAddressFactory(userid="user2")
|
|
103 |
mfactory.IPAddressFactory(userid="user3")
|
|
104 | 104 |
holdings = util.get_db_holdings() |
105 | 105 |
self.assertEqual(holdings["user1"]["cyclades.floating_ip"], 2) |
106 | 106 |
self.assertEqual(holdings["user2"]["cyclades.floating_ip"], 1) |
b/snf-cyclades-app/synnefo/quotas/util.py | ||
---|---|---|
33 | 33 |
|
34 | 34 |
from django.db.models import Sum, Count, Q |
35 | 35 |
|
36 |
from synnefo.db.models import VirtualMachine, Network, FloatingIP
|
|
36 |
from synnefo.db.models import VirtualMachine, Network, IPAddress
|
|
37 | 37 |
from synnefo.quotas import Quotaholder, ASTAKOS_TOKEN |
38 | 38 |
|
39 | 39 |
|
... | ... | |
43 | 43 |
|
44 | 44 |
vms = VirtualMachine.objects.filter(deleted=False) |
45 | 45 |
networks = Network.objects.filter(deleted=False) |
46 |
floating_ips = FloatingIP.objects.filter(deleted=False)
|
|
46 |
floating_ips = IPAddress.objects.filter(deleted=False)
|
|
47 | 47 |
|
48 | 48 |
if user is not None: |
49 | 49 |
vms = vms.filter(userid=user) |
Also available in: Unified diff