deanonimized capabilities request func
@@ -61,9 +61,16 @@ var capabilitiesCmd = &cobra.Command{
}
wg := new(sync.WaitGroup)
wg.Add(len(addresses))
- req := &gnmi.CapabilityRequest{}
+ lock := new(sync.Mutex)
for _, addr := range addresses {
- go func(address string) {
+ go reqCapability(ctx, addr, username, password, wg, lock)
+ }
+ wg.Wait()
+ return nil
+ },
+}
+
+func reqCapability(ctx context.Context, address, username, password string, wg *sync.WaitGroup, m *sync.Mutex) error {
defer wg.Done()
_, _, err := net.SplitHostPort(address)
if err != nil {
@@ -71,13 +78,13 @@ var capabilitiesCmd = &cobra.Command{
address = net.JoinHostPort(address, defaultGrpcPort)
} else {
logger.Printf("error parsing address '%s': %v", address, err)
- return
+ return err
}
}
conn, err := createGrpcConn(address)
if err != nil {
logger.Printf("connection to %s failed: %v", address, err)
- return
+ return err
}
client := gnmi.NewGNMIClient(conn)
@@ -85,38 +92,42 @@ var capabilitiesCmd = &cobra.Command{
defer cancel()
nctx = metadata.AppendToOutgoingContext(nctx, "username", username, "password", password)
+ req := &gnmi.CapabilityRequest{}
response, err := client.Capabilities(nctx, req)
if err != nil {
logger.Printf("error sending capabilities request: %v", err)
- return
+ return err
}
+ m.Lock()
+ printCapResponse(response, address)
+ m.Unlock()
+ return nil
+}
+
+func printCapResponse(r *gnmi.CapabilityResponse, address string) {
printPrefix := ""
+ addresses := viper.GetStringSlice("address")
if len(addresses) > 1 && !viper.GetBool("no-prefix") {
printPrefix = fmt.Sprintf("[%s] ", address)
}
if viper.GetString("format") == "textproto" {
- rsp := proto.MarshalTextString(response)
+ rsp := proto.MarshalTextString(r)
fmt.Println(indent(printPrefix, rsp))
return
}
- fmt.Printf("%sgNMI version: %s\n", printPrefix, response.GNMIVersion)
+ fmt.Printf("%sgNMI version: %s\n", printPrefix, r.GNMIVersion)
if viper.GetBool("version") {
return
}
fmt.Printf("%ssupported models:\n", printPrefix)
- for _, sm := range response.SupportedModels {
+ for _, sm := range r.SupportedModels {
fmt.Printf("%s - %s, %s, %s\n", printPrefix, sm.GetName(), sm.GetOrganization(), sm.GetVersion())
}
fmt.Printf("%ssupported encodings:\n", printPrefix)
- for _, se := range response.SupportedEncodings {
+ for _, se := range r.SupportedEncodings {
fmt.Printf("%s - %s\n", printPrefix, se.String())
}
fmt.Println()
- }(addr)
- }
- wg.Wait()
- return nil
- },
}
func init() {
