Skip to content

Commit

Permalink
removed juniper/go-netconf in favor of scrapli
Browse files Browse the repository at this point in the history
  • Loading branch information
hellt committed Jun 24, 2021
1 parent ead63cf commit 843e658
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 54 deletions.
34 changes: 21 additions & 13 deletions cmd/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
"strings"
"sync"

"github.com/Juniper/go-netconf/netconf"
"github.com/scrapli/scrapligo/driver/base"
"github.com/scrapli/scrapligo/netconf"
"github.com/scrapli/scrapligo/transport"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/srl-labs/containerlab/clab"
Expand Down Expand Up @@ -115,28 +117,34 @@ func init() {
rootCmd.AddCommand(saveCmd)
}

// netconfSave saves the running config to the startup by means
// of invoking a netconf rpc <copy-config>
// this method is used on the network elements that can't perform a save of config via other means
func netconfSave(cont types.GenericContainer) {
kind := cont.Labels["clab-node-kind"]
config := netconf.SSHConfigPassword(clab.DefaultCredentials[kind][0],
clab.DefaultCredentials[kind][1])

host := strings.TrimLeft(cont.Names[0], "/")
ncHost := host + ":830"

s, err := netconf.DialSSH(ncHost, config)
d, err := netconf.NewNetconfDriver(
host,
base.WithAuthStrictKey(false),
base.WithAuthUsername(clab.DefaultCredentials[kind][0]),
base.WithAuthPassword(clab.DefaultCredentials[kind][1]),
base.WithTransportType(transport.StandardTransportName),
)
log.Errorf("Could not create netconf driver for %s: %+v\n", host, err)

err = d.Open()
if err != nil {
log.Errorf("%s: Could not connect SSH to %s %s", cont.Names[0], host, err)
log.Errorf("failed to open netconf driver for %s: %+v\n", host, err)
return
}
defer s.Close()

save := `<copy-config><target><startup/></target><source><running/></source></copy-config>`
defer d.Close()

_, err = s.Exec(netconf.RawMethod(save))
_, err = d.CopyConfig("running", "startup")
if err != nil {
log.Errorf("%s: Could not send Netconf save to %s %s", cont.Names[0], host, err)
log.Errorf("%s: Could not send save config via Netconf: %+v", host, err)
return
}

log.Infof("saved %s configuration from node %s\n", kind, host)
log.Infof("saved configuration from %s node\n", host)
}
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/srl-labs/containerlab
go 1.15

require (
github.com/Juniper/go-netconf v0.1.1
github.com/awalterschulze/gographviz v2.0.1+incompatible
github.com/cloudflare/cfssl v1.4.1
github.com/containerd/containerd v1.5.2
Expand All @@ -23,10 +22,10 @@ require (
github.com/olekukonko/tablewriter v0.0.5-0.20201029120751-42e21c7531a3
github.com/opencontainers/runtime-spec v1.0.3-0.20210303205135-43e4633e40c1
github.com/pkg/errors v0.9.1
github.com/scrapli/scrapligo v0.0.0-20210617193454-8a38a1b551e8
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.0.0
github.com/vishvananda/netlink v1.1.1-0.20210330154013-f5de75959ad5
github.com/ziutek/telnet v0.0.0-20180329124119-c3b780dc415b // indirect
golang.org/x/term v0.0.0-20210503060354-a79de5458b56
gopkg.in/yaml.v2 v2.4.0
)
Loading

0 comments on commit 843e658

Please sign in to comment.