Skip to content

Commit

Permalink
use trans_util for save on set
Browse files Browse the repository at this point in the history
  • Loading branch information
rlucus committed Oct 30, 2023
1 parent e28fd28 commit add7f88
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions gnmi_server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"errors"
"fmt"
"github.com/Azure/sonic-mgmt-common/translib"
log "github.com/golang/glog"
"github.com/golang/protobuf/proto"
gnmipb "github.com/openconfig/gnmi/proto/gnmi"
Expand All @@ -15,6 +14,7 @@ import (
spb_gnoi "github.com/sonic-net/sonic-gnmi/proto/gnoi"
spb_jwt_gnoi "github.com/sonic-net/sonic-gnmi/proto/gnoi/jwt"
sdc "github.com/sonic-net/sonic-gnmi/sonic_data_client"
transutil "github.com/Azure/sonic-gnmi/transl_utils"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -43,7 +43,7 @@ type Server struct {
// SaveStartupConfig points to a function that is called to save changes of
// configuration to a file. By default it points to an empty function -
// the configuration is not saved to a file.
SaveStartupConfig func()
SaveStartupConfig func(ctx context.Context)

// ReqFromMaster point to a function that is called to verify if the request
// comes from a master controller.
Expand Down Expand Up @@ -399,16 +399,18 @@ func (s *Server) Get(ctx context.Context, req *gnmipb.GetRequest) (*gnmipb.GetRe
}

// saveOnSetEnabled saves configuration to a file
func saveOnSetEnabled() {
if err := translib.SaveStartupConfig(); err != nil {
func SaveOnSetEnabled(ctx context.Context) {
const reqstr = "{\"source\":\"running-configuration\",\"destination\":\"startup-configuration\",\"copy-config-option\":\"SAVE\"}"

if _, err := transutil.TranslProcessAction("/oc-file-mgmt-private:copy", []byte(reqstr), ctx); err != nil {
log.Errorf("Saving startup config failed: %v", err)
} else {
log.Info("Success! Startup config has been saved!")
}
}

// SaveOnSetDisabeld does nothing.
func saveOnSetDisabled() {}
func saveOnSetDisabled(ctx context.Context) {}

func (s *Server) Set(ctx context.Context, req *gnmipb.SetRequest) (*gnmipb.SetResponse, error) {
e := s.ReqFromMaster(req, &s.masterEID)
Expand Down Expand Up @@ -513,7 +515,7 @@ func (s *Server) Set(ctx context.Context, req *gnmipb.SetRequest) (*gnmipb.SetRe
common_utils.IncCounter(common_utils.GNMI_SET_FAIL)
}

s.SaveStartupConfig()
s.SaveStartupConfig(ctx)
return &gnmipb.SetResponse{
Prefix: req.GetPrefix(),
Response: results,
Expand Down

0 comments on commit add7f88

Please sign in to comment.