Skip to content
Snippets Groups Projects
get.go 746 B
Newer Older
  • Learn to ignore specific revisions
  • package cli
    
    import (
    	"code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi"
    	"code.fbi.h-da.de/cocsn/gosdn/nucleus"
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	"context"
    
    	gpb "github.com/openconfig/gnmi/proto/gnmi"
    	log "github.com/sirupsen/logrus"
    )
    
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    // Get sends a gNMI Get request to the specified target and prints the response to stdout
    func Get(a, u, p string, args...string) error {
    
    	sbi := &nucleus.OpenConfig{}
    	opts := &nucleus.GnmiTransportOptions{
    		Config: gnmi.Config{
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    			Addr:     a,
    			Username: u,
    			Password: p,
    
    			Encoding: gpb.Encoding_JSON_IETF,
    		},
    		SetNode: sbi.SetNode(),
    	}
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	t, err := nucleus.NewGnmiTransport(opts)
    
    	if err != nil {
    		return err
    	}
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	resp, err := t.Get(context.Background(), args...)
    
    	if err != nil {
    		return err
    	}
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	log.Info(resp)
    
    	return nil
    }