-
Notifications
You must be signed in to change notification settings - Fork 17
/
main.go
59 lines (50 loc) · 1.36 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"flag"
"fmt"
"os"
"log"
"math/rand"
"time"
xr "github.com/nleiva/xrgrpc"
)
func timeTrack(start time.Time) {
elapsed := time.Since(start)
log.Printf("This process took %s\n", elapsed)
}
func main() {
// To time this process
defer timeTrack(time.Now())
// YANG path arguments; defaults to "yangocpaths.json"
ypath := flag.String("ypath", "../input/yangocpaths.json", "YANG path arguments")
flag.Parse()
// Determine the ID for the transaction.
r := rand.New(rand.NewSource(time.Now().UnixNano()))
id := r.Int63n(10000)
var output string
// Manually specify target parameters.
router, err := xr.BuildRouter(
xr.WithUsername("admin"),
xr.WithPassword("C1sco12345"),
xr.WithHost("sandbox-iosxr-1.cisco.com:57777"),
xr.WithTimeout(5),
)
if err != nil {
log.Fatalf("could not build a router, %v", err)
}
conn, ctx, err := xr.Connect(*router)
if err != nil {
log.Fatalf("could not setup a client connection to %s, %v", router.Host, err)
}
defer conn.Close()
// Get config for the YANG paths specified on 'js'
js, err := os.ReadFile(*ypath)
if err != nil {
log.Fatalf("could not read file: %v: %v\n", *ypath, err)
}
output, err = xr.GetConfig(ctx, conn, string(js), id)
if err != nil {
log.Fatalf("could not get the config from %s, %v", router.Host, err)
}
fmt.Printf("\nconfig from %s\n %s\n", router.Host, output)
}