2015-09-25 18:49:31 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
2017-08-18 15:09:52 +00:00
|
|
|
|
|
|
|
"github.com/posener/complete"
|
2015-09-25 18:49:31 +00:00
|
|
|
)
|
|
|
|
|
2018-03-21 00:37:28 +00:00
|
|
|
type NodeConfigCommand struct {
|
2015-09-25 18:49:31 +00:00
|
|
|
Meta
|
|
|
|
}
|
|
|
|
|
2018-03-21 00:37:28 +00:00
|
|
|
func (c *NodeConfigCommand) Help() string {
|
2015-09-25 18:49:31 +00:00
|
|
|
helpText := `
|
2018-03-21 00:37:28 +00:00
|
|
|
Usage: nomad node config [options]
|
2015-09-25 18:49:31 +00:00
|
|
|
|
2018-03-21 00:37:28 +00:00
|
|
|
View or modify a client node's configuration details. This command only works
|
|
|
|
on client nodes, and can be used to update the running client configurations
|
|
|
|
it supports.
|
2015-09-25 18:49:31 +00:00
|
|
|
|
2018-03-21 00:37:28 +00:00
|
|
|
The arguments behave differently depending on the flags given. See each
|
|
|
|
flag's description for its specific requirements.
|
2015-09-25 18:49:31 +00:00
|
|
|
|
|
|
|
General Options:
|
|
|
|
|
2020-11-19 16:15:23 +00:00
|
|
|
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
|
2015-09-25 18:49:31 +00:00
|
|
|
|
|
|
|
Client Config Options:
|
|
|
|
|
|
|
|
-servers
|
2020-11-19 21:38:08 +00:00
|
|
|
List the known server addresses of the client node. Client nodes do not
|
|
|
|
participate in the gossip pool, and instead register with these servers
|
|
|
|
periodically over the network.
|
|
|
|
|
|
|
|
If ACLs are enabled, this option requires a token with the 'agent:read'
|
|
|
|
capability.
|
2015-09-25 18:49:31 +00:00
|
|
|
|
|
|
|
-update-servers
|
2020-11-19 21:38:08 +00:00
|
|
|
Updates the client's server list using the provided arguments. Multiple
|
|
|
|
server addresses may be passed using multiple arguments. IMPORTANT: When
|
|
|
|
updating the servers list, you must specify ALL of the server nodes you
|
|
|
|
wish to configure. The set is updated atomically.
|
|
|
|
|
|
|
|
If ACLs are enabled, this option requires a token with the 'agent:write'
|
|
|
|
capability.
|
2015-09-25 18:49:31 +00:00
|
|
|
|
|
|
|
Example:
|
2018-03-21 00:37:28 +00:00
|
|
|
$ nomad node config -update-servers foo:4647 bar:4647
|
2015-09-25 18:49:31 +00:00
|
|
|
`
|
|
|
|
return strings.TrimSpace(helpText)
|
|
|
|
}
|
|
|
|
|
2018-03-21 00:37:28 +00:00
|
|
|
func (c *NodeConfigCommand) Synopsis() string {
|
2015-09-25 18:49:31 +00:00
|
|
|
return "View or modify client configuration details"
|
|
|
|
}
|
|
|
|
|
2018-04-18 16:02:11 +00:00
|
|
|
func (c *NodeConfigCommand) Name() string { return "node config" }
|
|
|
|
|
2018-03-21 00:37:28 +00:00
|
|
|
func (c *NodeConfigCommand) Run(args []string) int {
|
2015-09-25 18:49:31 +00:00
|
|
|
var listServers, updateServers bool
|
|
|
|
|
2018-04-18 16:02:11 +00:00
|
|
|
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
|
2015-09-25 18:49:31 +00:00
|
|
|
flags.Usage = func() { c.Ui.Output(c.Help()) }
|
|
|
|
flags.BoolVar(&listServers, "servers", false, "")
|
|
|
|
flags.BoolVar(&updateServers, "update-servers", false, "")
|
|
|
|
|
|
|
|
if err := flags.Parse(args); err != nil {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
args = flags.Args()
|
|
|
|
|
|
|
|
// Check the flags for misuse
|
|
|
|
if !listServers && !updateServers {
|
2018-04-18 16:02:11 +00:00
|
|
|
c.Ui.Error("The '-servers' or '-update-servers' flag(s) must be set")
|
|
|
|
c.Ui.Error(commandErrorText(c))
|
2015-09-25 18:49:31 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the HTTP client
|
|
|
|
client, err := c.Meta.Client()
|
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if updateServers {
|
|
|
|
// Get the server addresses
|
|
|
|
if len(args) == 0 {
|
2019-05-13 14:01:19 +00:00
|
|
|
c.Ui.Error("If the '-update-servers' flag is set, at least one server argument must be provided")
|
2018-04-18 16:02:11 +00:00
|
|
|
c.Ui.Error(commandErrorText(c))
|
2015-09-25 18:49:31 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the servers list
|
|
|
|
if err := client.Agent().SetServers(args); err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error updating server list: %s", err))
|
|
|
|
return 1
|
|
|
|
}
|
2020-12-09 19:05:18 +00:00
|
|
|
c.Ui.Output("Updated server list")
|
2015-09-25 18:49:31 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
if listServers {
|
|
|
|
// Query the current server list
|
|
|
|
servers, err := client.Agent().Servers()
|
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error querying server list: %s", err))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print the results
|
|
|
|
for _, server := range servers {
|
|
|
|
c.Ui.Output(server)
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// Should not make it this far
|
|
|
|
return 1
|
|
|
|
}
|
2017-08-18 15:09:52 +00:00
|
|
|
|
2018-03-21 00:37:28 +00:00
|
|
|
func (c *NodeConfigCommand) AutocompleteFlags() complete.Flags {
|
2017-08-23 21:56:21 +00:00
|
|
|
return mergeAutocompleteFlags(c.Meta.AutocompleteFlags(FlagSetClient),
|
|
|
|
complete.Flags{
|
|
|
|
"-servers": complete.PredictNothing,
|
2017-08-23 22:52:31 +00:00
|
|
|
"-update-servers": complete.PredictAnything,
|
2017-08-23 21:56:21 +00:00
|
|
|
})
|
2017-08-18 15:09:52 +00:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:37:28 +00:00
|
|
|
func (c *NodeConfigCommand) AutocompleteArgs() complete.Predictor {
|
2017-08-18 15:09:52 +00:00
|
|
|
return complete.PredictNothing
|
|
|
|
}
|