Ejemplo n.º 1
0
def machine_actions(request):
    # TODO: We shouldn't return list_machines, just 200. Save the API!
    backend_id = request.matchdict['backend']
    machine_id = request.matchdict['machine']
    user = user_from_request(request)
    params = request.json_body
    action = params.get('action', '')
    plan_id = params.get('plan_id', '')
    #plan_id is the id of the plan to resize
    name = params.get('name', '')

    if action in ('start', 'stop', 'reboot', 'destroy', 'resize', 'rename'):
        if action == 'start':
            methods.start_machine(user, backend_id, machine_id)
        elif action == 'stop':
            methods.stop_machine(user, backend_id, machine_id)
        elif action == 'reboot':
            methods.reboot_machine(user, backend_id, machine_id)
        elif action == 'destroy':
            methods.destroy_machine(user, backend_id, machine_id)
        elif action == 'resize':
            methods.resize_machine(user, backend_id, machine_id, plan_id)
        elif action == 'rename':
            methods.rename_machine(user, backend_id, machine_id, name)
        ## return OK
        return methods.list_machines(user, backend_id)
    raise BadRequestError()
Ejemplo n.º 2
0
def machine_actions(request):
    # TODO: We shouldn't return list_machines, just 200. Save the API!
    backend_id = request.matchdict['backend']
    machine_id = request.matchdict['machine']
    user = user_from_request(request)
    params = request.json_body
    action = params.get('action', '')
    plan_id = params.get('plan_id', '')
    # plan_id is the id of the plan to resize
    name = params.get('name', '')

    if action in ('start', 'stop', 'reboot', 'destroy', 'resize', 'rename'):
        if action == 'start':
            methods.start_machine(user, backend_id, machine_id)
        elif action == 'stop':
            methods.stop_machine(user, backend_id, machine_id)
        elif action == 'reboot':
            methods.reboot_machine(user, backend_id, machine_id)
        elif action == 'destroy':
            methods.destroy_machine(user, backend_id, machine_id)
        elif action == 'resize':
            methods.resize_machine(user, backend_id, machine_id, plan_id)
        elif action == 'rename':
            methods.rename_machine(user, backend_id, machine_id, name)
        # return OK
        return methods.list_machines(user, backend_id)
    raise BadRequestError()