Skip to content

Commit

Permalink
added save cmd for crpd
Browse files Browse the repository at this point in the history
  • Loading branch information
hellt committed Jun 28, 2021
1 parent 09af65d commit b57ef53
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
20 changes: 20 additions & 0 deletions nodes/crpd/crpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
_ "embed"
"fmt"
"io/ioutil"
"path"

log "github.com/sirupsen/logrus"
Expand All @@ -23,6 +24,8 @@ var (

//go:embed sshd_config
sshdCfg string

saveCmd = []string{"cli", "show", "conf"}
)

func init() {
Expand Down Expand Up @@ -82,6 +85,23 @@ func (s *crpd) PostDeploy(ctx context.Context, r runtime.ContainerRuntime, ns ma
func (s *crpd) WithMgmtNet(*types.MgmtNet) {}

func (s *crpd) SaveConfig(ctx context.Context, r runtime.ContainerRuntime) error {
stdout, stderr, err := r.Exec(ctx, s.cfg.LongName, saveCmd)
if err != nil {
return fmt.Errorf("%s: failed to execute cmd: %v", s.cfg.ShortName, err)
}

if len(stderr) > 0 {
return fmt.Errorf("%s errors: %s", s.cfg.ShortName, string(stderr))
}

// path by which to save a config
confPath := s.cfg.LabDir + "/config/conf-saved.conf"
err = ioutil.WriteFile(confPath, stdout, 0777)
if err != nil {
return fmt.Errorf("failed to write config by %s path from %s container: %v", confPath, s.cfg.ShortName, err)
}
log.Infof("saved cRPD configuration from %s node to %s\n", s.cfg.ShortName, confPath)

return nil
}

Expand Down
1 change: 0 additions & 1 deletion nodes/srl/srl.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ func (s *srl) Destroy(ctx context.Context, r runtime.ContainerRuntime) error {
func (s *srl) WithMgmtNet(*types.MgmtNet) {}

func (s *srl) SaveConfig(ctx context.Context, r runtime.ContainerRuntime) error {

stdout, stderr, err := r.Exec(ctx, s.cfg.LongName, saveCmd)
if err != nil {
return fmt.Errorf("%s: failed to execute cmd: %v", s.cfg.ShortName, err)
Expand Down

0 comments on commit b57ef53

Please sign in to comment.