Esempio n. 1
0
def build_gnmi_sub_onchange():
    req = gnmi_pb2.SubscribeRequest()
    subList = req.subscribe
    subList.mode = gnmi_pb2.SubscriptionList.STREAM
    subList.updates_only = True
    sub = subList.subscription.add()
    sub.mode = gnmi_pb2.ON_CHANGE
    path = sub.path
    build_path(args.path, path)
    return req
Esempio n. 2
0
def build_gnmi_sub_sample():
    req = gnmi_pb2.SubscribeRequest()
    subList = req.subscribe
    subList.mode = gnmi_pb2.SubscriptionList.STREAM
    subList.updates_only = True
    sub = subList.subscription.add()
    sub.mode = gnmi_pb2.SAMPLE
    sub.sample_interval = args.interval
    path = sub.path
    build_path(args.path, path)
    return req
def main():
    channel = grpc.insecure_channel(args.grpc_addr)
    stub = gnmi_pb2.gNMIStub(channel)

    stream_out_q = queue.Queue()
    stream_in_q = queue.Queue()

    def req_iterator():
        while True:
            req = stream_out_q.get()
            if req is None:
                break
            print("***************************")
            print("REQUEST")
            print(req)
            print("***************************")
            yield req

    def stream_recv(stream):
        for response in stream:
            print("***************************")
            print("RESPONSE")
            print(response)
            print("***************************")
            stream_in_q.put(response)

    stream = stub.Subscribe(req_iterator())
    stream_recv_thread = threading.Thread(
        target=stream_recv, args=(stream,))
    stream_recv_thread.start()

    req = gnmi_pb2.SubscribeRequest()
    subList = req.subscribe
    subList.mode = gnmi_pb2.SubscriptionList.STREAM
    subList.updates_only = True
    sub = subList.subscription.add()
    sub.mode = gnmi_pb2.ON_CHANGE
    path = sub.path
    for name in ["interfaces", "interface", "..."]:
        e = path.elem.add()
        e.name = name

    stream_out_q.put(req)

    try:
        while True:
            sleep(1)
    except KeyboardInterrupt:
        stream_out_q.put(None)
        stream_recv_thread.join()
Esempio n. 4
0
 def req_iterator():
     while True:
         req = gnmi_pb2.SubscribeRequest()
         subList = req.subscribe
         subList.mode = gnmi_pb2.SubscriptionList.ONCE
         sub = subList.subscription.add()
         path = sub.path
         for name in ["interfaces", "interface", "..."]:
             e = path.elem.add()
             e.name = name
         print("***************************")
         print("REQUEST")
         print(req)
         print("***************************")
         yield req
         return