-
Notifications
You must be signed in to change notification settings - Fork 1
/
node.go
195 lines (158 loc) · 3.76 KB
/
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
193
194
195
// Code generated by lesiw.io/ctrctl. DO NOT EDIT.
package ctrctl
import (
"fmt"
"os/exec"
)
type NodeDemoteOpts struct {
// Base exec.Cmd.
Cmd *exec.Cmd
// Print usage.
Help bool
}
// Demote one or more nodes from manager in the swarm.
func NodeDemote(opts *NodeDemoteOpts, node ...string) (string, error) {
if len(node) == 0 {
return "", fmt.Errorf("node must have at least one value")
}
return runCtrCmd(
[]string{"node", "demote"},
node,
opts,
-1,
)
}
type NodeInspectOpts struct {
// Base exec.Cmd.
Cmd *exec.Cmd
// Format output using a custom template:
// 'json': Print in JSON format.
// 'TEMPLATE': Print output using the given Go template.
// Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates.
Format string
// Print usage.
Help bool
// Print the information in a human friendly format.
Pretty bool
}
// Display detailed information on one or more nodes.
func NodeInspect(opts *NodeInspectOpts, selfNode string, node ...string) (string, error) {
return runCtrCmd(
[]string{"node", "inspect"},
append([]string{selfNode}, node...),
opts,
0,
)
}
type NodeLsOpts struct {
// Base exec.Cmd.
Cmd *exec.Cmd
// Filter output based on conditions provided.
Filter string
// Format output using a custom template:
// 'table': Print output in table format with column headers (default).
// 'table TEMPLATE': Print output in table format using the given Go template.
// 'json': Print in JSON format.
// 'TEMPLATE': Print output using the given Go template.
// Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates.
Format string
// Print usage.
Help bool
// Only display IDs.
Quiet bool
}
// List nodes in the swarm.
func NodeLs(opts *NodeLsOpts) (string, error) {
return runCtrCmd(
[]string{"node", "ls"},
[]string{},
opts,
0,
)
}
type NodePromoteOpts struct {
// Base exec.Cmd.
Cmd *exec.Cmd
// Print usage.
Help bool
}
// Promote one or more nodes to manager in the swarm.
func NodePromote(opts *NodePromoteOpts, node ...string) (string, error) {
if len(node) == 0 {
return "", fmt.Errorf("node must have at least one value")
}
return runCtrCmd(
[]string{"node", "promote"},
node,
opts,
-1,
)
}
type NodePsOpts struct {
// Base exec.Cmd.
Cmd *exec.Cmd
// Filter output based on conditions provided.
Filter string
// Pretty-print tasks using a Go template.
Format string
// Print usage.
Help bool
// Do not map IDs to Names.
NoResolve bool
// Do not truncate output.
NoTrunc bool
// Only display task IDs.
Quiet bool
}
// List tasks running on one or more nodes, defaults to current node.
func NodePs(opts *NodePsOpts, node ...string) (string, error) {
return runCtrCmd(
[]string{"node", "ps"},
node,
opts,
0,
)
}
type NodeRmOpts struct {
// Base exec.Cmd.
Cmd *exec.Cmd
// Force remove a node from the swarm.
Force bool
// Print usage.
Help bool
}
// Remove one or more nodes from the swarm.
func NodeRm(opts *NodeRmOpts, node ...string) (string, error) {
if len(node) == 0 {
return "", fmt.Errorf("node must have at least one value")
}
return runCtrCmd(
[]string{"node", "rm"},
node,
opts,
0,
)
}
type NodeUpdateOpts struct {
// Base exec.Cmd.
Cmd *exec.Cmd
// Availability of the node (`active`, `pause`, `drain`).
Availability string
// Print usage.
Help bool
// Add or update a node label (`key=value`).
LabelAdd []string
// Remove a node label if exists.
LabelRm []string
// Role of the node (`worker`, `manager`).
Role string
}
// Update a node.
func NodeUpdate(opts *NodeUpdateOpts, node string) (string, error) {
return runCtrCmd(
[]string{"node", "update"},
[]string{node},
opts,
0,
)
}