Something went wrong. Try again.
NETCONF implementation in Go.
Something went wrong. Try again.
netconf example_ssh_test.go
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051package netconf_test
import ( "context" "log" "time"
"github.com/nemith/netconf" ncssh "github.com/nemith/netconf/transport/ssh" "golang.org/x/crypto/ssh")
const sshAddr = "myrouter.example.com:830"
func Example_ssh() { config := &ssh.ClientConfig{ User: "admin", Auth: []ssh.AuthMethod{ ssh.Password("secret"), }, }
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel()
transport, err := ncssh.Dial(ctx, "tcp", sshAddr, config) if err != nil { panic(err) } defer transport.Close()
session, err := netconf.Open(transport) if err != nil { panic(err) }
// timeout for the call itself. ctx, cancel = context.WithTimeout(ctx, 5*time.Second) defer cancel() deviceConfig, err := session.GetConfig(ctx, "running") if err != nil { log.Fatalf("failed to get config: %v", err) }
log.Printf("Config:\n%s\n", deviceConfig)
if err := session.Close(context.Background()); err != nil { log.Print(err) }}