Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/config/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ type SBI struct {
}

type SBIGnmiOptions struct {
Encoding string `yaml:"encoding,omitempty" json:"encoding,omitempty"`
Encoding string `yaml:"encoding,omitempty" json:"encoding,omitempty"`
TargetName string `yaml:"target,omitempty" json:"target,omitempty"`
}

type SBINetconfOptions struct {
Expand Down
6 changes: 6 additions & 0 deletions pkg/datastore/target/gnmi/gnmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ func (t *gnmiTarget) Set(ctx context.Context, source targetTypes.TargetSource) (
Delete: make([]*gnmi.Path, 0, len(deletes)),
Update: make([]*gnmi.Update, 0, len(upds)),
}

// check if the target name is set, then add the prefix field
if t.cfg.GnmiOptions.TargetName != "" {
setReq.Prefix = &gnmi.Path{Target: t.cfg.GnmiOptions.TargetName}
}

for _, del := range deletes {
gdel := utils.ToGNMIPath(del)
setReq.Delete = append(setReq.Delete, gdel)
Expand Down
48 changes: 26 additions & 22 deletions pkg/server/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,52 +102,56 @@ func (s *Server) CreateDataStore(ctx context.Context, req *sdcpb.CreateDataStore
return nil, status.Errorf(codes.InvalidArgument, "datastore %s already exists", name)
}

reqTarget := req.GetTarget()
sbi := &config.SBI{
Type: req.GetTarget().GetType(),
Port: req.GetTarget().GetPort(),
Address: req.GetTarget().GetAddress(),
Type: reqTarget.GetType(),
Port: reqTarget.GetPort(),
Address: reqTarget.GetAddress(),
}

switch strings.ToLower(req.GetTarget().GetType()) {
switch strings.ToLower(reqTarget.GetType()) {
case "netconf":
netconfOpts := reqTarget.GetNetconfOpts()
commitDatastore := "candidate"
switch req.GetTarget().GetNetconfOpts().GetCommitCandidate() {
switch netconfOpts.GetCommitCandidate() {
case sdcpb.CommitCandidate_COMMIT_CANDIDATE:
case sdcpb.CommitCandidate_COMMIT_RUNNING:
commitDatastore = "running"
default:
log.Error(nil, "unknown commitDatastore", "datastore", req.GetTarget().GetNetconfOpts().GetCommitCandidate())
return nil, fmt.Errorf("unknown commitDatastore: %v", req.GetTarget().GetNetconfOpts().GetCommitCandidate())
log.Error(nil, "unknown commitDatastore", "datastore", netconfOpts.GetCommitCandidate())
return nil, fmt.Errorf("unknown commitDatastore: %v", netconfOpts.GetCommitCandidate())
}
sbi.NetconfOptions = &config.SBINetconfOptions{
IncludeNS: req.GetTarget().GetNetconfOpts().GetIncludeNs(),
OperationWithNamespace: req.GetTarget().GetNetconfOpts().GetOperationWithNs(),
UseOperationRemove: req.GetTarget().GetNetconfOpts().GetUseOperationRemove(),
IncludeNS: netconfOpts.GetIncludeNs(),
OperationWithNamespace: netconfOpts.GetOperationWithNs(),
UseOperationRemove: netconfOpts.GetUseOperationRemove(),
CommitDatastore: commitDatastore,
}

case "gnmi":
gnmiOpts := reqTarget.GetGnmiOpts()
sbi.GnmiOptions = &config.SBIGnmiOptions{
Encoding: req.GetTarget().GetGnmiOpts().GetEncoding(),
Encoding: gnmiOpts.GetEncoding(),
TargetName: gnmiOpts.GetTargetName(),
}
default:
log.Error(nil, "unknowm targetconnection protocol type", "type", req.GetTarget().GetType())
return nil, fmt.Errorf("unknowm targetconnection protocol type %s", req.GetTarget().GetType())
log.Error(nil, "unknowm targetconnection protocol type", "type", reqTarget.GetType())
return nil, fmt.Errorf("unknowm targetconnection protocol type %s", reqTarget.GetType())
}

if req.GetTarget().GetTls() != nil {
if tls := reqTarget.GetTls(); tls != nil {
sbi.TLS = &config.TLS{
CA: req.GetTarget().GetTls().GetCa(),
Cert: req.GetTarget().GetTls().GetCert(),
Key: req.GetTarget().GetTls().GetKey(),
SkipVerify: req.GetTarget().GetTls().GetSkipVerify(),
CA: tls.GetCa(),
Cert: tls.GetCert(),
Key: tls.GetKey(),
SkipVerify: tls.GetSkipVerify(),
}
}
if req.GetTarget().GetCredentials() != nil {
if creds := reqTarget.GetCredentials(); creds != nil {
sbi.Credentials = &config.Creds{
Username: req.GetTarget().GetCredentials().GetUsername(),
Password: req.GetTarget().GetCredentials().GetPassword(),
Token: req.GetTarget().GetCredentials().GetToken(),
Username: creds.GetUsername(),
Password: creds.GetPassword(),
Token: creds.GetToken(),
}
}

Expand Down
Loading