Revision 495e2be8 snf-cyclades-app/synnefo/api/util.py
b/snf-cyclades-app/synnefo/api/util.py | ||
---|---|---|
49 | 49 |
from synnefo.db.models import (Flavor, VirtualMachine, VirtualMachineMetadata, |
50 | 50 |
Network, NetworkInterface, SecurityGroup, |
51 | 51 |
BridgePoolTable, MacPrefixPoolTable, IPAddress, |
52 |
IPPoolTable, Subnet)
|
|
52 |
IPPoolTable) |
|
53 | 53 |
from synnefo.db import pools |
54 | 54 |
|
55 | 55 |
from synnefo.plankton.utils import image_backend |
... | ... | |
226 | 226 |
raise faults.ItemNotFound('Network %s not found.' % network_id) |
227 | 227 |
|
228 | 228 |
|
229 |
def get_subnet(subnet_id, user_id, for_update=False, public=True, |
|
230 |
non_deleted=False): |
|
231 |
"""Return a Subnet instance or raise ItemNotFound.""" |
|
232 |
|
|
233 |
try: |
|
234 |
subnet_id = int(subnet_id) |
|
235 |
objects = Subnet.objects |
|
236 |
if for_update: |
|
237 |
objects = objects.select_for_update() |
|
238 |
if public: |
|
239 |
subnet = objects.get(Q(network__userid=user_id) | |
|
240 |
Q(network__public=True), id=subnet_id) |
|
241 |
else: |
|
242 |
subnet = objects.get(network__userid=user_id, id=subnet_id) |
|
243 |
if non_deleted and subnet.deleted: |
|
244 |
raise faults.BadRequest("Subnet has been deleted.") |
|
245 |
return subnet |
|
246 |
except (ValueError, Subnet.DoesNotExist): |
|
247 |
raise faults.ItemNotFound('Subnet %s not found.' % subnet_id) |
|
248 |
|
|
249 |
|
|
250 | 229 |
def get_port(port_id, user_id, for_update=False): |
251 | 230 |
""" |
252 | 231 |
Return a NetworkInteface instance or raise ItemNotFound. |
... | ... | |
268 | 247 |
except (ValueError, NetworkInterface.DoesNotExist): |
269 | 248 |
raise faults.ItemNotFound('Port not found.') |
270 | 249 |
|
271 |
|
|
272 | 250 |
def get_security_group(sg_id): |
273 | 251 |
try: |
274 | 252 |
sg = SecurityGroup.objects.get(id=sg_id) |
... | ... | |
276 | 254 |
except (ValueError, SecurityGroup.DoesNotExist): |
277 | 255 |
raise faults.ItemNotFound("Not valid security group") |
278 | 256 |
|
279 |
|
|
280 | 257 |
def get_floating_ip_by_address(userid, address, for_update=False): |
281 | 258 |
try: |
282 | 259 |
objects = IPAddress.objects |
Also available in: Unified diff