github.com/emate/nomad@v0.8.2-wo-binpacking/command/server_join.go (about)

     1  package command
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  )
     7  
     8  type ServerJoinCommand struct {
     9  	Meta
    10  }
    11  
    12  func (c *ServerJoinCommand) Help() string {
    13  	helpText := `
    14  Usage: nomad server join [options] <addr> [<addr>...]
    15  
    16    Joins the local server to one or more Nomad servers. Joining is
    17    only required for server nodes, and only needs to succeed
    18    against one or more of the provided addresses. Once joined, the
    19    gossip layer will handle discovery of the other server nodes in
    20    the cluster.
    21  
    22  General Options:
    23  
    24    ` + generalOptionsUsage()
    25  	return strings.TrimSpace(helpText)
    26  }
    27  
    28  func (c *ServerJoinCommand) Synopsis() string {
    29  	return "Join server nodes together"
    30  }
    31  
    32  func (c *ServerJoinCommand) Name() string { return "server join" }
    33  
    34  func (c *ServerJoinCommand) Run(args []string) int {
    35  	flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
    36  	flags.Usage = func() { c.Ui.Output(c.Help()) }
    37  	if err := flags.Parse(args); err != nil {
    38  		return 1
    39  	}
    40  
    41  	// Check that we got at least one node
    42  	args = flags.Args()
    43  	if len(args) < 1 {
    44  		c.Ui.Error("One or more node addresses must be given as arguments")
    45  		c.Ui.Error(commandErrorText(c))
    46  		return 1
    47  	}
    48  	nodes := args
    49  
    50  	// Get the HTTP client
    51  	client, err := c.Meta.Client()
    52  	if err != nil {
    53  		c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err))
    54  		return 1
    55  	}
    56  
    57  	// Attempt the join
    58  	n, err := client.Agent().Join(nodes...)
    59  	if err != nil {
    60  		c.Ui.Error(fmt.Sprintf("Error joining: %s", err))
    61  		return 1
    62  	}
    63  
    64  	// Success
    65  	c.Ui.Output(fmt.Sprintf("Joined %d servers successfully", n))
    66  	return 0
    67  }