Exemplo n.º 1
0
    def setUp(self):
        if options.http_path:
            self.transport = THttpClient.THttpClient(
                options.host, options.port, options.http_path)
        else:
            socket = TSocket.TSocket(options.host, options.port)

            # frame or buffer depending upon args
            if options.framed:
                self.transport = TTransport.TFramedTransport(socket)
            else:
                self.transport = TTransport.TBufferedTransport(socket)

        protocol = self.protocol_factory.getProtocol(self.transport)
        if options.header:
            protocol = THeaderProtocol.THeaderProtocol(socket)
            self.transport = protocol.trans
            protocol.trans.add_transform(protocol.trans.ZLIB_TRANSFORM)

        self.transport.open()
        self.client = ThriftTest.Client(protocol)
        if options.multiple:
            p = TMultiplexedProtocol.TMultiplexedProtocol(protocol,
                    "ThriftTest")
            self.client = ThriftTest.Client(p)
            p = TMultiplexedProtocol.TMultiplexedProtocol(protocol,
                    "SecondService")
            self.client2 = SecondService.Client(p)
        else:
            self.client = ThriftTest.Client(protocol)
            self.client2 = None
Exemplo n.º 2
0
    def __init__(self, sw_name, thrift_port, pd_thrift_path):
        print sw_name
        self.sw_name = sw_name
        self.thrift_port = thrift_port
        self.pd_thrift_path = pd_thrift_path

        sys.path.insert(0, pd_thrift_path)
        print pd_thrift_path

        self.p4_client_module = importlib.import_module(".".join(
            ["p4_pd_rpc", "simple_router"]))
        self.mc_client_module = importlib.import_module(".".join(
            ["mc_pd_rpc", "mc"]))
        self.conn_mgr_client_module = importlib.import_module(".".join(
            ["conn_mgr_pd_rpc", "conn_mgr"]))

        # Set up thrift client and contact server
        self.transport = TSocket.TSocket('localhost', thrift_port)
        self.transport = TTransport.TBufferedTransport(self.transport)
        bprotocol = TBinaryProtocol.TBinaryProtocol(self.transport)

        mc_protocol = TMultiplexedProtocol.TMultiplexedProtocol(
            bprotocol, "mc")
        conn_mgr_protocol = TMultiplexedProtocol.TMultiplexedProtocol(
            bprotocol, "conn_mgr")
        p4_protocol = TMultiplexedProtocol.TMultiplexedProtocol(
            bprotocol, "simple_router")

        self.client = self.p4_client_module.Client(p4_protocol)
        self.mc = self.mc_client_module.Client(mc_protocol)
        self.conn_mgr = self.conn_mgr_client_module.Client(conn_mgr_protocol)
        self.transport.open()

        sys.path.pop(0)
Exemplo n.º 3
0
def configure_switch():
    p4_name = "dc"
    p4_client_module = importlib.import_module(".".join(["p4_pd_rpc",
                                                         p4_name]))
    mc_client_module = importlib.import_module(".".join(["mc_pd_rpc", "mc"]))
    conn_mgr_client_module = importlib.import_module(".".join(
        ["conn_mgr_pd_rpc", "conn_mgr"]))

    transport = TSocket.TSocket('localhost', 9090)
    transport = TTransport.TBufferedTransport(transport)
    bprotocol = TBinaryProtocol.TBinaryProtocol(transport)

    mc_protocol = TMultiplexedProtocol.TMultiplexedProtocol(bprotocol, "mc")
    conn_mgr_protocol = TMultiplexedProtocol.TMultiplexedProtocol(
        bprotocol, "conn_mgr")
    p4_protocol = TMultiplexedProtocol.TMultiplexedProtocol(bprotocol, p4_name)

    client = p4_client_module.Client(p4_protocol)
    mc = mc_client_module.Client(mc_protocol)
    conn_mgr = conn_mgr_client_module.Client(conn_mgr_protocol)
    transport.open()

    setup_bd(client, conn_mgr)

    transport.close()
Exemplo n.º 4
0
    def setUp(self):
        if self.ssl:
            self.socket = TSSLSocket.TSSLSocket("localhost", self._port)
        else:
            self.socket = TSocket.TSocket("localhost", self._port)

        if self.server_type in FRAMED_TYPES \
                and not isinstance(self, HeaderTest):
            self.transport = TTransport.TFramedTransport(self.socket)
        else:
            self.transport = TTransport.TBufferedTransport(self.socket)

        self.protocol = self.protocol_factory.getProtocol(self.transport)
        if isinstance(self, HeaderAcceleratedCompactTest):
            self.protocol.trans.set_protocol_id(
                THeaderProtocol.THeaderProtocol.T_COMPACT_PROTOCOL)
            self.protocol.reset_protocol()
        self.transport.open()
        self.client = ThriftTest.Client(self.protocol)
        if self.multiple:
            p = TMultiplexedProtocol.TMultiplexedProtocol(
                self.protocol, "ThriftTest")
            self.client = ThriftTest.Client(p)
            p = TMultiplexedProtocol.TMultiplexedProtocol(
                self.protocol, "SecondService")
            self.client2 = SecondService.Client(p)
        else:
            self.client = ThriftTest.Client(self.protocol)
            self.client2 = None
Exemplo n.º 5
0
 def setUp(self):
     if options.http_path:
         self.transport = THttpClient.THttpClient(options.host,
                                                  port=options.port,
                                                  path=options.http_path)
     else:
         if options.ssl:
             from thrift.transport import TSSLSocket
             socket = TSSLSocket.TSSLSocket(options.host,
                                            options.port,
                                            validate=False)
         else:
             socket = TSocket.TSocket(options.host, options.port)
         # frame or buffer depending upon args
         if options.framed:
             self.transport = TTransport.TFramedTransport(socket)
         else:
             self.transport = TTransport.TBufferedTransport(socket)
         if options.zlib:
             self.transport = TZlibTransport.TZlibTransport(
                 self.transport, 9)
     self.transport.open()
     protocol = self.protocol_factory.getProtocol(self.transport)
     if options.multiple:
         p = TMultiplexedProtocol.TMultiplexedProtocol(
             protocol, "ThriftTest")
         self.client = ThriftTest.Client(p)
         p = TMultiplexedProtocol.TMultiplexedProtocol(
             protocol, "SecondService")
         self.client2 = SecondService.Client(p)
     else:
         self.client = ThriftTest.Client(protocol)
         self.client2 = None
Exemplo n.º 6
0
 def __init__(self,
              host='manager',
              port=40002,
              protocol=Protocol.THRIFT_TCP,
              request_client=None,
              response_client=None,
              ticket_client=None,
              loop=asyncio.get_event_loop()):
     init_mapper()
     self._loop = loop
     self._request_client = None
     self._ticket_client = None
     self._response_client = None
     if request_client is not None and response_client is not None and ticket_client is not None:
         self._request_client = request_client
         self._response_client = response_client
         self._ticket_client = ticket_client
     else:
         if protocol == Protocol.THRIFT_TCP:
             transport = TSocket.TSocket(host, port)
             protocol = TBinaryProtocol.TBinaryProtocol(transport)
             protocol_request = TMultiplexedProtocol.TMultiplexedProtocol(
                 protocol, self.THRIFT_SERVICE_NAME_REQUEST)
             protocol_ticket = TMultiplexedProtocol.TMultiplexedProtocol(
                 protocol, self.THRIFT_SERVICE_NAME_TICKET)
             protocol_response = TMultiplexedProtocol.TMultiplexedProtocol(
                 protocol, self.THRIFT_SERVICE_NAME_RESPONSE)
             self._request_client = ExecLogicService.Client(
                 protocol_request)
             self._ticket_client = TicketService.Client(protocol_ticket)
             self._response_client = ExecLogicResponseService.Client(
                 protocol_response)
             transport.open()
         elif protocol == Protocol.REST:
             self._request_client = RESTExecLogicService(host, port)
             self._response_client = RESTExecLogicResponseService(
                 host, port)
             self._ticket_client = RESTTicketService(host, port)
         elif protocol == Protocol.THRIFT_HTTP:
             transport_request = THttpClient('http://{}:{}/{}'.format(
                 host, port, self.THRIFT_SERVICE_NAME_REQUEST))
             transport_response = THttpClient('http://{}:{}/{}'.format(
                 host, port, self.THRIFT_SERVICE_NAME_RESPONSE))
             transport_ticket = THttpClient('http://{}:{}/{}'.format(
                 host, port, self.THRIFT_SERVICE_NAME_TICKET))
             protocol_request = TBinaryProtocol.TBinaryProtocol(
                 transport_request)
             protocol_response = TBinaryProtocol.TBinaryProtocol(
                 transport_response)
             protocol_ticket = TBinaryProtocol.TBinaryProtocol(
                 transport_ticket)
             self._request_client = ExecLogicService.Client(
                 protocol_request)
             self._response_client = ExecLogicResponseService.Client(
                 protocol_response)
             self._ticket_client = TicketService.Client(protocol_ticket)
             transport_request.open()
             transport_response.open()
             transport_ticket.open()
Exemplo n.º 7
0
def initThrift(host, port):
    transport = TSocket.TSocket(host, port)
    transport = TTransport.TBufferedTransport(transport)
    protocol = TBinaryProtocol.TBinaryProtocol(transport)
    aM = AccountManagement.Client(TMultiplexedProtocol.TMultiplexedProtocol(protocol, "manager"))
    aS = AccountService.Client(TMultiplexedProtocol.TMultiplexedProtocol(protocol, "standard"))
    paS = PremiumAccountService.Client(TMultiplexedProtocol.TMultiplexedProtocol(protocol, "premium"))
    transport.open()
    return transport, aM, aS, paS
Exemplo n.º 8
0
    def __init__(self, thrift_server):
        self.transport = TSocket.TSocket(thrift_server, 9090)
        self.transport = TTransport.TBufferedTransport(self.transport)
        bprotocol = TBinaryProtocol.TBinaryProtocol(self.transport)
        conn_mgr_protocol = TMultiplexedProtocol.TMultiplexedProtocol(
            bprotocol, "conn_mgr")
        self.conn_mgr = conn_mgr_pd_rpc.conn_mgr.Client(conn_mgr_protocol)
        p4_protocol = TMultiplexedProtocol.TMultiplexedProtocol(
            bprotocol, "pegasus")
        self.client = pegasus.p4_pd_rpc.pegasus.Client(p4_protocol)
        self.transport.open()

        self.sess_hdl = self.conn_mgr.client_init()
        self.dev = 0
        self.dev_tgt = DevTarget_t(self.dev, hex_to_i16(0xFFFF))

        self.read_reg_rset_fns = []
        self.read_reg_rset_fns.append(self.client.register_read_reg_rset_1)
        self.read_reg_rset_fns.append(self.client.register_read_reg_rset_2)
        self.read_reg_rset_fns.append(self.client.register_read_reg_rset_3)
        self.read_reg_rset_fns.append(self.client.register_read_reg_rset_4)
        self.read_reg_rset_fns.append(self.client.register_read_reg_rset_5)
        self.read_reg_rset_fns.append(self.client.register_read_reg_rset_6)
        self.read_reg_rset_fns.append(self.client.register_read_reg_rset_7)
        self.read_reg_rset_fns.append(self.client.register_read_reg_rset_8)
        self.read_reg_rset_fns.append(self.client.register_read_reg_rset_9)
        self.read_reg_rset_fns.append(self.client.register_read_reg_rset_10)
        self.read_reg_rset_fns.append(self.client.register_read_reg_rset_11)
        self.read_reg_rset_fns.append(self.client.register_read_reg_rset_12)
        self.read_reg_rset_fns.append(self.client.register_read_reg_rset_13)
        self.read_reg_rset_fns.append(self.client.register_read_reg_rset_14)
        self.read_reg_rset_fns.append(self.client.register_read_reg_rset_15)
        self.read_reg_rset_fns.append(self.client.register_read_reg_rset_16)
        self.write_reg_rset_fns = []
        self.write_reg_rset_fns.append(self.client.register_write_reg_rset_1)
        self.write_reg_rset_fns.append(self.client.register_write_reg_rset_2)
        self.write_reg_rset_fns.append(self.client.register_write_reg_rset_3)
        self.write_reg_rset_fns.append(self.client.register_write_reg_rset_4)
        self.write_reg_rset_fns.append(self.client.register_write_reg_rset_5)
        self.write_reg_rset_fns.append(self.client.register_write_reg_rset_6)
        self.write_reg_rset_fns.append(self.client.register_write_reg_rset_7)
        self.write_reg_rset_fns.append(self.client.register_write_reg_rset_8)
        self.write_reg_rset_fns.append(self.client.register_write_reg_rset_9)
        self.write_reg_rset_fns.append(self.client.register_write_reg_rset_10)
        self.write_reg_rset_fns.append(self.client.register_write_reg_rset_11)
        self.write_reg_rset_fns.append(self.client.register_write_reg_rset_12)
        self.write_reg_rset_fns.append(self.client.register_write_reg_rset_13)
        self.write_reg_rset_fns.append(self.client.register_write_reg_rset_14)
        self.write_reg_rset_fns.append(self.client.register_write_reg_rset_15)
        self.write_reg_rset_fns.append(self.client.register_write_reg_rset_16)

        # keyhash -> ReplicatedKey (sorted in ascending load)
        self.replicated_keys = SortedDict(
            lambda x: self.replicated_keys[x].load)
        self.num_nodes = DEFAULT_NUM_NODES
        self.switch_lock = threading.Lock()
Exemplo n.º 9
0
 def __init__(self):
     self.transport = transport = TSocket.TSocket("localhost", 41400)
     transport = TTransport.TBufferedTransport(transport)
     protocol = TBinaryProtocol.TBinaryProtocol(transport)
     multiplex1 = TMultiplexedProtocol.TMultiplexedProtocol(
         protocol, "SurrogateStoreService")
     self._thrift_client = SurrogateStore.Client(multiplex1)
     multiplex2 = TMultiplexedProtocol.TMultiplexedProtocol(
         protocol, "AdministrationService")
     self._admin_client = Administration.Client(multiplex2)
     transport.open()
Exemplo n.º 10
0
def main():
    # Make socket
    transport = TSocket.TSocket('localhost', 9091)

    try:
        # Buffering is critical. Raw sockets are very slow
        transport = TTransport.TBufferedTransport(transport)

        # Wrap in a protocol
        protocol = TBinaryProtocol.TBinaryProtocol(transport)

        # Create a client to use the protocol encoder
        account_factory_client = AccountFactory.Client(
            TMultiplexedProtocol.TMultiplexedProtocol(protocol,
                                                      "AccountFactory"))
        account_service = AccountService.Client(
            TMultiplexedProtocol.TMultiplexedProtocol(protocol,
                                                      "AccountService"))
        premium_account_service = PremiumAccountService.Client(
            TMultiplexedProtocol.TMultiplexedProtocol(protocol,
                                                      "PremiumAccountService"))

        # Connect!
        transport.open()

        while True:
            print("Client console - available commands:")
            print("1. CREATE - create account")
            print("2. LOGIN - login to account")
            print("3. PREMIUM-LOGIN - login to account")
            print("4. CLOSE - close console")
            print("Enter one of commands ...")
            print("/> ")
            try:
                line = input()
                if line.lower() == "create" or line == "1":
                    create_account(account_factory_client)
                elif line.lower() == "login" or line == "2":
                    login_to_account(account_service)
                elif line.lower() == "premium-login" or line == "3":
                    premium_login_to_account(premium_account_service)
                elif line.lower() == "close" or line == "4":
                    transport.close()
                    break
                else:
                    print("[FAIL] Wrong command")
            except IOError as e:
                print("I/O error({0}): {1}".format(e.errno, e.strerror))

    except TException:
        print("TException")
        traceback.print_exc()
    finally:
        transport.close()
Exemplo n.º 11
0
 def __init__(self):
     self.transport = TSocket.TSocket('localhost', 9090)
     self.transport = TTransport.TBufferedTransport(self.transport)
     self.protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
     self.conn_mgr_protocol = TMultiplexedProtocol.TMultiplexedProtocol(
         self.protocol, 'conn_mgr')
     self.switch_p4_protocol = TMultiplexedProtocol.TMultiplexedProtocol(
         self.protocol, 'dc')
     self.client = switch_pd_rpc.Client(self.switch_p4_protocol)
     self.conn_mgr = conn_mgr_rpc.Client(self.conn_mgr_protocol)
     self.transport.open()
     self.sess_hdl = self.conn_mgr.client_init()
Exemplo n.º 12
0
    def __init__(self, thrift_server, thrift_port):
        self.transport = TSocket.TSocket(thrift_server, thrift_port)
        self.transport = TTransport.TBufferedTransport(self.transport)
        bprotocol = TBinaryProtocol.TBinaryProtocol(self.transport)
        conn_mgr_protocol = TMultiplexedProtocol.TMultiplexedProtocol(
            bprotocol, "conn_mgr")
        self.conn_mgr = conn_mgr_pd_rpc.conn_mgr.Client(conn_mgr_protocol)
        p4_protocol = TMultiplexedProtocol.TMultiplexedProtocol(
            bprotocol, "netcache")
        self.client = netcache.p4_pd_rpc.netcache.Client(p4_protocol)
        self.transport.open()

        self.sess_hdl = self.conn_mgr.client_init()
        self.dev = 0
        self.dev_tgt = DevTarget_t(self.dev, hex_to_i16(0xFFFF))
Exemplo n.º 13
0
def thrift_connect(thrift_ip, thrift_port, services):
    # Make socket
    transport = TSocket.TSocket(thrift_ip, thrift_port)
    # Buffering is critical. Raw sockets are very slow
    transport = TTransport.TBufferedTransport(transport)
    # Wrap in a protocol
    bprotocol = TBinaryProtocol.TBinaryProtocol(transport)

    clients = []

    for service_name, service_cls in services:
        if service_name is None:
            clients.append(None)
        protocol = TMultiplexedProtocol.TMultiplexedProtocol(
            bprotocol, service_name)
        client = service_cls(protocol)
        clients.append(client)

    # Connect!
    try:
        transport.open()
    except TTransport.TTransportException:
        print "Could not connect to thrift client on port", thrift_port
        print "Make sure the switch is running and that you have the right port"
        sys.exit(1)

    return clients
Exemplo n.º 14
0
    def thrift_setup(self):
        global thrift_server, transport, pltfm_mgr
        transport = TSocket.TSocket(thrift_server, 9090)

        transport = TTransport.TBufferedTransport(transport)
        bprotocol = TBinaryProtocol.TBinaryProtocol(transport)

        pltfm_mgr_client_module = importlib.import_module(".".join(
            ["pltfm_mgr_rpc", "pltfm_mgr_rpc"]))
        pltfm_mgr_protocol = TMultiplexedProtocol.TMultiplexedProtocol(
            bprotocol, "pltfm_mgr_rpc")
        pltfm_mgr = pltfm_mgr_client_module.Client(pltfm_mgr_protocol)

        for i in range(self.THRIFT_RETRIES):
            try:
                transport.open()
                if i:
                    # The main thrift server is starded without platform api
                    # Platform api is added later during syncd initialization
                    # So we need to wait a little bit before do any platform api call
                    # Just in case when can't connect from the first try (warm-reboot case)
                    time.sleep(self.THRIFT_TIMEOUT)
                break
            except TTransport.TTransportException as e:
                if e.type != TTransport.TTransportException.NOT_OPEN or i >= self.THRIFT_RETRIES - 1:
                    raise e
                time.sleep(self.THRIFT_TIMEOUT)
Exemplo n.º 15
0
def thrift_connect(thrift_ip, thrift_port, services, out=sys.stdout):
    def my_print(s):
        out.write(s)

    # Make socket
    transport = TSocket.TSocket(thrift_ip, thrift_port)
    # Buffering is critical. Raw sockets are very slow
    transport = TTransport.TBufferedTransport(transport)
    # Wrap in a protocol
    bprotocol = TBinaryProtocol.TBinaryProtocol(transport)

    clients = []

    for service_name, service_cls in services:
        if service_name is None:
            clients.append(None)
            continue
        protocol = TMultiplexedProtocol.TMultiplexedProtocol(
            bprotocol, service_name)
        client = service_cls(protocol)
        clients.append(client)

    # Connect!
    try:
        transport.open()
    except TTransport.TTransportException:
        my_print("Could not connect to thrift client on port {}\n".format(
            thrift_port))
        my_print("Make sure the switch is running ")
        my_print("and that you have the right port\n")
        sys.exit(1)

    return clients
Exemplo n.º 16
0
    def _create_client(self, service_name, socket_timeout=None):
        """
        :param service_name [str]: service name
        :param socket_timeout [int]: socket connection timeout in ms.
        :rtype: service client
        """
        sock = TSocket.TSocket(self._address, self._port)
        sock.setTimeout(socket_timeout)
        transport = TTransport.TFramedTransport(sock)
        self.transports.append(transport)
        protocol = TCompactProtocol.TCompactProtocol(transport)
        mp = TMultiplexedProtocol.TMultiplexedProtocol(protocol, service_name)

        client = \
            {"Host": Host.Client(mp),
             "RootScheduler": RootScheduler.Client(mp),
             "AgentControl": AgentControl.Client(mp)}[service_name]

        # try 3 times
        counter = 0

        while counter < 3:
            try:
                transport.open()
                break
            except:
                counter += 1
                time.sleep(1)

        if counter == 3:
            self.fail(
                "Failed to connect to {0} thrift server.".format(service_name))
        return client
Exemplo n.º 17
0
def thrift_connect_standard(thrift_ip, thrift_port, out=sys.stdout):
    def my_print(s):
        out.write(s)

    # Make socket
    transport = TSocket.TSocket(thrift_ip, thrift_port)
    # Buffering is critical. Raw sockets are very slow
    transport = TTransport.TBufferedTransport(transport)
    # Wrap in a protocol
    bprotocol = TBinaryProtocol.TBinaryProtocol(transport)

    protocol = TMultiplexedProtocol.TMultiplexedProtocol(bprotocol, "standard")
    client = Standard.Client(protocol)

    # Connect!
    try:
        transport.open()
    except TTransport.TTransportException:
        my_print("Could not connect to thrift client on port {}\n".format(
            thrift_port))
        my_print("Make sure the switch is running ")
        my_print("and that you have the right port\n")
        sys.exit(1)

    return client,transport
Exemplo n.º 18
0
def create_chairman_client(host, port):
    socket = TSocket.TSocket(host, port)
    transport = TTransport.TFramedTransport(socket)
    protocol = TCompactProtocol.TCompactProtocol(transport)
    mp = TMultiplexedProtocol.TMultiplexedProtocol(protocol, "Chairman")
    client = Chairman.Client(mp)
    _wait_for_transport(transport)
    return (transport, client)
Exemplo n.º 19
0
def thrift_connect(thrift_ip, thrift_port):
    transport = TSocket.TSocket(thrift_ip, thrift_port)
    transport = TTransport.TBufferedTransport(transport)
    bprotocol = TBinaryProtocol.TBinaryProtocol(transport)
    protocol = TMultiplexedProtocol.TMultiplexedProtocol(bprotocol, "standard")
    client = Standard.Client(protocol)
    transport.open()
    return client
Exemplo n.º 20
0
def create_root_client(port, host):
    socket = TSocket.TSocket(host, port)
    transport = TTransport.TFramedTransport(socket)
    protocol = TCompactProtocol.TCompactProtocol(transport)
    mp = TMultiplexedProtocol.TMultiplexedProtocol(protocol, "RootScheduler")
    client = RootScheduler.Client(mp)
    _wait_for_transport(transport)
    return (transport, client)
Exemplo n.º 21
0
    def __init__(self):
        p4_client_module = importlib.import_module("p4_pd_rpc." + p4_name)
        self.transport = TSocket.TSocket("localhost", 9090)
        self.bprotocol = TBinaryProtocol.TBinaryProtocol(self.transport)
        p4_protocol = TMultiplexedProtocol.TMultiplexedProtocol(self.bprotocol, p4_name)
        self.client = p4_client_module.Client(p4_protocol)
        conn_mgr_client_module = importlib.import_module('.'.join(['conn_mgr_pd_rpc', 'conn_mgr']))
        conn_mgr_protocol = TMultiplexedProtocol.TMultiplexedProtocol(self.bprotocol, 'conn_mgr')
        self.conn_mgr = conn_mgr_client_module.Client(conn_mgr_protocol)
        tm_client_module = importlib.import_module(".".join(["tm_api_rpc", "tm"]))
        tm_protocol = TMultiplexedProtocol.TMultiplexedProtocol(self.bprotocol, "tm")
        self.tm = tm_client_module.Client(tm_protocol)

        self.transport.open()
        print "Transport opened."

        self.sess_hdl = self.conn_mgr.client_init()
        self.dev_tgt = DevTarget_t(0, int(0xFFFF) - 0x10000)
Exemplo n.º 22
0
    def __init__(self):
        self.transport = TTransport.TBufferedTransport(TSocket.TSocket("localhost", 9090))
        self.protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
        self.conn_mgr_client_module = importlib.import_module(".".join(["conn_mgr_pd_rpc", "conn_mgr"]))
        self.conn_mgr_protocol = self.conn_mgr_protocol = TMultiplexedProtocol.TMultiplexedProtocol(self.protocol, "conn_mgr")
        self.conn_mgr = self.conn_mgr_client_module.Client(self.conn_mgr_protocol)

        self.transport.open()

        self.hdl = self.conn_mgr.client_init()
Exemplo n.º 23
0
    def __enter__(self):
        transport = TSocket.TSocket('localhost', config.port())
        transport = TTransport.TBufferedTransport(transport)
        protocol = TBinaryProtocol.TBinaryProtocol(transport)
        protocol = TMultiplexedProtocol.TMultiplexedProtocol(
            protocol, self.service_name())

        transport.open()
        self.transport = transport
        self.protocol = protocol
Exemplo n.º 24
0
    def setup(self, hostname, port):

        # Set up thrift client and contact server
        self._transport = TSocket.TSocket(hostname, port)
        self._transport = TTransport.TBufferedTransport(self._transport)
        bprotocol = TBinaryProtocol.TBinaryProtocol(self._transport)

        self._mc_protocol = TMultiplexedProtocol.TMultiplexedProtocol(
            bprotocol, "mc")
        self._conn_mgr_protocol = TMultiplexedProtocol.TMultiplexedProtocol(
            bprotocol, "conn_mgr")
        self._p4_protocol = TMultiplexedProtocol.TMultiplexedProtocol(
            bprotocol, self._p4_name)

        self._client = self.p4_client_module.Client(self._p4_protocol)
        self._mc = self.mc_client_module.Client(self._mc_protocol)
        self._conn_mgr = self.conn_mgr_client_module.Client(
            self._conn_mgr_protocol)
        self._transport.open()
Exemplo n.º 25
0
    def setUp(self):
        BaseTest.setUp(self)

        # Set up thrift client and contact server
        self.transport = TSocket.TSocket('localhost', 9090)
        self.transport = TTransport.TBufferedTransport(self.transport)
        bprotocol = TBinaryProtocol.TBinaryProtocol(self.transport)

        self.mc_protocol = TMultiplexedProtocol.TMultiplexedProtocol(
            bprotocol, "mc")
        self.conn_mgr_protocol = TMultiplexedProtocol.TMultiplexedProtocol(
            bprotocol, "conn_mgr")
        self.p4_protocol = TMultiplexedProtocol.TMultiplexedProtocol(
            bprotocol, self.p4_name)

        self.client = self.p4_client_module.Client(self.p4_protocol)
        self.mc = self.mc_client_module.Client(self.mc_protocol)
        self.conn_mgr = self.conn_mgr_client_module.Client(
            self.conn_mgr_protocol)
        self.transport.open()
Exemplo n.º 26
0
def _createProtocol(service_name, config: Config):
    client = THttpClient.THttpClient(config.RPC_URL)
    if config.RPC_SECRET:
        (cf_id, cf_secret, *dummy) = config.RPC_SECRET.split(',')
        client.setCustomHeaders({
            'CF-Access-Client-Id': cf_id,
            'CF-Access-Client-Secret': cf_secret
        })
    protocol = TJSONProtocol.TJSONProtocol(client)
    protocol = TMultiplexedProtocol.TMultiplexedProtocol(
        protocol, service_name)
    return protocol
Exemplo n.º 27
0
def services():

    cls_transport = TTransport.TBufferedTransport(
        TSocket.TSocket('localhost', 2020))
    acc_transport = TTransport.TBufferedTransport(
        TSocket.TSocket('localhost', 9090))

    std_cls_proto = TMultiplexedProtocol.TMultiplexedProtocol(
        TBinaryProtocol.TBinaryProtocol(cls_transport), "STD_CLS")
    prm_cls_proto = TMultiplexedProtocol.TMultiplexedProtocol(
        TBinaryProtocol.TBinaryProtocol(cls_transport), "PRM_CLS")
    acc_crs_proto = TBinaryProtocol.TBinaryProtocol(acc_transport)

    std_cls = StandardClient.Client(std_cls_proto)
    prm_cls = PremiumClient.Client(prm_cls_proto)
    acc_crs = AccountCreator.Client(acc_crs_proto)

    cls_transport.open()
    acc_transport.open()

    return std_cls, prm_cls, acc_crs
Exemplo n.º 28
0
    def thrift_setup(self):
        global thrift_server, transport, pltfm_mgr
        transport = TSocket.TSocket(thrift_server, 9090)

        transport = TTransport.TBufferedTransport(transport)
        bprotocol = TBinaryProtocol.TBinaryProtocol(transport)

        pltfm_mgr_client_module = importlib.import_module(".".join(["pltfm_mgr_rpc", "pltfm_mgr_rpc"]))
        pltfm_mgr_protocol = TMultiplexedProtocol.TMultiplexedProtocol(bprotocol, "pltfm_mgr_rpc")
        pltfm_mgr = pltfm_mgr_client_module.Client(pltfm_mgr_protocol)

        transport.open()
Exemplo n.º 29
0
 def connect(self):
     """Connect to the HostHandler."""
     sock = TSocket.TSocket(self._host, self._port)
     if self._client_timeout:
         sock.setTimeout(self._client_timeout * 1000)
     self._transport = TTransport.TFramedTransport(sock)
     protocol = TCompactProtocol.TCompactProtocol(self._transport)
     mux_protocol = TMultiplexedProtocol.TMultiplexedProtocol(
         protocol, self._service_name)
     self._client = self._client_cls(mux_protocol)
     self._transport.open()
     self._logger.info("Connected to %s:%s. for service %s" %
                       (self._host, self._port, self._service_name))
Exemplo n.º 30
0
    def __init__(self, port):
        transport = TSocket.TSocket('127.0.0.1', port)

        # Buffering is critical. Raw sockets are very slow
        transport = TTransport.TBufferedTransport(transport)

        # Wrap in a protocol
        protocol = TBinaryProtocol.TBinaryProtocol(transport)
        protocol = TMultiplexedProtocol.TMultiplexedProtocol(
            protocol, "standard")
        self.client = Standard.Client(protocol)
        self.transport = transport
        transport.open()