Example #1
0
class NetworkManagerWrapper(ManagerInterface):
    name = "Network Manager"

    def __init__(self, conf: NetworkManagerConfig):
        super().__init__(conf)

        # Build network manager
        self._network_manager = NetworkManager(
            port=conf.GRPC_PORT,
            known_priorities=conf.PRIORITIES,
            limit_to_known_priorities=conf.LIMIT_PRIORITIES,
            logfile_dir=conf.OUTPUT_DIR,
        )

        # Add network services
        self._network_manager.add_service(services.DebugPing())
        self._network_manager.add_service(
            services.LoggingClient(
                host=conf.LOGGING_SERVER_HOST,
                port=conf.LOGGING_SERVER_PORT,
            ))

    def get_service(self, service_name):
        return self._network_manager.get_service(service_name)

    def _start(self):
        self._network_manager.start()

    def _stop(self):
        self._network_manager.stop()
Example #2
0
    backup_count = int(config['LOGGING'].get('backup_count', str(5)))
    log_format = '%(asctime)s - %(name)s - %(levelname)s -- %(message)s'
    formatter = Formatter(log_format)
    fileHandler = RotatingFileHandler(filename, maxBytes=max_bytes, backupCount=backup_count)
    consoleHandler = StreamHandler()
    consoleHandler.setFormatter(formatter)
    fileHandler.setFormatter(formatter)
    handlers = [fileHandler, consoleHandler] if log_on_console else [fileHandler]
    # noinspection PyArgumentList
    basicConfig(level=level, handlers=handlers)
    logger = getLogger('Main')
    logger.info('Starting')

    try:

        network_manager.start()

        while True:

            network_manager.accept_client()
            ctrl = Controller(config)
            logger.info('Ready to receive commands from client')

            while True:

                try:
                    req = network_manager.receive()
                    cmd = parser.parse(req)
                    if not isinstance(cmd, Disconnect):
                        cmd.validate_arguments()
                        result = ctrl.exec_cmd(cmd)