From c9e49137068bd6fb096dffe392e886510433eda3 Mon Sep 17 00:00:00 2001 From: Manuel Kieweg <mail@manuelkieweg.de> Date: Fri, 15 Jan 2021 18:00:30 +0100 Subject: [PATCH] parse notification --- cmd/gnmi/gnmi.go | 10 ++++++++-- nucleus/device.go | 33 ++++++++++----------------------- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/cmd/gnmi/gnmi.go b/cmd/gnmi/gnmi.go index 22f9798c7..aea11deb6 100644 --- a/cmd/gnmi/gnmi.go +++ b/cmd/gnmi/gnmi.go @@ -3,6 +3,7 @@ package main import ( "code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi" "code.fbi.h-da.de/cocsn/gosdn/nucleus" + "code.fbi.h-da.de/cocsn/yang-models/generated/openconfig" "context" "fmt" "github.com/google/uuid" @@ -12,6 +13,7 @@ import ( func main() { sbi := &nucleus.OpenConfig{} device := nucleus.Device{ + Device: &openconfig.Device{}, SBI: sbi, Config: nucleus.DeviceConfig{ Uuid: uuid.New(), @@ -33,11 +35,15 @@ func main() { ctx := gnmi.NewContext(context.Background(), cfg) ctx = context.WithValue(ctx, "config", cfg) - paths := []string{"interfaces/interface"} + paths := []string{""} req, err := gnmi.NewGetRequest(gnmi.SplitPaths(paths), "") resp, err := nucleus.GetWithRequest(ctx, req) if err != nil { log.Fatal(err) } - fmt.Printf("%v", resp) + fmt.Println(resp) + if err := device.Add(resp); err != nil { + log.Fatal(err) + } + fmt.Println(device.Config) } diff --git a/nucleus/device.go b/nucleus/device.go index f39d1bc6e..e356d3bbc 100644 --- a/nucleus/device.go +++ b/nucleus/device.go @@ -1,11 +1,10 @@ package nucleus import ( - "code.fbi.h-da.de/cocsn/yang-models/generated/openconfig" "github.com/google/uuid" - "github.com/openconfig/gnmi/proto/gnmi" + pb "github.com/openconfig/gnmi/proto/gnmi" "github.com/openconfig/ygot/ygot" - log "github.com/sirupsen/logrus" + "github.com/openconfig/ygot/ytypes" ) type Device struct { @@ -18,27 +17,15 @@ type Device struct { // Add adds a property to a device. Please // use better naming in further develop // Also all that Interface Call specific logic belongs to SBI! -func (d Device) Add(resp interface{}) { - r := resp.(*gnmi.GetResponse) - log.Debug(r) - device := d.Device.(*openconfig.Device) - ifaces := make(map[string]*openconfig.OpenconfigInterfaces_Interfaces_Interface) - ifaces["test"] = &openconfig.OpenconfigInterfaces_Interfaces_Interface{ - Aggregation: nil, - Config: nil, - Ethernet: nil, - HoldTime: nil, - Name: nil, - RoutedVlan: nil, - State: nil, - Subinterfaces: nil, +func (d Device) Add(resp interface{}) error { + r := resp.(*pb.GetResponse) + rn := r.Notification + for _,msg := range rn { + if err := ytypes.SetNode(nil, d.Device, msg.Prefix ,msg); err != nil { + return err + } } - // It's possible that the gnmi response already is too Arista-fied to be used w/YGOT - ifs := &openconfig.OpenconfigInterfaces_Interfaces{ - Interface: ifaces, - } - device.Interfaces = ifs - d.Device = device + return nil } type DeviceConfig struct { -- GitLab