예제 #1
0
    def __init__(self, config):
        """
        @param config: Configuration container
        @type config: Config
        """
        self.config = config
        self.logger = logging.getLogger()

        self.server = Server(
            config.server.port,
            config.server.ssl_key_file,
            config.server.ssl_crt_file,
            config.server.ssl_method,
        )
        self.collector = Collector()
        self.endpoints_root = EndpointsRoot(self.collector)

        self.endpoints_lookup = config.server.endpoints
예제 #2
0
파일: control.py 프로젝트: inkhey/mmc
    def __init__(self, config):
        """
        @param config: Configuration container
        @type config: Config
        """
        self.config = config
        self.logger = logging.getLogger()

        self.server = Server(config.server.port,
                             config.server.ssl_key_file,
                             config.server.ssl_crt_file,
                             config.server.ssl_method,
                             )
        self.collector = Collector()
        self.endpoints_root = EndpointsRoot(self.collector)

        self.endpoints_lookup = config.server.endpoints
예제 #3
0
class Dispatcher(object):
    """
    Common point providing the cooperation between gateway and endpoints.

    Gateway as producer puts the received requests into a queue and launches
    the getters of endpoints (consumers) by linked trigger.
    Each endpoint may forward incoming request, store them into a database,
    or just treat each incoming request, where for all types of endpoints,
    a result is always returned to producer to pass them to client.
    """
    endpoints = [
        PackagesEndpoint,
        InventoryServerEndpoint,
        VPNInstallEndpoint,
    ]

    endpoints_root = None
    collector = None

    def __init__(self, config):
        """
        @param config: Configuration container
        @type config: Config
        """
        self.config = config
        self.logger = logging.getLogger()

        self.server = Server(
            config.server.port,
            config.server.ssl_key_file,
            config.server.ssl_crt_file,
            config.server.ssl_method,
        )
        self.collector = Collector()
        self.endpoints_root = EndpointsRoot(self.collector)

        self.endpoints_lookup = config.server.endpoints

    def _start_server(self):
        """
        Starts the gateway instance.

        @return: endpoint port instance
        @rtype: Deferred
        """

        trigger = Trigger(self.endpoints_root.do_calls)

        d = self.server.start(self.collector, trigger)
        d.addCallback(self._connect_endpoints)
        d.addErrback(self._eb_start_failed)

        return d

    def _connect_endpoints(self, reason):
        """
        Installs the endpoints consuming the requests from gateway.

        """
        for endpoint in self.endpoints:
            if endpoint.prefix in self.endpoints_lookup:
                self.logger.info("Registering '%s' endpoint" % endpoint.prefix)
                self.endpoints_root.register(endpoint(self.config))

    def _eb_start_failed(self, failure):
        self.logger.warn("\033[31mStart server failed: %s\033[0m" %
                         str(failure))

    def run(self):

        d = self._start_server()
        return d
예제 #4
0
파일: control.py 프로젝트: inkhey/mmc
class Dispatcher(object):
    """
    Common point providing the cooperation between gateway and endpoints.

    Gateway as producer puts the received requests into a queue and launches
    the getters of endpoints (consumers) by linked trigger.
    Each endpoint may forward incoming request, store them into a database,
    or just treat each incoming request, where for all types of endpoints,
    a result is always returned to producer to pass them to client.
    """
    endpoints = [PackagesEndpoint,
                 InventoryServerEndpoint,
                 VPNInstallEndpoint,
                 ]

    endpoints_root = None
    collector = None

    def __init__(self, config):
        """
        @param config: Configuration container
        @type config: Config
        """
        self.config = config
        self.logger = logging.getLogger()

        self.server = Server(config.server.port,
                             config.server.ssl_key_file,
                             config.server.ssl_crt_file,
                             config.server.ssl_method,
                             )
        self.collector = Collector()
        self.endpoints_root = EndpointsRoot(self.collector)

        self.endpoints_lookup = config.server.endpoints


    def _start_server(self):
        """
        Starts the gateway instance.

        @return: endpoint port instance
        @rtype: Deferred
        """

        trigger = Trigger(self.endpoints_root.do_calls)

        d = self.server.start(self.collector, trigger)
        d.addCallback(self._connect_endpoints)
        d.addErrback(self._eb_start_failed)

        return d

    def _connect_endpoints(self, reason):
        """
        Installs the endpoints consuming the requests from gateway.

        """
        for endpoint in self.endpoints:
            if endpoint.prefix in self.endpoints_lookup:
                self.logger.info("Registering '%s' endpoint" % endpoint.prefix)
                self.endpoints_root.register(endpoint(self.config))



    def _eb_start_failed(self, failure):
        self.logger.warn("\033[31mStart server failed: %s\033[0m" % str(failure))



    def run(self):

        d = self._start_server()
        return d