2015-09-11 22:48:36 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AgentJoinCommand struct {
|
2015-09-14 20:13:52 +00:00
|
|
|
Meta
|
2015-09-11 22:48:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *AgentJoinCommand) Help() string {
|
|
|
|
helpText := `
|
|
|
|
Usage: nomad agent-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.
|
|
|
|
|
2015-09-14 20:13:52 +00:00
|
|
|
General Options:
|
2015-09-11 22:48:36 +00:00
|
|
|
|
2015-09-14 20:13:52 +00:00
|
|
|
` + generalOptionsUsage()
|
2015-09-11 22:48:36 +00:00
|
|
|
return strings.TrimSpace(helpText)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *AgentJoinCommand) Synopsis() string {
|
2015-09-14 20:13:52 +00:00
|
|
|
return "Join server nodes together"
|
2015-09-11 22:48:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *AgentJoinCommand) Run(args []string) int {
|
2015-09-14 20:13:52 +00:00
|
|
|
flags := c.Meta.FlagSet("agent-join", FlagSetClient)
|
2015-09-11 22:48:36 +00:00
|
|
|
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
|
2015-09-14 20:13:52 +00:00
|
|
|
args = flags.Args()
|
|
|
|
if len(args) < 1 {
|
2015-09-11 22:48:36 +00:00
|
|
|
c.Ui.Error(c.Help())
|
|
|
|
return 1
|
|
|
|
}
|
2015-09-14 20:13:52 +00:00
|
|
|
nodes := args
|
2015-09-11 22:48:36 +00:00
|
|
|
|
|
|
|
// Get the HTTP client
|
2015-09-14 20:13:52 +00:00
|
|
|
client, err := c.Meta.Client()
|
2015-09-11 22:48:36 +00:00
|
|
|
if err != nil {
|
2015-09-14 20:13:52 +00:00
|
|
|
c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err))
|
2015-09-11 22:48:36 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attempt the join
|
|
|
|
n, err := client.Agent().Join(nodes...)
|
|
|
|
if err != nil {
|
2015-09-14 20:13:52 +00:00
|
|
|
c.Ui.Error(fmt.Sprintf("Error joining: %s", err))
|
2015-09-11 22:48:36 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
// Success
|
|
|
|
c.Ui.Output(fmt.Sprintf("Joined %d nodes successfully", n))
|
|
|
|
return 0
|
|
|
|
}
|