Exemplo n.º 1
0
 def _get_client(self, options):
     socket = TSocket.TSocket(unix_socket=options.path)
     if options.framed:
         transport = TTransport.TFramedTransport(socket)
     else:
         transport = TTransport.TBufferedTransport(socket)
     return self._get_client_by_transport(options, transport, socket=socket)
Exemplo n.º 2
0
    def open_SSL(self, ip, port, timeout, ssl_config=None):
        """open the SSL connection

        :param ip: the server ip
        :param port: the server port
        :param timeout: the timeout for connect and execute
        :ssl_config: configs for SSL
        :return: void
        """
        self._ip = ip
        self._port = port
        self._timeout = timeout
        try:
            if ssl_config is not None:
                s = TSSLSocket.TSSLSocket(
                    self._ip, self._port, ssl_config.unix_socket,
                    ssl_config.ssl_version, ssl_config.cert_reqs,
                    ssl_config.ca_certs, ssl_config.verify_name,
                    ssl_config.keyfile, ssl_config.certfile,
                    ssl_config.allow_weak_ssl_versions)
            else:
                s = TSocket.TSocket(self._ip, self._port)
            if timeout > 0:
                s.setTimeout(timeout)
            transport = TTransport.TBufferedTransport(s)
            protocol = TBinaryProtocol.TBinaryProtocol(transport)
            transport.open()
            self._connection = GraphService.Client(protocol)
            resp = self._connection.verifyClientVersion(
                VerifyClientVersionReq())
            if resp.error_code != ErrorCode.SUCCEEDED:
                self._connection._iprot.trans.close()
                raise ClientServerIncompatibleException(resp.error_msg)
        except Exception:
            raise
Exemplo n.º 3
0
def establish_a_rare_connection(pytestconfig):
    addr = pytestconfig.getoption("address")
    host_addr = addr.split(":") if addr else ["localhost", get_ports()[0]]
    socket = TSocket.TSocket(host_addr[0], host_addr[1])
    transport = TTransport.TBufferedTransport(socket)
    protocol = TBinaryProtocol.TBinaryProtocol(transport)
    transport.open()
    return GraphService.Client(protocol)
Exemplo n.º 4
0
 def _get_client(self, options):
     host, port = self._parse_host_port(options.host, self.default_port)
     socket = (TSSLSocket.TSSLSocket(host, port) if options.ssl
               else TSocket.TSocket(host, port))
     if options.framed:
         transport = TTransport.TFramedTransport(socket)
     else:
         transport = TTransport.TBufferedTransport(socket)
     return self._get_client_by_transport(options, transport, socket=socket)
Exemplo n.º 5
0
 def _get_client_by_host(self):
     config = self.config
     host, port = self._parse_host_port(config.host, self.default_port)
     socket = (TSSLSocket.TSSLSocket(host, port) if config.ssl
               else TSocket.TSocket(host, port))
     if config.framed:
         transport = TTransport.TFramedTransport(socket)
     else:
         transport = TTransport.TBufferedTransport(socket)
     return self._get_client_by_transport(config, transport, socket=socket)
Exemplo n.º 6
0
 def get_connection(ip, port):
     try:
         socket = TSocket.TSocket(ip, port)
         transport = TTransport.TBufferedTransport(socket)
         protocol = TBinaryProtocol.TBinaryProtocol(transport)
         transport.open()
         connection = GraphService.Client(protocol)
     except Exception as ex:
         assert False, 'Create connection to {}:{} failed'.format(
             ip, port)
     return connection
Exemplo n.º 7
0
 def open(self):
     try:
         self.close()
         s = TSocket.TSocket(self._leader[0], self._leader[1])
         if self._timeout > 0:
             s.setTimeout(self._timeout)
         transport = TTransport.TBufferedTransport(s)
         protocol = TBinaryProtocol.TBinaryProtocol(transport)
         transport.open()
         self._connection = MetaService.Client(protocol)
     except Exception:
         raise
Exemplo n.º 8
0
 def open(self):
     try:
         self.close()
         s = TSocket.TSocket(self._address.host, self._address.port)
         if self._timeout > 0:
             s.setTimeout(self._timeout)
         transport = TTransport.TBufferedTransport(s)
         protocol = TBinaryProtocol.TBinaryProtocol(transport)
         transport.open()
         self._connection = GraphStorageService.Client(protocol)
     except Exception:
         raise
Exemplo n.º 9
0
 def open(self, ip, port, timeout):
     self._ip = ip
     self._port = port
     try:
         s = TSocket.TSocket(self._ip, self._port)
         if timeout > 0:
             s.setTimeout(timeout)
         transport = TTransport.TBufferedTransport(s)
         protocol = TBinaryProtocol.TBinaryProtocol(transport)
         transport.open()
         self._connection = GraphService.Client(protocol)
     except Exception:
         raise
Exemplo n.º 10
0
    def open(self, ip, port, timeout):
        """open the connection

        :param ip: the server ip
        :param port: the server port
        :param timeout: the timeout for connect and execute
        :return: void
        """
        self._ip = ip
        self._port = port
        self._timeout = timeout
        s = TSocket.TSocket(self._ip, self._port)
        if timeout > 0:
            s.setTimeout(timeout)
        transport = TTransport.TBufferedTransport(s)
        protocol = TBinaryProtocol.TBinaryProtocol(transport)
        transport.open()
        self._connection = GraphService.Client(protocol)
        resp = self._connection.verifyClientVersion(VerifyClientVersionReq())
        if resp.error_code != ErrorCode.SUCCEEDED:
            self._connection._iprot.trans.close()
            raise ClientVersionRejectedException(resp.error_msg)