Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package cli
import (
"code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi"
"code.fbi.h-da.de/cocsn/gosdn/nucleus"
"github.com/google/uuid"
gpb "github.com/openconfig/gnmi/proto/gnmi"
log "github.com/sirupsen/logrus"
)
/*
Simple gnmi request program. Use with cauton and leaf paths only.
Bootstrapping of pnd, device and transport simplified not idiomatic
*/
func Get() error {
sbi := &nucleus.OpenConfig{}
opts := &nucleus.GnmiTransportOptions{
Config: gnmi.Config{
Addr: "portainer.danet.fbi.h-da.de:6030",
Username: "admin",
Password: "arista",
Encoding: gpb.Encoding_JSON_IETF,
},
SetNode: sbi.SetNode(),
}
device, err := nucleus.NewDevice(sbi, opts)
if err != nil {
return err
}
pnd, err := nucleus.NewPND("openconfig", "test description", uuid.New(), sbi)
if err != nil {
return err
}
if err := pnd.AddDevice(device); err != nil {
return err
}
p := []string{"/interfaces/interface"}
errors := 0
for _, path := range p {
err := pnd.RequestAll(path)
if err != nil {
log.Debug(err)
errors++
break
}
}
percentage := float64(errors) / float64(len(p)) * 100.0
if errors != 0 {
log.Error("%v errors", errors)
log.Error("%v percent failed", percentage)
}
return nil
}