github.com/huiliang/nomad@v0.2.1-0.20151124023127-7a8b664699ff/command/client_config.go (about) 1 package command 2 3 import ( 4 "fmt" 5 "strings" 6 ) 7 8 type ClientConfigCommand struct { 9 Meta 10 } 11 12 func (c *ClientConfigCommand) Help() string { 13 helpText := ` 14 Usage: nomad client-config [options] 15 16 View or modify client configuration details. This command only 17 works on client nodes, and can be used to update the running 18 client configurations it supports. 19 20 The arguments behave differently depending on the flags given. 21 See each flag's description for its specific requirements. 22 23 General Options: 24 25 ` + generalOptionsUsage() + ` 26 27 Client Config Options: 28 29 -servers 30 List the known server addresses of the client node. Client 31 nodes do not participate in the gossip pool, and instead 32 register with these servers periodically over the network. 33 34 -update-servers 35 Updates the client's server list using the provided 36 arguments. Multiple server addresses may be passed using 37 multiple arguments. IMPORTANT: When updating the servers 38 list, you must specify ALL of the server nodes you wish 39 to configure. The set is updated atomically. 40 41 Example: 42 $ nomad client-config -update-servers foo:4647 bar:4647 43 ` 44 return strings.TrimSpace(helpText) 45 } 46 47 func (c *ClientConfigCommand) Synopsis() string { 48 return "View or modify client configuration details" 49 } 50 51 func (c *ClientConfigCommand) Run(args []string) int { 52 var listServers, updateServers bool 53 54 flags := c.Meta.FlagSet("client-servers", FlagSetClient) 55 flags.Usage = func() { c.Ui.Output(c.Help()) } 56 flags.BoolVar(&listServers, "servers", false, "") 57 flags.BoolVar(&updateServers, "update-servers", false, "") 58 59 if err := flags.Parse(args); err != nil { 60 return 1 61 } 62 args = flags.Args() 63 64 // Check the flags for misuse 65 if !listServers && !updateServers { 66 c.Ui.Error(c.Help()) 67 return 1 68 } 69 70 // Get the HTTP client 71 client, err := c.Meta.Client() 72 if err != nil { 73 c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err)) 74 return 1 75 } 76 77 if updateServers { 78 // Get the server addresses 79 if len(args) == 0 { 80 c.Ui.Error(c.Help()) 81 return 1 82 } 83 84 // Set the servers list 85 if err := client.Agent().SetServers(args); err != nil { 86 c.Ui.Error(fmt.Sprintf("Error updating server list: %s", err)) 87 return 1 88 } 89 return 0 90 } 91 92 if listServers { 93 // Query the current server list 94 servers, err := client.Agent().Servers() 95 if err != nil { 96 c.Ui.Error(fmt.Sprintf("Error querying server list: %s", err)) 97 return 1 98 } 99 100 // Print the results 101 for _, server := range servers { 102 c.Ui.Output(server) 103 } 104 return 0 105 } 106 107 // Should not make it this far 108 return 1 109 }