-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrun_node.go
192 lines (148 loc) · 4.33 KB
/
run_node.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package main
import (
"fmt"
"github.com/jawher/mow.cli"
"github.com/pki-io/controller"
)
func nodeCmd(cmd *cli.Cmd) {
cmd.Command("new", "Create a new node", nodeNewCmd)
cmd.Command("run", "Run tasks for node", nodeRunCmd)
cmd.Command("cert", "Get certificates for node", nodeCertCmd)
cmd.Command("list", "List nodes", nodeListCmd)
cmd.Command("show", "Show a node", nodeShowCmd)
cmd.Command("delete", "Delete a node", nodeDeleteCmd)
}
func nodeNewCmd(cmd *cli.Cmd) {
cmd.Spec = "NAME [OPTIONS] [--host --agent-file -- [SSH_OPTIONS]]"
params := controller.NewNodeParams()
params.Name = cmd.StringArg("NAME", "", "name of node")
params.PairingId = cmd.StringOpt("pairing-id", "", "pairing id")
params.PairingKey = cmd.StringOpt("pairing-key", "", "pairing key")
params.Host = cmd.StringOpt("host", "", "node hostname or ip address")
params.AgentFile = cmd.StringOpt("agent-file", "", "path to agent package")
params.InstallFile = cmd.StringOpt("install-file", "./agent-installer.sh", "path to agent installer script")
params.SSHOptions = cmd.StringArg("SSH_OPTIONS", "", "arguments to pass to ssh NOT WORKING YET")
cmd.Action = func() {
app := NewAdminApp()
logger.Info("creating new node")
cont, err := controller.NewNode(app.env)
if err != nil {
app.Fatal(err)
}
node, err := cont.New(params)
if err != nil {
app.Fatal(err)
}
if node != nil {
table := app.NewTable()
table.SetHeader([]string{"Name", "Id"})
table.Append([]string{node.Name(), node.Id()})
app.RenderTable(table)
}
}
}
func nodeRunCmd(cmd *cli.Cmd) {
cmd.Spec = "NAME [OPTIONS]"
params := controller.NewNodeParams()
params.Name = cmd.StringArg("NAME", "", "name of node")
cmd.Action = func() {
app := NewAdminApp()
logger.Info("running node tasks")
cont, err := controller.NewNode(app.env)
if err != nil {
app.Fatal(err)
}
if err := cont.Run(params); err != nil {
app.Fatal(err)
}
}
}
func nodeCertCmd(cmd *cli.Cmd) {
cmd.Spec = "NAME [OPTIONS]"
params := controller.NewNodeParams()
params.Name = cmd.StringArg("NAME", "", "name of node")
params.Tags = cmd.StringOpt("tags", "NAME", "comma separated list of tags")
params.Export = cmd.StringOpt("export", "", "tar.gz export to file")
params.Private = cmd.BoolOpt("private", false, "show/export private data")
cmd.Action = func() {
app := NewAdminApp()
logger.Info("creating node certificate")
cont, err := controller.NewNode(app.env)
if err != nil {
app.Fatal(err)
}
if err := cont.Cert(params); err != nil {
app.Fatal(err)
}
}
}
func nodeListCmd(cmd *cli.Cmd) {
cmd.Spec = "[OPTIONS]"
params := controller.NewNodeParams()
cmd.Action = func() {
app := NewAdminApp()
logger.Info("listing nodes")
cont, err := controller.NewNode(app.env)
if err != nil {
app.Fatal(err)
}
nodes, err := cont.List(params)
if err != nil {
app.Fatal(err)
}
table := app.NewTable()
table.SetHeader([]string{"Name", "Id"})
for _, node := range nodes {
table.Append([]string{node.Name(), node.Id()})
}
app.RenderTable(table)
app.Exit()
}
}
func nodeShowCmd(cmd *cli.Cmd) {
cmd.Spec = "NAME [OPTIONS]"
params := controller.NewNodeParams()
params.Name = cmd.StringArg("NAME", "", "name of node")
cmd.Action = func() {
app := NewAdminApp()
logger.Info("showing node")
cont, err := controller.NewNode(app.env)
if err != nil {
app.Fatal(err)
}
node, err := cont.Show(params)
if err != nil {
app.Fatal(err)
}
if node != nil {
table := app.NewTable()
nodeData := [][]string{
[]string{"ID", node.Id()},
[]string{"Name", node.Name()},
[]string{"Key type", node.Data.Body.KeyType},
}
table.AppendBulk(nodeData)
app.RenderTable(table)
fmt.Println("")
fmt.Printf("Public signing key:\n%s\n", node.Data.Body.PublicSigningKey)
fmt.Printf("Public encryption key:\n%s\n", node.Data.Body.PublicEncryptionKey)
}
}
}
func nodeDeleteCmd(cmd *cli.Cmd) {
cmd.Spec = "NAME [OPTIONS]"
params := controller.NewNodeParams()
params.Name = cmd.StringArg("NAME", "", "name of node")
params.ConfirmDelete = cmd.StringOpt("confirm-delete", "", "reason for deleting node")
cmd.Action = func() {
app := NewAdminApp()
logger.Info("deleting node")
cont, err := controller.NewNode(app.env)
if err != nil {
app.Fatal(err)
}
if err := cont.Delete(params); err != nil {
app.Fatal(err)
}
}
}