Revision 14402edc snf-cyclades-app/synnefo/api/servers.py
b/snf-cyclades-app/synnefo/api/servers.py | ||
---|---|---|
447 | 447 |
req = utils.get_request_dict(request) |
448 | 448 |
log.info('update_server_name %s %s', server_id, req) |
449 | 449 |
|
450 |
try: |
|
451 |
name = req['server']['name'] |
|
452 |
except (TypeError, KeyError): |
|
453 |
raise faults.BadRequest("Malformed request") |
|
450 |
req = utils.get_attribute(req, "server", attr_type=dict, required=True) |
|
451 |
name = utils.get_attribute(req, "name", attr_type=basestring, |
|
452 |
required=True) |
|
454 | 453 |
|
455 | 454 |
vm = util.get_vm(server_id, request.user_uniq, for_update=True, |
456 | 455 |
non_suspended=True) |
... | ... | |
500 | 499 |
req = utils.get_request_dict(request) |
501 | 500 |
log.debug('server_action %s %s', server_id, req) |
502 | 501 |
|
503 |
if len(req) != 1: |
|
502 |
if not isinstance(req, dict) and len(req) != 1:
|
|
504 | 503 |
raise faults.BadRequest("Malformed request") |
505 | 504 |
|
506 | 505 |
# Do not allow any action on deleted or suspended VMs |
... | ... | |
508 | 507 |
non_deleted=True, non_suspended=True) |
509 | 508 |
|
510 | 509 |
action = req.keys()[0] |
510 |
if not isinstance(action, basestring): |
|
511 |
raise faults.BadRequest("Malformed Request. Invalid action.") |
|
511 | 512 |
|
512 | 513 |
if key_to_action(action) not in [x[0] for x in VirtualMachine.ACTIONS]: |
513 | 514 |
if action not in ARBITRARY_ACTIONS: |
514 | 515 |
raise faults.BadRequest("Action %s not supported" % action) |
515 |
action_args = req[action] |
|
516 |
|
|
517 |
if not isinstance(action_args, dict): |
|
518 |
raise faults.BadRequest("Invalid argument") |
|
516 |
action_args = utils.get_attribute(req, action, required=True, |
|
517 |
attr_type=dict) |
|
519 | 518 |
|
520 | 519 |
return server_actions[action](request, vm, action_args) |
521 | 520 |
|
... | ... | |
530 | 529 |
# overLimit (413) |
531 | 530 |
|
532 | 531 |
log.debug('list_addresses %s', server_id) |
533 |
vm = util.get_vm(server_id, request.user_uniq, prefetch_related="nics__ips") |
|
532 |
vm = util.get_vm(server_id, request.user_uniq, |
|
533 |
prefetch_related="nics__ips") |
|
534 | 534 |
attachments = [nic_to_attachments(nic) |
535 | 535 |
for nic in vm.nics.filter(state="ACTIVE")] |
536 | 536 |
addresses = attachments_to_addresses(attachments) |
... | ... | |
598 | 598 |
req = utils.get_request_dict(request) |
599 | 599 |
log.info('update_server_metadata %s %s', server_id, req) |
600 | 600 |
vm = util.get_vm(server_id, request.user_uniq, non_suspended=True) |
601 |
try: |
|
602 |
metadata = req['metadata'] |
|
603 |
assert isinstance(metadata, dict) |
|
604 |
except (KeyError, AssertionError): |
|
605 |
raise faults.BadRequest("Malformed request") |
|
601 |
metadata = utils.get_attribute(req, "metadata", required=True, |
|
602 |
attr_type=dict) |
|
606 | 603 |
|
607 | 604 |
for key, val in metadata.items(): |
605 |
if not isinstance(key, (basestring, int)) or\ |
|
606 |
not isinstance(val, (basestring, int)): |
|
607 |
raise faults.BadRequest("Malformed Request. Invalid metadata.") |
|
608 | 608 |
meta, created = vm.metadata.get_or_create(meta_key=key) |
609 | 609 |
meta.meta_value = val |
610 | 610 |
meta.save() |
Also available in: Unified diff