Exemplo n.º 1
0
    def top(port, socket, auth, title, modules, cors_origin, workers, backlog,
            authz):
        """Run Treadmill API server."""
        context.GLOBAL.zk.add_listener(zkutils.exit_on_lost)

        api_paths = api.init(modules, title.replace('_', ' '), cors_origin,
                             authz)

        if port:
            rest_server = rest.TcpRestServer(port,
                                             auth_type=auth,
                                             protect=api_paths,
                                             workers=workers,
                                             backlog=backlog)
        # TODO: need to rename that - conflicts with import socket.
        elif socket:
            rest_server = rest.UdsRestServer(socket,
                                             auth_type=auth,
                                             workers=workers,
                                             backlog=backlog)
        else:
            click.echo('port or socket must be specified')
            sys.exit(1)

        try:
            rest_server.run()
        except sock.error as sock_err:
            print(sock_err)
            if sock_err.errno == errno.EADDRINUSE:
                # TODO: hack, but please keep it for now, otherwise on the
                #       setup several master processes run on same server
                #       lookup api (listen on port 8080) is in tight loop.
                time.sleep(5)
Exemplo n.º 2
0
    def server(port, socket, auth, title, cors_origin, workers, interval):
        """Create pge server to provide authorize service."""
        (base_api, cors) = api.base_api(title, cors_origin)
        endpoint = cgroup_api.init(base_api, cors, interval=interval)
        if not endpoint.startswith('/'):
            endpoint = '/' + endpoint

        if port:
            rest_server = rest.TcpRestServer(port,
                                             auth_type=auth,
                                             protect=[endpoint],
                                             workers=workers)
        # TODO: need to rename that - conflicts with import socket.
        elif socket:
            rest_server = rest.UdsRestServer(socket)
        else:
            click.echo('port or socket must be specified')
            sys.exit(1)
        try:
            rest_server.run()
        except sock.error as sock_err:
            print(sock_err)
            if sock_err.errno == errno.EADDRINUSE:
                # TODO: hack, but please keep it for now, otherwise on the
                #       setup several master processes run on same server
                #       lookup api (listen on port 8080) is in tight loop.
                time.sleep(5)
Exemplo n.º 3
0
    def test_udsrestsrv(self):
        """Dummy test."""
        socket = os.path.join(tempfile.gettempdir(), 'no', 'such', 'dir',
                              'foo.sock')
        rest_server = rest.UdsRestServer(socket)

        # not yet existing socket w/ containing dir should be created
        rest_server._setup_endpoint(mock.Mock())
        self.assertTrue(os.path.exists(socket))

        # shouldn't fail if the containing dir already exists
        rest_server._setup_endpoint(mock.Mock())
Exemplo n.º 4
0
    def top(port, socket, auth, title, modules, config, params, cors_origin,
            workers, backlog, authz):
        """Run Treadmill API server."""
        context.GLOBAL.zk.add_listener(zkutils.exit_on_lost)

        api_modules = {module: {} for module in modules}
        for module, cfg in config:
            if module not in api_modules:
                raise click.UsageError('Orphan config: %s, not in: %r' %
                                       (module, modules))
            api_modules[module] = yaml.load(stream=cfg)
            cfg.close()

        for module, param in params:
            if module not in api_modules:
                raise click.UsageError('Orphan config: %s, not in: %r' %
                                       (module, modules))

            api_modules[module].update(yaml.load(param))

        api_paths = api.init(api_modules, title.replace('_', ' '), cors_origin,
                             authz)

        if port:
            rest_server = rest.TcpRestServer(port,
                                             auth_type=auth,
                                             protect=api_paths,
                                             workers=workers,
                                             backlog=backlog)
        # TODO: need to rename that - conflicts with import socket.
        elif socket:
            rest_server = rest.UdsRestServer(socket,
                                             auth_type=auth,
                                             workers=workers,
                                             backlog=backlog)
        else:
            click.echo('port or socket must be specified')
            sys.exit(1)

        try:
            rest_server.run()
        except sock.error as sock_err:
            _LOGGER.warning('Socker error: %s', sock_err)
            if sock_err.errno == errno.EADDRINUSE:
                # TODO: hack, but please keep it for now, otherwise on the
                #       setup several master processes run on same server
                #       lookup api (listen on port 8080) is in tight loop.
                time.sleep(5)
Exemplo n.º 5
0
    def top(port, socket, auth, title, modules, cors_origin, workers, authz):
        """Run Treadmill API server."""
        context.GLOBAL.zk.add_listener(zkutils.exit_on_lost)

        api_paths = api.init(modules, title.replace('_', ' '), cors_origin,
                             authz)

        if port:
            rest_server = rest.TcpRestServer(port,
                                             auth_type=auth,
                                             protect=api_paths,
                                             workers=workers)
        elif socket:
            rest_server = rest.UdsRestServer(socket)
        else:
            click.echo('port or socket must be specified')
            sys.exit(1)

        rest_server.run()