Revision 95a213d4 snf-cyclades-app/synnefo/api/util.py
b/snf-cyclades-app/synnefo/api/util.py | ||
---|---|---|
206 | 206 |
disk_template, provider = disk_template.split("_", 1) |
207 | 207 |
return disk_template, provider |
208 | 208 |
|
209 |
''' |
|
209 |
|
|
210 | 210 |
def get_network(network_id, user_id, for_update=False, non_deleted=False): |
211 | 211 |
"""Return a Network instance or raise ItemNotFound.""" |
212 | 212 |
|
... | ... | |
222 | 222 |
return network |
223 | 223 |
except (ValueError, Network.DoesNotExist): |
224 | 224 |
raise faults.ItemNotFound('Network not found.') |
225 |
''' |
|
226 |
def get_network(network_id, user_id, public=False, for_update=False): |
|
225 |
|
|
226 |
|
|
227 |
def get_port(port_id, user_id, for_update=False): |
|
227 | 228 |
""" |
228 |
Return a Network instance or raise ItemNotFound. |
|
229 |
Return a NetworkInteface instance or raise ItemNotFound.
|
|
229 | 230 |
""" |
230 | 231 |
try: |
231 |
objects = Network.objects |
|
232 |
if for_update: |
|
233 |
objects = objects.select_for_update() |
|
234 |
if public: |
|
235 |
objects = objects.filter(public=True) |
|
236 |
return objects.get(Q(userid=user_id) | Q(public=True), id=network_id) |
|
237 |
except (ValueError, Network.DoesNotExist): |
|
238 |
raise faults.ItemNotFound('Network not found.') |
|
239 |
|
|
240 |
def get_port(port_id, user_id, for_update=False): |
|
241 |
""" |
|
242 |
Return a NetworkInteface instance or raise ItemNotFound. |
|
243 |
""" |
|
244 |
try: |
|
245 | 232 |
objects = NetworkInterface.objects |
246 | 233 |
if for_update: |
247 | 234 |
objects = objects.select_for_update() |
... | ... | |
249 | 236 |
port = objects.get(network__userid=user_id, id=port_id) |
250 | 237 |
|
251 | 238 |
if (port.device_owner != "vm") and for_update: |
252 |
raise api.faults.BadRequest('Can not update non vm port')
|
|
239 |
raise faults.BadRequest('Can not update non vm port') |
|
253 | 240 |
|
254 | 241 |
return port |
255 |
except (ValueError, NetworkInterface.DoesNotExist): |
|
256 |
raise faults.ItemNotFound('Port not found.') |
|
242 |
except (ValueError, NetworkInterface.DoesNotExist): |
|
243 |
raise faults.ItemNotFound('Port not found.') |
|
244 |
|
|
257 | 245 |
|
258 | 246 |
def get_floating_ip(user_id, ipv4, for_update=False): |
259 | 247 |
try: |
Also available in: Unified diff