-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathdoc.go
91 lines (91 loc) · 2.42 KB
/
doc.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Package gornir provides a pluggable framework with inventory management to help operate
// collections of devices.
// It's similar to https://github.com/nornir-automation/nornir/ but in Go.
//
// The goal is to be able to operate on many devices with little effort. For instance:
//
// package main
//
// import (
// "context"
// "os"
//
// "github.com/nornir-automation/gornir/pkg/gornir"
// "github.com/nornir-automation/gornir/pkg/plugins/connection"
// "github.com/nornir-automation/gornir/pkg/plugins/inventory"
// "github.com/nornir-automation/gornir/pkg/plugins/logger"
// "github.com/nornir-automation/gornir/pkg/plugins/output"
// "github.com/nornir-automation/gornir/pkg/plugins/runner"
// "github.com/nornir-automation/gornir/pkg/plugins/task"
// )
//
// func main() {
// log := logger.NewLogrus(false)
//
// file := "/go/src/github.com/nornir-automation/gornir/examples/hosts.yaml"
// plugin := inventory.FromYAML{HostsFile: file}
// inv, err := plugin.Create()
// if err != nil {
// log.Fatal(err)
// }
//
// gr := gornir.New().WithInventory(inv).WithLogger(log).WithRunner(runner.Parallel())
//
// results, err := gr.RunSync(
// context.Background(),
// &connection.SSHOpen{},
// )
// if err != nil {
// log.Fatal(err)
// }
//
// // defer closing the SSH connection we just opened
// defer func() {
// results, err = gr.RunSync(
// context.Background(),
// &connection.SSHClose{},
// )
// if err != nil {
// log.Fatal(err)
// }
// }()
//
// results, err = gr.RunSync(
// context.Background(),
// &task.RemoteCommand{Command: "ip addr | grep \\/24 | awk '{ print $2 }'"},
// )
// if err != nil {
// log.Fatal(err)
// }
// output.RenderResults(os.Stdout, results, "What is my ip?", true)
// }
//
// would render:
//
// # What is my ip?
// @ dev5.no_group
// - err: failed to retrieve connection: couldn't find connection
//
// @ dev1.group_1
// - stdout: 10.21.33.101/24
//
// - stderr:
// @ dev6.no_group
// - stdout: 10.21.33.106/24
//
// - stderr:
// @ dev4.group_2
// - stdout: 10.21.33.104/24
//
// - stderr:
// @ dev3.group_2
// - stdout: 10.21.33.103/24
//
// - stderr:
// @ dev2.group_1
// - stdout: 10.21.33.102/24
//
// - stderr:
//
// You can see more examples here: https://github.com/nornir-automation/gornir/tree/master/examples
package gornir