Skip to content
Snippets Groups Projects
Commit 4619c5d9 authored by Neil Schark's avatar Neil Schark
Browse files

wip 2

parent 7021e873
No related branches found
No related tags found
No related merge requests found
Pipeline #125409 failed
This commit is part of merge request !404. Comments created here will be created in the context of that merge request.
...@@ -2,6 +2,7 @@ package nucleus ...@@ -2,6 +2,7 @@ package nucleus
import ( import (
"encoding/json" "encoding/json"
"fmt"
"path/filepath" "path/filepath"
"code.fbi.h-da.de/danet/gosdn/controller/customerrs" "code.fbi.h-da.de/danet/gosdn/controller/customerrs"
...@@ -153,6 +154,27 @@ func generateEmptyValidatedStructs(schema *ytypes.Schema, path *gpb.Path) (ygot. ...@@ -153,6 +154,27 @@ func generateEmptyValidatedStructs(schema *ytypes.Schema, path *gpb.Path) (ygot.
return validatedDeepCopy, validatedCreatedNode, nil return validatedDeepCopy, validatedCreatedNode, nil
} }
func removeReadOnlyFields(validatedGoStruct ygot.ValidatedGoStruct, emptyValidatedGoStruct ygot.ValidatedGoStruct, schema *ytypes.Schema) error {
diff, err := ygot.Diff(emptyValidatedGoStruct, validatedGoStruct)
if err != nil {
return err
}
filteredUpdates := make([]*gpb.Update, 0)
for _, u := range diff.Update {
rootSchema := schema.RootSchema()
pathString, err := ygot.PathToString(u.GetPath())
if err != nil {
return err
}
entry := rootSchema.Find(pathString)
if !entry.ReadOnly() {
filteredUpdates = append(filteredUpdates, u)
}
}
return nil
}
// unmarshal parses a gNMI response to a go struct. // unmarshal parses a gNMI response to a go struct.
func unmarshal(schema *ytypes.Schema, bytes []byte, path *gpb.Path, goStruct ygot.GoStruct, opt ...ytypes.UnmarshalOpt) error { func unmarshal(schema *ytypes.Schema, bytes []byte, path *gpb.Path, goStruct ygot.GoStruct, opt ...ytypes.UnmarshalOpt) error {
defer func() { defer func() {
...@@ -161,20 +183,31 @@ func unmarshal(schema *ytypes.Schema, bytes []byte, path *gpb.Path, goStruct ygo ...@@ -161,20 +183,31 @@ func unmarshal(schema *ytypes.Schema, bytes []byte, path *gpb.Path, goStruct ygo
} }
}() }()
validatedDeepCopy, emptyValidatedCreatedNode, err := generateEmptyValidatedStructs(schema, path) ygot
validatedDeepCopy, validatedCreatedNode, err := generateEmptyValidatedStructs(schema, path)
if err != nil { if err != nil {
return err return err
} }
_, emptyValidatedCreatedNodeForDiff, err := generateEmptyValidatedStructs(schema, path) validatedDeepCopyForDiff, validatedCreatedNodeForDiff, err := generateEmptyValidatedStructs(schema, path)
if err != nil { if err != nil {
return err return err
} }
if err := openconfig.Unmarshal(bytes, emptyValidatedCreatedNode, opt...); err != nil { fmt.Println(validatedDeepCopyForDiff)
fmt.Println(validatedCreatedNodeForDiff)
if err := openconfig.Unmarshal(bytes, validatedCreatedNode, opt...); err != nil {
return err return err
} }
validatedCreatedNode.
//err = removeReadOnlyFields(validatedCreatedNode, validatedCreatedNodeForDiff, schema)
//if err != nil {
// return err
//}
opts := []ygot.MergeOpt{&ygot.MergeOverwriteExistingFields{}} opts := []ygot.MergeOpt{&ygot.MergeOverwriteExistingFields{}}
return ygot.MergeStructInto(goStruct, validatedDeepCopy, opts...) return ygot.MergeStructInto(goStruct, validatedDeepCopy, opts...)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment