Revision e221ade2 snf-cyclades-app/synnefo/api/servers.py

b/snf-cyclades-app/synnefo/api/servers.py
131 131
        d['created'] = util.isoformat(vm.created)
132 132
        d['flavorRef'] = vm.flavor.id
133 133
        d['imageRef'] = vm.imageid
134
        d['suspended'] = vm.suspended
134 135

  
135 136
        metadata = dict((m.meta_key, m.meta_value) for m in vm.metadata.all())
136 137
        if metadata:
......
418 419
    except (TypeError, KeyError):
419 420
        raise faults.BadRequest("Malformed request")
420 421

  
421
    vm = util.get_vm(server_id, request.user_uniq)
422
    vm = util.get_vm(server_id, request.user_uniq, non_suspended=True)
422 423
    vm.name = name
423 424
    vm.save()
424 425

  
......
438 439
    #                       overLimit (413)
439 440

  
440 441
    log.info('delete_server %s', server_id)
441
    vm = util.get_vm(server_id, request.user_uniq)
442
    vm = util.get_vm(server_id, request.user_uniq, non_suspended=True)
442 443
    delete_instance(vm)
443 444
    return HttpResponse(status=204)
444 445

  
......
447 448
def server_action(request, server_id):
448 449
    req = util.get_request_dict(request)
449 450
    log.debug('server_action %s %s', server_id, req)
450
    vm = util.get_vm(server_id, request.user_uniq)
451

  
451 452
    if len(req) != 1:
452 453
        raise faults.BadRequest("Malformed request")
453 454

  
454
    key = req.keys()[0]
455
    val = req[key]
455
    # Do not allow any action on deleted or suspended VMs
456
    vm = util.get_vm(server_id, request.user_uniq, non_deleted=True,
457
                     non_suspended=True)
456 458

  
457 459
    try:
460
        key = req.keys()[0]
461
        val = req[key]
458 462
        assert isinstance(val, dict)
459
        return server_actions[key](request, vm, req[key])
463
        return server_actions[key](request, vm, val)
460 464
    except KeyError:
461 465
        raise faults.BadRequest("Unknown action")
462 466
    except AssertionError:
......
536 540

  
537 541
    req = util.get_request_dict(request)
538 542
    log.info('update_server_metadata %s %s', server_id, req)
539
    vm = util.get_vm(server_id, request.user_uniq)
543
    vm = util.get_vm(server_id, request.user_uniq, non_suspended=True)
540 544
    try:
541 545
        metadata = req['metadata']
542 546
        assert isinstance(metadata, dict)
......
585 589

  
586 590
    req = util.get_request_dict(request)
587 591
    log.info('create_server_metadata_item %s %s %s', server_id, key, req)
588
    vm = util.get_vm(server_id, request.user_uniq)
592
    vm = util.get_vm(server_id, request.user_uniq, non_suspended=True)
589 593
    try:
590 594
        metadict = req['meta']
591 595
        assert isinstance(metadict, dict)
......
619 623
    #                       overLimit (413),
620 624

  
621 625
    log.info('delete_server_metadata_item %s %s', server_id, key)
622
    vm = util.get_vm(server_id, request.user_uniq)
626
    vm = util.get_vm(server_id, request.user_uniq, non_suspended=True)
623 627
    meta = util.get_vm_meta(vm, key)
624 628
    meta.delete()
625 629
    vm.save()

Also available in: Unified diff