aristanetworks / goarista

Fairly general building blocks used in Arista Go code and open-sourced for the benefit of all.
Apache License 2.0
213 stars 68 forks source link

Can single grpc connection be used to receive data from multiple switches? #42

Closed stangedas closed 5 years ago

stangedas commented 5 years ago

I am able to subscribe to data on a single switch with arista gnmi client. Below is the command used to get some data from switch. So this is essentially one to one connection.

gnmi -addr xx.xx.xx.xx:xxxx -username admin -password password get '/components/component'.

Can i use the same connection and add more switch ip's to receive more data? I would like to give string of switch ip's to receive same data from all the devices.

aaronbee commented 5 years ago

The gnmi client provided here does not allow connecting to multiple switches at once.

Though, this is very doable using the libraries provided here to write a new client.

            go gnmi.Subscribe(ctx, client, subscribeOptions, respChan, errChan)
            for {
                select {
                case resp, open := <-respChan:
                    if !open {
                        return
                    }
                    if err := gnmi.LogSubscribeResponse(resp); err != nil {
                        glog.Fatal(err)
                    }
                case err := <-errChan:
                    glog.Fatal(err)
                }
            }

This is what gnmi does to start a subscription to one client. You could tack on extra calls to Subscribe and emit the output in a way that you like, eg. prefix each line with a name of the device you are connecting to.