Пример #1
0
def get_server(server_id):
    context = flask.request.environ.get('context')

    try:
        server = central_api.get_server(context, server_id)
    except exceptions.Forbidden:
        return flask.Response(status=401)
    except exceptions.ServerNotFound:
        return flask.Response(status=404)
    else:
        server = _append_server_links(server, server['id'])

        server = server_schema.filter(server)

        return flask.jsonify(server)
Пример #2
0
    context = flask.request.environ.get('context')
    values = flask.request.json

    try:
        server_schema.validate(values)
        server = central_api.create_server(context, values=flask.request.json)
    except exceptions.Forbidden:
        return flask.Response(status=401)
    except exceptions.InvalidObject, e:
        return flask.Response(status=400, response=str(e))
    except exceptions.DuplicateServer:
        return flask.Response(status=409)
    else:
        server = _append_server_links(server, server['id'])

        server = server_schema.filter(server)

        response = flask.jsonify(server)
        response.status_int = 201
        response.location = flask.url_for('.get_server',
                                          server_id=server['id'])
        return response


@blueprint.route('/servers', methods=['GET'])
def get_servers():
    context = flask.request.environ.get('context')

    try:
        servers = central_api.get_servers(context)
    except exceptions.Forbidden: