Skip to content
Snippets Groups Projects
set.go 947 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
    	"code.fbi.h-da.de/cocsn/gosdn/nucleus/util/proto"
    
    	"context"
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	pb "google.golang.org/protobuf/proto"
    
    	"os"
    )
    
    func Set() error {
    	a := os.Getenv("GOSDN_TEST_ENDPOINT")
    	if a == "" {
    		a = "portainer.danet.fbi.h-da.de:6030"
    	}
    
    	opts := &nucleus.GnmiTransportOptions{
    		Config: gnmi.Config{
    			Addr:     a,
    			Username: "admin",
    			Password: "arista",
    		},
    	}
    	t, err := nucleus.NewGnmiTransport(opts)
    	if err != nil {
    		return err
    	}
    
    	reqs := []interface{}{
    		&gnmi.Operation{
    			Type:   "update",
    			Origin: "",
    			Target: "",
    			Path: []string{
    				"system",
    				"config",
    				"hostname",
    			},
    			Val: "ceos3000",
    		},
    	}
    
    	resp, err := t.Set(context.Background(), reqs...)
    	if err != nil {
    		return err
    	}
    
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	if err := proto.Write(resp.(pb.Message), "resp-set-system-config-hostname"); err != nil {
    
    		return err
    	}
    	return nil
    }