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

gNMI responses serialised into ygot.Device

parent 6e564041
No related branches found
No related tags found
2 merge requests!91"Overhaul Architecture",!90Develop
Pipeline #60671 passed with warnings
......@@ -11,13 +11,14 @@ import (
)
func main() {
log.SetLevel(log.DebugLevel)
sbi := &nucleus.OpenConfig{}
device := nucleus.Device{
Device: &openconfig.Device{},
SBI: sbi,
Config: nucleus.DeviceConfig{
Uuid: uuid.New(),
Address: "141.100.70.170:6030",
Address: "[fdfd::ce05]:6030",
Username: "admin",
Password: "arista",
},
......@@ -35,7 +36,7 @@ func main() {
ctx := gnmi.NewContext(context.Background(), cfg)
ctx = context.WithValue(ctx, "config", cfg)
paths := []string{"interfaces/interface"}
paths := []string{"/interfaces/interface[name=*]/name"}
req, err := gnmi.NewGetRequest(gnmi.SplitPaths(paths), "")
resp, err := nucleus.GetWithRequest(ctx, req)
if err != nil {
......
......@@ -13,11 +13,9 @@ require (
github.com/golang/protobuf v1.4.2
github.com/google/uuid v1.1.2
github.com/neo4j/neo4j-go-driver v1.8.3
github.com/onsi/ginkgo v1.13.0 // indirect
github.com/openconfig/gnmi v0.0.0-20200617225440-d2b4e6a45802
github.com/openconfig/goyang v0.2.4
github.com/openconfig/reference v0.0.0-20190727015836-8dfd928c9696
github.com/openconfig/ygot v0.8.11
github.com/openconfig/ygot v0.10.0
github.com/rivo/tview v0.0.0-20201018122409-d551c850a743
github.com/sirupsen/logrus v1.4.2
github.com/spf13/viper v1.7.1
......
......@@ -91,6 +91,7 @@ github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/frankban/quicktest v1.7.2 h1:2QxQoC1TS09S7fhCPsrvqYdvP1H5M1P1ih5ABm3BTYk=
github.com/frankban/quicktest v1.7.2/go.mod h1:jaStnuzAqU1AJdCO0l53JDCJrVDKcS03DbaAcR7Ks/o=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
......@@ -374,15 +375,15 @@ github.com/openconfig/gnmi v0.0.0-20200508230933-d19cebf5e7be/go.mod h1:M/EcuapN
github.com/openconfig/gnmi v0.0.0-20200617225440-d2b4e6a45802 h1:WXFwJlWOJINlwlyAZuNo4GdYZS6qPX36+rRUncLmN8Q=
github.com/openconfig/gnmi v0.0.0-20200617225440-d2b4e6a45802/go.mod h1:M/EcuapNQgvzxo1DDXHK4tx3QpYM/uG4l591v33jG2A=
github.com/openconfig/goyang v0.0.0-20200115183954-d0a48929f0ea/go.mod h1:dhXaV0JgHJzdrHi2l+w0fZrwArtXL7jEFoiqLEdmkvU=
github.com/openconfig/goyang v0.2.1 h1:TaADsLGzULGQL8xTmvLjmXqZ/J1F73dMzURDqrv9cLs=
github.com/openconfig/goyang v0.2.1/go.mod h1:vX61x01Q46AzbZUzG617vWqh/cB+aisc+RrNkXRd3W8=
github.com/openconfig/goyang v0.2.4 h1:xGmGr3zuhq9ASCu5jRdtMFdRnixhbg8TJEQ0nylyvxA=
github.com/openconfig/goyang v0.2.4/go.mod h1:vX61x01Q46AzbZUzG617vWqh/cB+aisc+RrNkXRd3W8=
github.com/openconfig/goyang v0.2.2 h1:J8hlJk1GSHrcr9vVI7dTvsThsKihWcNXRjWOkjRK0Cw=
github.com/openconfig/goyang v0.2.2/go.mod h1:vX61x01Q46AzbZUzG617vWqh/cB+aisc+RrNkXRd3W8=
github.com/openconfig/reference v0.0.0-20190727015836-8dfd928c9696 h1:yHCGAHg2zMaW8olLrqEt3SAHGcEx2aJPEQWMRCyravY=
github.com/openconfig/reference v0.0.0-20190727015836-8dfd928c9696/go.mod h1:ym2A+zigScwkSEb/cVQB0/ZMpU3rqiH6X7WRRsxgOGw=
github.com/openconfig/ygot v0.6.0/go.mod h1:o30svNf7O0xK+R35tlx95odkDmZWS9JyWWQSmIhqwAs=
github.com/openconfig/ygot v0.8.11 h1:s9BtpSeqChokRQHhTatv2xmwkTLHPz0ghPnVpgmz8WU=
github.com/openconfig/ygot v0.8.11/go.mod h1:Qh/F0ycMLXJlZn4cR+5iuefEMthLggO8KBq8wjXYPTY=
github.com/openconfig/ygot v0.10.0 h1:EmgwLXbFiCBmEUlSI4/1fPuRzgf4EsD0sThmAmRqbYM=
github.com/openconfig/ygot v0.10.0/go.mod h1:oCQNdXnv7dWc8scTDgoFkauv1wwplJn5HspHcjlxSAQ=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pborman/getopt v0.0.0-20190409184431-ee0cd42419d3 h1:YtFkrqsMEj7YqpIhRteVxJxCeC3jJBieuLr0d4C4rSA=
github.com/pborman/getopt v0.0.0-20190409184431-ee0cd42419d3/go.mod h1:85jBQOZwpVEaDAr341tbn15RS4fCAsIst0qp7i8ex1o=
......
package nucleus
import (
_ "code.fbi.h-da.de/cocsn/yang-models/generated/openconfig"
"code.fbi.h-da.de/cocsn/yang-models/generated/openconfig"
"github.com/google/uuid"
pb "github.com/openconfig/gnmi/proto/gnmi"
"github.com/openconfig/goyang/pkg/util"
"github.com/openconfig/ygot/ygot"
"github.com/openconfig/ygot/ytypes"
"io/ioutil"
)
type Device struct {
......@@ -21,30 +19,18 @@ type Device struct {
// use better naming in further develop
// Also all that Interface Call specific logic belongs to SBI!
func (d Device) Add(resp interface{}) error {
files, err := ioutil.ReadDir("api/models")
s, err := openconfig.Schema()
if err != nil {
return err
}
inFiles := make([]string, 0)
for _, file := range files {
inFiles = append(inFiles, "api/models/"+file.Name())
}
inPath := []string{}
models, errA := util.ProcessModules(inFiles, inPath)
for _, e := range errA {
if e != nil {
return e
}
}
models := s.SchemaTree
opts := []ytypes.SetNodeOpt{&ytypes.InitMissingElements{}, &ytypes.TolerateJSONInconsistencies{}}
r := resp.(*pb.GetResponse)
rn := r.Notification
for _, msg := range rn {
for _, val := range msg.Update {
// Assuming the first path element is the name of the schema
schemaPrefix := d.SBI.SbiIdentifier() + "-"
schema := models[schemaPrefix+val.Path.Elem[0].Name]
if err := ytypes.SetNode(schema, d.Device, val.Path, val.Val, opts...); err != nil {
schema := models["Device"]
if err := ytypes.SetNode(schema, d.Device.(*openconfig.Device), val.Path, val.Val, opts...); err != nil {
return err
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment