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