Skip to content
Snippets Groups Projects
get.go 925 B
Newer Older
  • Learn to ignore specific revisions
  • package cli
    
    import (
    
    Andre Sterba's avatar
    Andre Sterba committed
    	"context"
    
    
    	"code.fbi.h-da.de/cocsn/gosdn/nucleus/errors"
    
    
    	"code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi"
    	"code.fbi.h-da.de/cocsn/gosdn/nucleus"
    	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
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    func Get(a, u, p string, args ...string) (*gpb.GetResponse, 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 {
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    		return nil, err
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	resp, err := t.Get(context.Background(), args...)
    
    	if err != nil {
    
    		return nil, err
    
    	log.Debug(resp)
    	r, ok := resp.(*gpb.GetResponse)
    	if !ok {
    
    		return nil, &errors.ErrInvalidTypeAssertion{}
    
    	}
    	return r, nil