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.
# Enable eventlet for async networking
# NOTE: monkey_patch needs to be executed before importing any other module.
import eventlet
eventlet.monkey_patch()
#pylint: disable=wrong-import-position
import logging
from common.Constants import ServiceNameEnum
from common.Settings import (
ENVVAR_SUFIX_SERVICE_HOST, ENVVAR_SUFIX_SERVICE_PORT_GRPC,
get_env_var_name, get_http_bind_address, get_log_level,
wait_for_environment_variables
)
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
LOG_LEVEL = get_log_level()
logging.basicConfig(level=LOG_LEVEL)
logging.getLogger('socketio.server').setLevel(logging.WARNING)
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),
])
BASE_URL = get_service_baseurl_http(ServiceNameEnum.NBI) or ''
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()
# Only used to run it locally during development stage;
# otherwise, app is directly launched by gunicorn.
BIND_ADDRESS = get_http_bind_address()
BIND_PORT = get_service_port_http(ServiceNameEnum.NBI)
nbi_app._sio.run(
app, host=BIND_ADDRESS, port=BIND_PORT,
debug=True, use_reloader=False