Revision 08b079e2 snf-cyclades-app/synnefo/api/util.py
b/snf-cyclades-app/synnefo/api/util.py | ||
---|---|---|
55 | 55 |
from django.utils.cache import add_never_cache_headers |
56 | 56 |
|
57 | 57 |
from synnefo.api.faults import (Fault, BadRequest, BuildInProgress, |
58 |
ItemNotFound, ServiceUnavailable, Unauthorized) |
|
58 |
ItemNotFound, ServiceUnavailable, Unauthorized, BadMediaType)
|
|
59 | 59 |
from synnefo.db.models import (Flavor, VirtualMachine, VirtualMachineMetadata, |
60 | 60 |
Network, NetworkInterface) |
61 | 61 |
from synnefo.lib.astakos import get_user |
... | ... | |
214 | 214 |
except NetworkInterface.DoesNotExist: |
215 | 215 |
raise ItemNotFound('Server not connected to this network.') |
216 | 216 |
|
217 |
def get_nic_from_index(vm, nic_index): |
|
218 |
"""Returns the nic_index-th nic of a vm |
|
219 |
Error Response Codes: itemNotFound (404), badMediaType (415) |
|
220 |
""" |
|
221 |
matching_nics = vm.nics.filter(index=nic_index) |
|
222 |
matching_nics_len = len(matching_nics) |
|
223 |
if matching_nics_len < 1: |
|
224 |
raise ItemNotFound('NIC not found on VM') |
|
225 |
elif matching_nics_len > 1: |
|
226 |
raise BadMediaType('NIC index conflict on VM') |
|
227 |
nic = matching_nics[0] |
|
228 |
return nic |
|
217 | 229 |
|
218 | 230 |
def get_request_dict(request): |
219 | 231 |
"""Returns data sent by the client as a python dict.""" |
... | ... | |
321 | 333 |
raise Unauthorized('No user found.') |
322 | 334 |
if http_method and request.method != http_method: |
323 | 335 |
raise BadRequest('Method not allowed.') |
324 |
|
|
336 |
|
|
325 | 337 |
resp = func(request, *args, **kwargs) |
326 | 338 |
update_response_headers(request, resp) |
327 | 339 |
return resp |
... | ... | |
339 | 351 |
return render_fault(request, fault) |
340 | 352 |
return wrapper |
341 | 353 |
return decorator |
354 |
|
|
355 |
def construct_nic_id(nic): |
|
356 |
return "-".join(["nic", unicode(nic.machine.id), unicode(nic.index)]) |
Also available in: Unified diff