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

Merge branch '258-deal-with-read-only-fields-in-yang' into export-import-sdn-config

parents 5c1ee61f 0ee1cd75
No related branches found
No related tags found
1 merge request!404Enable export and import of SDN configuration
......@@ -16,7 +16,6 @@ import (
"code.fbi.h-da.de/danet/gosdn/forks/goarista/gnmi"
gpb "github.com/openconfig/gnmi/proto/gnmi"
"github.com/openconfig/goyang/pkg/yang"
"github.com/openconfig/ygot/util"
"github.com/openconfig/ygot/ygot"
"github.com/openconfig/ygot/ytypes"
log "github.com/sirupsen/logrus"
......@@ -123,41 +122,25 @@ func (g *Gnmi) applyDiff(ctx context.Context, payload change.Payload, path *gpb.
return customerrs.NoNewChangesError{Original: payload.Original, Modified: payload.Modified}
}
var json []byte
if op := ctx.Value(types.CtxKeyOperation); op == ppb.ApiOperation_API_OPERATION_UPDATE || op == ppb.ApiOperation_API_OPERATION_REPLACE {
rootCopy, err := ygot.DeepCopy(schema.Root)
if err != nil {
return err
}
filteredUpdates := make([]*gpb.Update, 0)
for _, u := range diff.Update {
opts := []ytypes.SetNodeOpt{&ytypes.InitMissingElements{}, &ytypes.TolerateJSONInconsistencies{}}
if err := g.SetNode(schema.RootSchema(), rootCopy, u.GetPath(), u.GetVal(), opts...); err != nil {
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)
}
}
ygot.PruneEmptyBranches(rootCopy)
opts := []ytypes.GetNodeOpt{
&ytypes.GetHandleWildcards{},
}
nodes, err := ytypes.GetNode(schema.RootSchema(), rootCopy, path, opts...)
if err != nil {
return err
}
if len(nodes) == 0 || err != nil || util.IsValueNil(nodes[0].Data) {
return customerrs.PathNotFoundError{Path: path, Err: err}
}
json, err = ygot.Marshal7951(nodes[0].Data, &ygot.RFC7951JSONConfig{AppendModuleName: true})
if err != nil {
return err
}
diff.Update = filteredUpdates
}
req, err := createSetRequest(ctx, diff, json, path)
req, err := createSetRequest(ctx, diff)
if err != nil {
return err
}
......@@ -167,25 +150,15 @@ func (g *Gnmi) applyDiff(ctx context.Context, payload change.Payload, path *gpb.
return err
}
func createSetRequest(ctx context.Context, diff *gpb.Notification, json []byte, path *gpb.Path) (*gpb.SetRequest, error) {
func createSetRequest(ctx context.Context, diff *gpb.Notification) (*gpb.SetRequest, error) {
op := ctx.Value(types.CtxKeyOperation)
req := &gpb.SetRequest{}
if diff.Update != nil {
switch op {
case ppb.ApiOperation_API_OPERATION_UPDATE:
req.Update = []*gpb.Update{{
Path: path,
Val: &gpb.TypedValue{
Value: &gpb.TypedValue_JsonIetfVal{JsonIetfVal: json},
},
}}
req.Update = diff.Update
case ppb.ApiOperation_API_OPERATION_REPLACE:
req.Replace = []*gpb.Update{{
Path: path,
Val: &gpb.TypedValue{
Value: &gpb.TypedValue_JsonIetfVal{JsonIetfVal: json},
},
}}
req.Replace = diff.Update
default:
return nil, &customerrs.OperationNotSupportedError{Op: op}
}
......
......@@ -354,7 +354,7 @@ func (pnd *pndImplementation) addNetworkElement(mne networkelement.NetworkElemen
}
if mne.IsTransportValid() {
_, err = pnd.Request(mne.ID(), "/interfaces")
_, err = pnd.Request(mne.ID(), "/")
if err != nil {
return uuid.Nil, err
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment