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
+ 29
15
Compare changes
  • Side-by-side
  • Inline
@@ -122,42 +122,56 @@ func (oc *OpenConfig) Unmarshal(bytes []byte, path *gpb.Path, goStruct ygot.GoSt
return unmarshal(oc.Schema(), bytes, path, goStruct, opt...)
}
// 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() {
if r := recover(); r != nil {
log.Error(r.(error))
}
}()
// Generates an empty validated struct from a given schema and path
func generateEmptyValidatedStructs(schema *ytypes.Schema, path *gpb.Path) (ygot.ValidatedGoStruct, ygot.ValidatedGoStruct, error) {
// Load SBI definition
root, err := ygot.DeepCopy(schema.Root)
if err != nil {
return err
return nil, nil, err
}
validatedDeepCopy, ok := root.(ygot.ValidatedGoStruct)
if !ok {
return &customerrs.InvalidTypeAssertionError{
return nil, nil, &customerrs.InvalidTypeAssertionError{
Value: root,
Type: (*ygot.ValidatedGoStruct)(nil),
}
}
// returns the node we want to fill with the data contained in 'bytes',
// using the specified 'path'.
// returns the node we want to fill with the data contained in 'bytes', using the specified 'path'.
createdNode, _, err := ytypes.GetOrCreateNode(schema.RootSchema(), validatedDeepCopy, path)
if err != nil {
return err
return nil, nil, err
}
validatedCreatedNode, ok := createdNode.(ygot.ValidatedGoStruct)
if !ok {
return &customerrs.InvalidTypeAssertionError{
return nil, nil, &customerrs.InvalidTypeAssertionError{
Value: createdNode,
Type: (*ygot.ValidatedGoStruct)(nil),
}
}
if err := openconfig.Unmarshal(bytes, validatedCreatedNode, opt...); err != nil {
return validatedDeepCopy, validatedCreatedNode, 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() {
if r := recover(); r != nil {
log.Error(r.(error))
}
}()
validatedDeepCopy, emptyValidatedCreatedNode, err := generateEmptyValidatedStructs(schema, path)
if err != nil {
return err
}
_, emptyValidatedCreatedNodeForDiff, err := generateEmptyValidatedStructs(schema, path)
if err != nil {
return err
}
if err := openconfig.Unmarshal(bytes, emptyValidatedCreatedNode, opt...); err != nil {
return err
}
Loading