Upcoming maintenance: Thursday 21 August @ 12:00-14:00 CEST.

Skip to content
Snippets Groups Projects
app.py 3.23 KiB
Newer Older
# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

Lluis Gifre Renom's avatar
Lluis Gifre Renom committed

Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
# Enable eventlet for async networking
# NOTE: monkey_patch needs to be executed before importing any other module.
import eventlet
eventlet.monkey_patch()
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed

Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
#pylint: disable=wrong-import-position
import logging
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
from common.Constants import ServiceNameEnum
from common.Settings import (
    ENVVAR_SUFIX_SERVICE_HOST, ENVVAR_SUFIX_SERVICE_PORT_GRPC,
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
    get_env_var_name, get_http_bind_address, get_log_level,
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
    get_service_baseurl_http, get_service_port_http,
    wait_for_environment_variables
)
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
from .NbiApplication import NbiApplication
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
from .etsi_bwm import register_etsi_bwm_api
from .health_probes import register_health_probes
from .ietf_acl import register_ietf_acl
from .ietf_hardware import register_ietf_hardware
from .ietf_l2vpn import register_ietf_l2vpn
from .ietf_l3vpn import register_ietf_l3vpn
from .ietf_network import register_ietf_network
from .ietf_network_slice import register_ietf_nss
from .qkd_app import register_qkd_app
from .restconf_root import register_restconf_root
from .tfs_api import register_tfs_api
from .well_known_meta import register_well_known
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed


LOG_LEVEL = get_log_level()
logging.basicConfig(level=LOG_LEVEL)
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
logging.getLogger('socketio.server').setLevel(logging.WARNING)
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
LOGGER = logging.getLogger(__name__)

Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
wait_for_environment_variables([
    get_env_var_name(ServiceNameEnum.CONTEXT, ENVVAR_SUFIX_SERVICE_HOST     ),
    get_env_var_name(ServiceNameEnum.CONTEXT, ENVVAR_SUFIX_SERVICE_PORT_GRPC),
    get_env_var_name(ServiceNameEnum.DEVICE,  ENVVAR_SUFIX_SERVICE_HOST     ),
    get_env_var_name(ServiceNameEnum.DEVICE,  ENVVAR_SUFIX_SERVICE_PORT_GRPC),
    get_env_var_name(ServiceNameEnum.SERVICE, ENVVAR_SUFIX_SERVICE_HOST     ),
    get_env_var_name(ServiceNameEnum.SERVICE, ENVVAR_SUFIX_SERVICE_PORT_GRPC),
])

Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
BASE_URL = get_service_baseurl_http(ServiceNameEnum.NBI) or ''
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed

Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
nbi_app = NbiApplication(base_url=BASE_URL)
register_health_probes(nbi_app)
register_restconf_root(nbi_app)
register_well_known   (nbi_app)
register_tfs_api      (nbi_app)
register_etsi_bwm_api (nbi_app)
register_ietf_hardware(nbi_app)
register_ietf_l2vpn   (nbi_app)
register_ietf_l3vpn   (nbi_app)
register_ietf_network (nbi_app)
register_ietf_nss     (nbi_app)
register_ietf_acl     (nbi_app)
register_qkd_app      (nbi_app)

nbi_app.dump_configuration()
app = nbi_app.get_flask_app()
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed

if __name__ == '__main__':
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
    # Only used to run it locally during development stage;
    # otherwise, app is directly launched by gunicorn.
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
    BIND_ADDRESS = get_http_bind_address()
    BIND_PORT    = get_service_port_http(ServiceNameEnum.NBI)
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
    nbi_app._sio.run(
        app, host=BIND_ADDRESS, port=BIND_PORT,
        debug=True, use_reloader=False
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
    )