Example #1
0
def make_app():
    """App builder (wsgi).

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

    app.route('/', methods=['GET'])(version_list)
    app.teardown_request(teardown_request)
    app.register_blueprint(api_v1_0.rest, url_prefix='/v1')

    for code in werkzeug_exceptions.default_exceptions.iterkeys():
        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 = debug.Debug.factory(app.config)(app.wsgi_app)

    app.wsgi_app = auth_token.filter_factory(
        app.config,
        auth_host=CONF.os_auth_host,
        auth_port=CONF.os_auth_port,
        auth_protocol=CONF.os_auth_protocol,
        admin_user=CONF.os_admin_username,
        admin_password=CONF.os_admin_password,
        admin_tenant_name=CONF.os_admin_tenant_name,
        auth_version=CONF.os_auth_version,
    )(app.wsgi_app)

    return app
Example #2
0
def make_app():
    """App builder (wsgi).

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

    app.route('/', methods=['GET'])(version_list)
    app.register_blueprint(api_v1_0.rest, url_prefix='/v1')

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

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

    if cfg.CONF.log_exchange:
        app.wsgi_app = debug.Debug.factory(app.config)(app.wsgi_app)

    app.wsgi_app = auth_token.filter_factory(
        app.config,
        auth_host=cfg.CONF.os_auth_host,
        auth_port=cfg.CONF.os_auth_port,
        auth_protocol=cfg.CONF.os_auth_protocol,
        admin_user=cfg.CONF.os_admin_username,
        admin_password=cfg.CONF.os_admin_password,
        admin_tenant_name=cfg.CONF.os_admin_tenant_name,
        auth_version=cfg.CONF.os_auth_version,
    )(app.wsgi_app)

    return app
Example #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": "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:
        cfg = app.config
        app.wsgi_app = log_exchange.LogExchange.factory(cfg)(app.wsgi_app)

    app.wsgi_app = auth_valid.filter_factory(app.config)(app.wsgi_app)

    app.wsgi_app = auth_token.filter_factory(
        app.config,
        auth_host=CONF.os_auth_host,
        auth_port=CONF.os_auth_port,
        auth_protocol=CONF.os_auth_protocol,
        admin_user=CONF.os_admin_username,
        admin_password=CONF.os_admin_password,
        admin_tenant_name=CONF.os_admin_tenant_name
    )(app.wsgi_app)

    return app
Example #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": "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:
        cfg = app.config
        app.wsgi_app = log_exchange.LogExchange.factory(cfg)(app.wsgi_app)

    app.wsgi_app = auth_valid.filter_factory(app.config)(app.wsgi_app)

    app.wsgi_app = auth_token.filter_factory(
        app.config,
        auth_host=CONF.os_auth_host,
        auth_port=CONF.os_auth_port,
        auth_protocol=CONF.os_auth_protocol,
        admin_user=CONF.os_admin_username,
        admin_password=CONF.os_admin_password,
        admin_tenant_name=CONF.os_admin_tenant_name)(app.wsgi_app)

    return app
Example #5
0
def make_app():
    """App builder (wsgi)

    Entry point for Savanna REST API server
    """
    app = flask.Flask("savanna.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")

    plugins_base.setup_plugins()
    periodic.setup(app)

    engine = _get_infrastructure_engine()
    remote.setup_remote(engine)
    service_api.setup_service_api(engine)

    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:
        cfg = app.config
        app.wsgi_app = log_exchange.LogExchange.factory(cfg)(app.wsgi_app)

    app.wsgi_app = auth_valid.filter_factory(app.config)(app.wsgi_app)

    app.wsgi_app = auth_token.filter_factory(
        app.config,
        auth_host=CONF.os_auth_host,
        auth_port=CONF.os_auth_port,
        auth_protocol=CONF.os_auth_protocol,
        admin_user=CONF.os_admin_username,
        admin_password=CONF.os_admin_password,
        admin_tenant_name=CONF.os_admin_tenant_name,
    )(app.wsgi_app)

    return app
Example #6
0
def make_app():
    """App builder (wsgi).

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

    app.route('/', methods=['GET'])(version_list)
    app.route('/versions', methods=['GET'])(version_list)
    app.register_blueprint(api_v1_0.rest, url_prefix='/v1')

    LOG.debug("List of plugins: %s", cfg.CONF.manager.plugins)
    # TODO(sbauza) : Change this whole crap by removing hardcoded values and
    #   maybe using stevedore for achieving this
    if (cfg.CONF.manager.plugins
            and 'physical.host.plugin' in cfg.CONF.manager.plugins):
        app.register_blueprint(host_api_v1_0.rest, url_prefix='/v1/os-hosts')

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

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

    if cfg.CONF.log_exchange:
        app.wsgi_app = debug.Debug.factory(app.config)(app.wsgi_app)

    app.wsgi_app = auth_token.filter_factory(
        app.config,
        auth_host=cfg.CONF.os_auth_host,
        auth_port=cfg.CONF.os_auth_port,
        auth_protocol=cfg.CONF.os_auth_protocol,
        admin_user=cfg.CONF.os_admin_username,
        admin_password=cfg.CONF.os_admin_password,
        admin_tenant_name=cfg.CONF.os_admin_project_name,
        auth_version=cfg.CONF.os_auth_version,
    )(app.wsgi_app)

    return app
Example #7
0
def make_app():
    """App builder (wsgi).

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

    app.route('/', methods=['GET'])(version_list)
    app.route('/versions', methods=['GET'])(version_list)
    app.register_blueprint(api_v1_0.rest, url_prefix='/v1')

    LOG.debug("List of plugins: %s", cfg.CONF.manager.plugins)
    # TODO(sbauza) : Change this whole crap by removing hardcoded values and
    #   maybe using stevedore for achieving this
    if (cfg.CONF.manager.plugins
            and 'physical.host.plugin' in cfg.CONF.manager.plugins):
        app.register_blueprint(host_api_v1_0.rest, url_prefix='/v1/os-hosts')

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

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

    if cfg.CONF.log_exchange:
        app.wsgi_app = debug.Debug.factory(app.config)(app.wsgi_app)

    app.wsgi_app = auth_token.filter_factory(
        app.config,
        auth_host=cfg.CONF.os_auth_host,
        auth_port=cfg.CONF.os_auth_port,
        auth_protocol=cfg.CONF.os_auth_protocol,
        admin_user=cfg.CONF.os_admin_username,
        admin_password=cfg.CONF.os_admin_password,
        admin_tenant_name=cfg.CONF.os_admin_project_name,
        auth_version=cfg.CONF.os_auth_version,
    )(app.wsgi_app)

    return app
Example #8
0
def make_app():
    """App builder (wsgi)

    Entry point for Savanna REST API server
    """
    app = flask.Flask('savanna.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):
        # TODO(slukjanov): how it'll work in case of exception?
        if context.has_ctx():
            if flask.request.path != '/':
                try:
                    session = context.session()
                    if session.transaction:
                        session.transaction.commit()
                except Exception as e:
                    return api_utils.internal_error(
                        500, 'Internal Server Error', e)

        context.set_ctx(None)

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

    db_api.configure_db()
    scheduler.setup_scheduler(app)
    plugins_base.setup_plugins()

    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 werkzeug_exceptions.default_exceptions.iterkeys():
        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 = debug.Debug.factory(app.config)(app.wsgi_app)

    app.wsgi_app = auth_valid.filter_factory(app.config)(app.wsgi_app)

    app.wsgi_app = auth_token.filter_factory(
        app.config,
        auth_host=CONF.os_auth_host,
        auth_port=CONF.os_auth_port,
        auth_protocol=CONF.os_auth_protocol,
        admin_user=CONF.os_admin_username,
        admin_password=CONF.os_admin_password,
        admin_tenant_name=CONF.os_admin_tenant_name
    )(app.wsgi_app)

    return app