Ejemplo n.º 1
0
def main():
    server.setup_common(possible_topdir, 'engine')

    # NOTE(apavlov): acl.wrap is called here to set up auth_uri value
    # in context by using keystone functionality (mostly to avoid
    # code duplication).
    acl.wrap(None)

    server.setup_sahara_engine()

    ops_server = ops.OpsServer()
    ops_server.start()
Ejemplo n.º 2
0
def main():
    server.setup_common(possible_topdir, 'engine')

    # NOTE(apavlov): acl.wrap is called here to set up auth_uri value
    # in context by using keystone functionality (mostly to avoid
    # code duplication).
    acl.wrap(None)

    server.setup_sahara_engine()

    ops_server = ops.OpsServer()
    ops_server.start()
Ejemplo n.º 3
0
def make_app():
    """App builder (wsgi)

    Entry point for Sahara REST API server
    """
    app = flask.Flask('sahara.api')

    @app.route('/', methods=['GET'])
    def version_list():
        context.set_ctx(None)
        return api_utils.render({
            "versions": [
                {"id": "v1.0", "status": "SUPPORTED"},
                {"id": "v1.1", "status": "CURRENT"}
            ]
        })

    @app.teardown_request
    def teardown_request(_ex=None):
        context.set_ctx(None)

    app.register_blueprint(api_v10.rest, url_prefix='/v1.0')
    app.register_blueprint(api_v10.rest, url_prefix='/v1.1')
    app.register_blueprint(api_v11.rest, url_prefix='/v1.1')

    def make_json_error(ex):
        status_code = (ex.code
                       if isinstance(ex, werkzeug_exceptions.HTTPException)
                       else 500)
        description = (ex.description
                       if isinstance(ex, werkzeug_exceptions.HTTPException)
                       else str(ex))
        return api_utils.render({'error': status_code,
                                 'error_message': description},
                                status=status_code)

    for code in six.iterkeys(werkzeug_exceptions.default_exceptions):
        app.error_handler_spec[None][code] = make_json_error

    if CONF.debug and not CONF.log_exchange:
        LOG.debug('Logging of request/response exchange could be enabled using'
                  ' flag --log-exchange')

    # Create a CORS wrapper, and attach sahara-specific defaults that must be
    # included in all CORS responses.
    app.wsgi_app = cors_middleware.CORS(app.wsgi_app, CONF)
    app.wsgi_app.set_latent(
        allow_headers=['X-Auth-Token', 'X-Server-Management-Url'],
        allow_methods=['GET', 'PUT', 'POST', 'DELETE', 'PATCH'],
        expose_headers=['X-Auth-Token', 'X-Server-Management-Url']
    )

    if CONF.log_exchange:
        app.wsgi_app = log_exchange.LogExchange.factory(CONF)(app.wsgi_app)

    app.wsgi_app = auth_valid.wrap(app.wsgi_app)
    app.wsgi_app = acl.wrap(app.wsgi_app)
    app.wsgi_app = request_id.RequestId(app.wsgi_app)

    return app
Ejemplo n.º 4
0
def make_app():
    """App builder (wsgi)

    Entry point for Sahara REST API server
    """
    app = flask.Flask('sahara.api')

    @app.route('/', methods=['GET'])
    def version_list():
        context.set_ctx(None)
        return api_utils.render({
            "versions": [
                {"id": "v1.0", "status": "SUPPORTED"},
                {"id": "v1.1", "status": "CURRENT"}
            ]
        })

    @app.teardown_request
    def teardown_request(_ex=None):
        context.set_ctx(None)

    app.register_blueprint(api_v10.rest, url_prefix='/v1.0')
    app.register_blueprint(api_v10.rest, url_prefix='/v1.1')
    app.register_blueprint(api_v11.rest, url_prefix='/v1.1')

    def make_json_error(ex):
        status_code = (ex.code
                       if isinstance(ex, werkzeug_exceptions.HTTPException)
                       else 500)
        description = (ex.description
                       if isinstance(ex, werkzeug_exceptions.HTTPException)
                       else str(ex))
        return api_utils.render({'error': status_code,
                                 'error_message': description},
                                status=status_code)

    for code in six.iterkeys(werkzeug_exceptions.default_exceptions):
        app.error_handler_spec[None][code] = make_json_error

    if CONF.debug and not CONF.log_exchange:
        LOG.debug('Logging of request/response exchange could be enabled using'
                  ' flag --log-exchange')

    if CONF.log_exchange:
        app.wsgi_app = log_exchange.LogExchange.factory(CONF)(app.wsgi_app)

    app.wsgi_app = auth_valid.wrap(app.wsgi_app)
    app.wsgi_app = acl.wrap(app.wsgi_app)
    app.wsgi_app = request_id.RequestId(app.wsgi_app)

    return app
Ejemplo n.º 5
0
def make_app():
    """App builder (wsgi)

    Entry point for Sahara REST API server
    """
    app = flask.Flask('sahara.api')

    @app.route('/', methods=['GET'])
    def version_list():
        context.set_ctx(None)
        return api_utils.render(
            {"versions": [{
                "id": "v1.0",
                "status": "CURRENT"
            }]})

    @app.teardown_request
    def teardown_request(_ex=None):
        context.set_ctx(None)

    app.register_blueprint(api_v10.rest, url_prefix='/v1.0')
    app.register_blueprint(api_v10.rest, url_prefix='/v1.1')
    app.register_blueprint(api_v11.rest, url_prefix='/v1.1')

    def make_json_error(ex):
        status_code = (ex.code if isinstance(
            ex, werkzeug_exceptions.HTTPException) else 500)
        description = (ex.description if isinstance(
            ex, werkzeug_exceptions.HTTPException) else str(ex))
        return api_utils.render(
            {
                'error': status_code,
                'error_message': description
            },
            status=status_code)

    for code in six.iterkeys(werkzeug_exceptions.default_exceptions):
        app.error_handler_spec[None][code] = make_json_error

    if CONF.debug and not CONF.log_exchange:
        LOG.debug('Logging of request/response exchange could be enabled using'
                  ' flag --log-exchange')

    if CONF.log_exchange:
        app.wsgi_app = log_exchange.LogExchange.factory(CONF)(app.wsgi_app)

    app.wsgi_app = auth_valid.wrap(app.wsgi_app)
    app.wsgi_app = acl.wrap(app.wsgi_app)
    app.wsgi_app = request_id.RequestId(app.wsgi_app)

    return app