Revision e57893cd
b/snf-cyclades-app/synnefo/api/floating_ips.py | ||
---|---|---|
133 | 133 |
" 'pool' attribute") |
134 | 134 |
|
135 | 135 |
try: |
136 |
network = Network.objects.get(public=True, deleted=False, id=pool) |
|
136 |
objects = Network.objects.select_for_update() |
|
137 |
network = objects.get(id=pool, public=True, deleted=False) |
|
137 | 138 |
except Network.DoesNotExist: |
138 | 139 |
raise faults.ItemNotFound("Pool '%s' does not exist." % pool) |
139 | 140 |
|
b/snf-cyclades-app/synnefo/api/management/commands/network-remove.py | ||
---|---|---|
51 | 51 |
self.stdout.write('Trying to remove network: %s\n' % str(network)) |
52 | 52 |
|
53 | 53 |
if network.machines.exists(): |
54 |
raise CommandError('Network is not empty. Can not delete') |
|
54 |
raise CommandError('Can not delete: Network has connected VMs.') |
|
55 |
if network.floating_ips.filter(deleted=False).exists(): |
|
56 |
raise CommandError("Can not delete: Network has reserved floating" |
|
57 |
" IP addresses.") |
|
55 | 58 |
|
56 | 59 |
network.action = 'DESTROY' |
57 | 60 |
network.save() |
b/snf-cyclades-app/synnefo/api/networks.py | ||
---|---|---|
306 | 306 |
if net.machines.all(): # Nics attached on network |
307 | 307 |
raise faults.NetworkInUse('Machines are connected to network.') |
308 | 308 |
|
309 |
if net.floating_ips.filter(deleted=False).exists(): |
|
310 |
raise faults.NetworkInUse("Network has allocated floating IP addresses") |
|
311 |
|
|
309 | 312 |
net.action = 'DESTROY' |
310 | 313 |
net.save() |
311 | 314 |
|
b/snf-cyclades-app/synnefo/api/test/floating_ips.py | ||
---|---|---|
38 | 38 |
from synnefo.db.models_factory import (FloatingIPFactory, NetworkFactory, |
39 | 39 |
VirtualMachineFactory, |
40 | 40 |
NetworkInterfaceFactory) |
41 |
from mock import patch |
|
41 |
from mock import patch, Mock
|
|
42 | 42 |
|
43 | 43 |
|
44 | 44 |
URL = "/api/v1.1/os-floating-ips" |
... | ... | |
184 | 184 |
ips_after = FloatingIP.objects.filter(id=ip.id) |
185 | 185 |
self.assertEqual(len(ips_after), 0) |
186 | 186 |
|
187 |
@patch("synnefo.logic.backend", Mock()) |
|
188 |
def test_delete_network_with_floating_ips(self): |
|
189 |
ip = FloatingIPFactory(machine=None) |
|
190 |
net = ip.network |
|
191 |
# Can not remove network with floating IPs |
|
192 |
with mocked_quotaholder(): |
|
193 |
response = self.delete("/api/v1.1/networks/%s" % net.id, |
|
194 |
net.userid) |
|
195 |
self.assertFault(response, 421, "networkInUse") |
|
196 |
# But we can with only deleted Floating Ips |
|
197 |
ip.deleted = True |
|
198 |
ip.save() |
|
199 |
with mocked_quotaholder(): |
|
200 |
response = self.delete("/api/v1.1/networks/%s" % net.id, |
|
201 |
net.userid) |
|
202 |
self.assertSuccess(response) |
|
203 |
|
|
187 | 204 |
|
188 | 205 |
POOLS_URL = "/api/v1.1/os-floating-ip-pools" |
189 | 206 |
|
b/snf-cyclades-app/synnefo/management/common.py | ||
---|---|---|
112 | 112 |
" available server IDs." % server_id) |
113 | 113 |
|
114 | 114 |
|
115 |
def get_network(network_id): |
|
115 |
def get_network(network_id, for_update=True):
|
|
116 | 116 |
"""Get a Network object by its ID. |
117 | 117 |
|
118 | 118 |
@type network_id: int or string |
... | ... | |
128 | 128 |
except Network.InvalidBackendIdError: |
129 | 129 |
raise CommandError("Invalid network ID: %s" % network_id) |
130 | 130 |
|
131 |
networks = Network.objects |
|
132 |
if for_update: |
|
133 |
networks = networks.select_for_update() |
|
131 | 134 |
try: |
132 |
return Network.objects.get(id=network_id)
|
|
135 |
return networks.get(id=network_id)
|
|
133 | 136 |
except Network.DoesNotExist: |
134 | 137 |
raise CommandError("Network with ID %s not found in DB." |
135 | 138 |
" Use snf-manage network-list to find out" |
Also available in: Unified diff