diff --git a/cmd/gnmi/gnmi.go b/cmd/gnmi/gnmi.go index 22f9798c77a6050aaef8c1e9900a2604dd97053b..aea11deb6187c29325ac08a20a582cd480b4b725 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 f39d1bc6eb3d7582f352de1d8ed49423b61f561e..e356d3bbcf3238c37b76f09c9faa511a50398481 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 {