def run_forchestrator(): """main function to start forch""" logger = get_logger(_LOGGER_NAME) logger.info('Starting Forchestrator') config = load_config() if not config: logger.error('Invalid config, exiting.') sys.exit(1) forchestrator = Forchestrator(config) http_server = forch.http_server.HttpServer(forchestrator.get_local_port(), config.http) try: forchestrator.initialize() http_server.map_request('system_state', forchestrator.get_system_state) http_server.map_request('dataplane_state', forchestrator.get_dataplane_state) http_server.map_request('switch_state', forchestrator.get_switch_state) http_server.map_request('cpn_state', forchestrator.get_cpn_state) http_server.map_request('process_state', forchestrator.get_process_state) http_server.map_request('host_path', forchestrator.get_host_path) http_server.map_request('list_hosts', forchestrator.get_list_hosts) http_server.map_request('vrrp_state', forchestrator.get_vrrp_state) http_server.map_request('sys_config', forchestrator.get_sys_config) http_server.map_request('', http_server.static_file('')) except Exception as e: logger.error("Cannot initialize forch: %s", e, exc_info=True) http_server.map_request('', functools.partial(show_error, e)) finally: http_server.start_server() forchestrator.update_initialization_varz() if not forchestrator.main_loop(): try: http_server.join_thread() except KeyboardInterrupt: logger.info('Keyboard interrupt. Exiting.') logger.warning('Exiting program') http_server.stop_server() forchestrator.stop()
def main(): """main function to start forch""" configure_logging() config = load_config() if not config: LOGGER.error('Invalid config, exiting.') sys.exit(1) forchestrator = Forchestrator(config) http_server = forch.http_server.HttpServer(config.get('http', {}), forchestrator.get_local_port()) try: forchestrator.initialize() http_server.map_request('system_state', forchestrator.get_system_state) http_server.map_request('dataplane_state', forchestrator.get_dataplane_state) http_server.map_request('switch_state', forchestrator.get_switch_state) http_server.map_request('cpn_state', forchestrator.get_cpn_state) http_server.map_request('process_state', forchestrator.get_process_state) http_server.map_request('host_path', forchestrator.get_host_path) http_server.map_request('list_hosts', forchestrator.get_list_hosts) http_server.map_request('sys_config', forchestrator.get_sys_config) http_server.map_request('', http_server.static_file('')) except Exception as e: LOGGER.error("Cannot initialize forch: %s", e, exc_info=True) http_server.map_request('', functools.partial(show_error, e)) finally: http_server.start_server() if forchestrator.initialized(): forchestrator.main_loop() else: try: http_server.join_thread() except KeyboardInterrupt: LOGGER.info('Keyboard interrupt. Exiting.') LOGGER.warning('Exiting program') http_server.stop_server()