Skip to content
Snippets Groups Projects

Enable export and import of SDN configuration

Merged Ghost User requested to merge export-import-sdn-config into develop
1 file
+ 36
3
Compare changes
  • Side-by-side
  • Inline
@@ -2,6 +2,7 @@ package nucleus
import (
"encoding/json"
"fmt"
"path/filepath"
"code.fbi.h-da.de/danet/gosdn/controller/customerrs"
@@ -153,6 +154,27 @@ func generateEmptyValidatedStructs(schema *ytypes.Schema, path *gpb.Path) (ygot.
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.
func unmarshal(schema *ytypes.Schema, bytes []byte, path *gpb.Path, goStruct ygot.GoStruct, opt ...ytypes.UnmarshalOpt) error {
defer func() {
@@ -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 {
return err
}
_, emptyValidatedCreatedNodeForDiff, err := generateEmptyValidatedStructs(schema, path)
validatedDeepCopyForDiff, validatedCreatedNodeForDiff, err := generateEmptyValidatedStructs(schema, path)
if err != nil {
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
}
validatedCreatedNode.
//err = removeReadOnlyFields(validatedCreatedNode, validatedCreatedNodeForDiff, schema)
//if err != nil {
// return err
//}
opts := []ygot.MergeOpt{&ygot.MergeOverwriteExistingFields{}}
return ygot.MergeStructInto(goStruct, validatedDeepCopy, opts...)
}
Loading