Esempio n. 1
0
def config_accessor_grpcapi():
    global orig_sigint

    grpcapi_endpoint = Config.get("accessor.endpoint")
    grpcapi_username = Config.get("accessor.username")
    grpcapi_password = Config.get("accessor.password")

    # if password starts with "@", then retreive the password from a file
    if grpcapi_password.startswith("@"):
        fn = grpcapi_password[1:]
        if not os.path.exists(fn):
            raise Exception("%s does not exist" % fn)
        grpcapi_password = open(fn).readline().strip()

    from xosapi.xos_grpc_client import SecureClient
    from twisted.internet import reactor

    grpcapi_client = SecureClient(endpoint=grpcapi_endpoint,
                                  username=grpcapi_username,
                                  password=grpcapi_password)
    grpcapi_client.set_reconnect_callback(
        functools.partial(grpcapi_reconnect, grpcapi_client, reactor))
    grpcapi_client.start()

    # Start reactor. This will cause the client to connect and then execute
    # grpcapi_callback().

    # Reactor will take over SIGINT during reactor.run(), but does not return it when reactor.stop() is called.

    orig_sigint = signal.getsignal(signal.SIGINT)

    # Start reactor. This will cause the client to connect and then execute
    # grpcapi_callback().

    reactor.run()
Esempio n. 2
0
 def create_secure_client(self, username, password, arg):
     """
     This method will check if this combination of username/password already
     has stored orm classes in RESOURCES, otherwise create them
     """
     deferred = defer.Deferred()
     key = "%s~%s" % (username, password)
     if key in RESOURCES:
         reactor.callLater(0, deferred.callback, arg)
     else:
         local_cert = Config.get("local_cert")
         client = SecureClient(
             endpoint=self.grpc_secure_endpoint,
             username=username,
             password=password,
             cacert=local_cert,
         )
         client.restart_on_disconnect = True
         # SecureClient is preceeded by an insecure client, so treat all secure clients as previously connected
         # See CORD-3152
         client.was_connected = True
         client.set_reconnect_callback(
             functools.partial(self.setup_resources, client, key, deferred,
                               arg))
         client.start()
     return deferred
Esempio n. 3
0
def config_accessor_grpcapi():
    global orig_sigint

    log.info("Connecting to the gRPC API")

    grpcapi_endpoint = Config.get("accessor.endpoint")
    grpcapi_username = Config.get("accessor.username")
    grpcapi_password = Config.get("accessor.password")

    # if password starts with "@", then retreive the password from a file
    if grpcapi_password.startswith("@"):
        fn = grpcapi_password[1:]
        if not os.path.exists(fn):
            raise Exception("%s does not exist" % fn)
        grpcapi_password = open(fn).readline().strip()

    from xosapi.xos_grpc_client import SecureClient
    from twisted.internet import reactor

    grpcapi_client = SecureClient(endpoint=grpcapi_endpoint,
                                  username=grpcapi_username,
                                  password=grpcapi_password)
    grpcapi_client.set_reconnect_callback(
        functools.partial(grpcapi_reconnect, grpcapi_client, reactor))
    grpcapi_client.restart_on_protobuf_change = True
    grpcapi_client.start()

    # Start reactor. This will cause the client to connect and then execute
    # grpcapi_callback().

    # Reactor will take over SIGINT during reactor.run(), but does not return it when reactor.stop() is called.

    orig_sigint = signal.getsignal(signal.SIGINT)

    # Start reactor. This will cause the client to connect and then execute
    # grpcapi_callback().

    reactor.run()

    # Catch if we wanted to stop while inside of a reactor callback
    if after_reactor_exit_code is not None:
        log.info("exiting with status", code=after_reactor_exit_code)
        sys.exit(after_reactor_exit_code)
Esempio n. 4
0
def config_accessor():
    global model_accessor

    accessor_kind = getattr(Config(), "observer_accessor_kind", "django")

    if (accessor_kind == "django"):
        from djangoaccessor import DjangoModelAccessor
        model_accessor = DjangoModelAccessor()
        import_models_to_globals()
    else:
        grpcapi_endpoint = getattr(Config(), "observer_accessor_endpoint",
                                   "xos-core.cord.lab:50051")
        grpcapi_username = getattr(Config(), "observer_accessor_username",
                                   "*****@*****.**")
        grpcapi_password = getattr(Config(), "observer_accessor_password")

        # if password starts with "@", then retreive the password from a file
        if grpcapi_password.startswith("@"):
            fn = grpcapi_password[1:]
            if not os.path.exists(fn):
                raise Exception("%s does not exist" % fn)
            grpcapi_password = open(fn).readline().strip()

        from xosapi.xos_grpc_client import SecureClient
        from twisted.internet import reactor

        grpcapi_client = SecureClient(endpoint=grpcapi_endpoint,
                                      username=grpcapi_username,
                                      password=grpcapi_password)
        grpcapi_client.set_reconnect_callback(
            functools.partial(grpcapi_reconnect, grpcapi_client, reactor))
        grpcapi_client.start()

        # Start reactor. This will cause the client to connect and then execute
        # grpcapi_callback().

        reactor.run()