Esempio n. 1
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
Esempio n. 2
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
Esempio n. 3
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()
def thrift_connect(pre_type):
    # Make socket
    transport = TSocket.TSocket('localhost', THRIFT_PORT)
    # Buffering is critical. Raw sockets are very slow
    transport = TTransport.TBufferedTransport(transport)
    # Wrap in a protocol
    protocol = TBinaryProtocol.TBinaryProtocol(transport)

    standard_protocol = TMultiplexedProtocol.TMultiplexedProtocol(protocol, "standard")
    standard_client = Standard.Client(standard_protocol)

    if pre_type == PreType.SimplePre:
        mc_protocol = TMultiplexedProtocol.TMultiplexedProtocol(protocol, "simple_pre")
        mc_client = SimplePre.Client(mc_protocol)
    elif pre_type == PreType.SimplePreLAG:
        mc_protocol = TMultiplexedProtocol.TMultiplexedProtocol(protocol, "simple_pre_lag")
        mc_client = SimplePreLAG.Client(mc_protocol)
    else:
        mc_client = None

    # Connect!
    transport.open()

    return standard_client, mc_client