forked from hashicorp/nomad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_join.go
64 lines (52 loc) · 1.35 KB
/
server_join.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
package command
import (
"fmt"
"strings"
)
type ServerJoinCommand struct {
Meta
}
func (c *ServerJoinCommand) Help() string {
helpText := `
Usage: nomad server-join [options] <addr> [<addr>...]
Joins the local server to one or more Nomad servers. Joining is
only required for server nodes, and only needs to succeed
against one or more of the provided addresses. Once joined, the
gossip layer will handle discovery of the other server nodes in
the cluster.
General Options:
` + generalOptionsUsage()
return strings.TrimSpace(helpText)
}
func (c *ServerJoinCommand) Synopsis() string {
return "Join server nodes together"
}
func (c *ServerJoinCommand) Run(args []string) int {
flags := c.Meta.FlagSet("server-join", FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
if err := flags.Parse(args); err != nil {
return 1
}
// Check that we got at least one node
args = flags.Args()
if len(args) < 1 {
c.Ui.Error(c.Help())
return 1
}
nodes := args
// Get the HTTP client
client, err := c.Meta.Client()
if err != nil {
c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err))
return 1
}
// Attempt the join
n, err := client.Agent().Join(nodes...)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error joining: %s", err))
return 1
}
// Success
c.Ui.Output(fmt.Sprintf("Joined %d servers successfully", n))
return 0
}