Exemplo n.º 1
0
def service():
    if GRPC:
        server = serve()
        server.service = Service()
        connect_str = f"localhost:{os.environ.get('PORT', '50051')}"
        with grpc.insecure_channel(connect_str) as ch:
            yield Client(channel=ch)
        server.stop(0)
    else:
        yield Service()
Exemplo n.º 2
0
class Servicer(hbi_pb2_grpc.HostInventoryServicer):
    def __init__(self):
        self.service = Service()

    def CreateOrUpdate(self, host_list, context):
        hosts = [Host.from_pb(h) for h in host_list.hosts]
        ret = self.service.create_or_update(hosts)
        return hbi_pb2.HostList(hosts=[h.to_pb() for h in ret])

    def Get(self, filter_list, context):
        filters = [Filter.from_pb(f) for f in filter_list.filters]
        ret = self.service.get(filters)
        return hbi_pb2.HostList(hosts=[h.to_pb() for h in ret])
Exemplo n.º 3
0
def service():
    if MODE == "grpc":
        server = serve()
        connect_str = f"localhost:{os.environ.get('PORT', '50051')}"
        with grpc.insecure_channel(connect_str) as ch:
            yield Client(channel=ch)
        server.stop(0)
    elif MODE == "tornado":
        app.service.reset()
        yield TornadoClient()
    else:
        yield Service()
Exemplo n.º 4
0
def createClient(mode, server, port):
    if mode == "grpc":
        import grpc
        from hbi.client import Client
        print("Running in gRPC mode")
        return Client(host=server, port=port)
    elif mode == "tornado":
        from hbi.client import TornadoClient
        print("Running in REST mode")
        return TornadoClient(host=server, port=port)
    elif mode == "native":
        return Service()
    else:
        raise RuntimeError("The MODE envrionment property was not set")
Exemplo n.º 5
0
def serve_tornado():
    app = tornado.web.Application([
        (r"/", RootHandler),
        (r"/entities/search", EntitiesSearcher),
        (r"/entities", EntitiesPoster),
    ])
    app.listen(int(os.environ.get("PORT", "50051")))
    app.service = Service()
    loop = IOLoop.current()

    class TornadoRunThread(Thread):
        def run(self):
            loop.start()

    TornadoRunThread().start()
    return app, loop
Exemplo n.º 6
0
def service():
    return Service()
Exemplo n.º 7
0
 def __init__(self):
     self.service = Service()