Beispiel #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()
Beispiel #2
0
            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)
                        response = Response(HTTPStatus.OK, result)
                        network_manager.send(response)
                    else:
                        network_manager.stop()
                        break
                except ParseError as e:
                    logger.warning('Invalid command received')
                    response = Response(HTTPStatus.BAD_REQUEST, e.errors)
                    network_manager.send(response)
                except ValidationError as e:
                    logger.warning('Invalid command received')
                    response = Response(HTTPStatus.BAD_REQUEST, e.get_msg())
                    network_manager.send(response)
                except ExecutionError as e:
                    response = Response(HTTPStatus.CONFLICT, {'error': e.get_msg()})
                    network_manager.send(response)
                except ClientDisconnected as e:
                    network_manager.disconnect_client()
                    break