Skip to content
Snippets Groups Projects
Commit c9e49137 authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

parse notification

parent 09b42989
Branches
Tags
2 merge requests!91"Overhaul Architecture",!90Develop
This commit is part of merge request !91. Comments created here will be created in the context of that merge request.
......@@ -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)
}
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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment