Skip to content
Snippets Groups Projects
gnmi.go 1.1 KiB
Newer Older
  • Learn to ignore specific revisions
  • Manuel Kieweg's avatar
    Manuel Kieweg committed
    package main
    
    import (
    	"code.fbi.h-da.de/cocsn/gosdn/nucleus"
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	gpb "github.com/openconfig/gnmi/proto/gnmi"
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	log "github.com/sirupsen/logrus"
    )
    
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    /*
      Simple gnmi request program. Use with cauton and leaf paths only.
    
      Bootstrapping of pnd, device and transport simplified not idiomatic
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    func main() {
    
    	log.SetLevel(log.DebugLevel)
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	sbi := &nucleus.AristaOC{}
    
    	device, err := nucleus.NewDevice("gnmi", sbi,
    		&nucleus.GnmiTransportOptions{
    			Addr:     "portainer.danet.fbi.h-da.de:6030",
    			Username: "admin",
    			Password: "arista",
    			SetNode:  sbi.SetNode(),
    			Encoding: gpb.Encoding_JSON_IETF,
    		})
    	if err != nil {
    		log.Debug(err)
    
    	pnd, err := nucleus.NewPND("openconfig", "test description", sbi)
    	if err != nil {
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    		log.Fatal(err)
    	}
    
    	if err := pnd.AddDevice(device); err != nil {
    
    	p := []string{"/interfaces/interface"}
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	errors := 0
    
    		err := pnd.RequestAll(path)
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    		if err != nil {
    			log.Debug(err)
    			errors++
    			break
    		}
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	}
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	percentage := float64(errors) / float64(len(p)) * 100.0
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	log.Debugf("%v errors", errors)
    	log.Debugf("%v percent failed", percentage)