def __init__(self, hostname, port=50051, cacert=SERVER_CA, username=None, password=None, sessionid=None): super(SecureClient, self).__init__(hostname, port) server_ca = open(cacert, "r").read() if (sessionid): call_creds = metadata_call_credentials( SessionIdCallCredentials(sessionid)) else: call_creds = metadata_call_credentials( UsernamePasswordCallCredentials(username, password)) chan_creds = ssl_channel_credentials(server_ca) chan_creds = composite_channel_credentials(chan_creds, call_creds) self.channel = grpc.secure_channel( "%s:%d" % (self.hostname, self.port), chan_creds) self.stub = xos_pb2_grpc.xosStub(self.channel) self.modeldefs = modeldefs_pb2_grpc.modeldefsStub(self.channel) self.utility = utility_pb2_grpc.utilityStub(self.channel) self.xos_orm = orm.ORMStub(self.stub, "xos")
def reconnected(self): for api in ['modeldefs', 'utility', 'xos']: pb2_file_name = os.path.join(self.work_dir, api + "_pb2.py") pb2_grpc_file_name = os.path.join(self.work_dir, api + "_pb2_grpc.py") if os.path.exists(pb2_file_name) and os.path.exists( pb2_grpc_file_name): orig_sys_path = sys.path try: sys.path.append(self.work_dir) m_protos = __import__(api + "_pb2") reload(m_protos) m_grpc = __import__(api + "_pb2_grpc") reload(m_grpc) finally: sys.path = orig_sys_path stub_class = getattr(m_grpc, api + "Stub") setattr(self, api, stub_class(self.channel)) setattr(self, api + "_pb2", m_protos) else: print >> sys.stderr, "failed to locate api", api if hasattr(self, "xos"): self.xos_orm = orm.ORMStub(self.xos, "xos") if self.reconnect_callback2: self.reconnect_callback2()
def __init__(self, hostname, port=50055): super(InsecureClient,self).__init__(hostname, port) self.channel = grpc.insecure_channel("%s:%d" % (self.hostname, self.port)) self.stub = xos_pb2_grpc.xosStub(self.channel) self.modeldefs = modeldefs_pb2_grpc.modeldefsStub(self.channel) self.utility = utility_pb2_grpc.utilityStub(self.channel) self.xos_orm = orm.ORMStub(self.stub, "xos")
def reconnected(self): for api in ["modeldefs", "utility", "xos", "dynamicload"]: pb2_file_name = os.path.join(self.work_dir, api + "_pb2.py") pb2_grpc_file_name = os.path.join(self.work_dir, api + "_pb2_grpc.py") if os.path.exists(pb2_file_name) and os.path.exists( pb2_grpc_file_name): orig_sys_path = sys.path try: sys.path.append(self.work_dir) m_protos = __import__(api + "_pb2") # reload(m_protos) m_grpc = __import__(api + "_pb2_grpc") # reload(m_grpc) finally: sys.path = orig_sys_path stub_class = getattr(m_grpc, api + "Stub") setattr(self, api, stub_class(self.channel)) setattr(self, api + "_pb2", m_protos) else: print("failed to locate api", api, file=sys.stderr) if hasattr(self, "xos"): self.xos_orm = orm.ORMStub(self.xos, self.xos_pb2, "xos") # ask the core for the convenience methods self.load_convenience_methods() # Load convenience methods after reconnect orm.import_convenience_methods() if self.reconnect_callback2: self.reconnect_callback2()