2015-09-11 19:31:13 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AgentForceLeaveCommand struct {
|
2015-09-14 20:13:52 +00:00
|
|
|
Meta
|
2015-09-11 19:31:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *AgentForceLeaveCommand) Help() string {
|
|
|
|
helpText := `
|
|
|
|
Usage: nomad agent-force-leave [options] <node>
|
|
|
|
|
|
|
|
Forces an agent to enter the "left" state. This can be used to
|
|
|
|
eject nodes which have failed and will not rejoin the cluster.
|
|
|
|
Note that if the member is actually still alive, it will
|
|
|
|
eventually rejoin the cluster again.
|
|
|
|
|
2015-09-14 20:13:52 +00:00
|
|
|
General Options:
|
2015-09-11 19:31:13 +00:00
|
|
|
|
2015-09-14 20:13:52 +00:00
|
|
|
` + generalOptionsUsage()
|
2015-09-11 19:31:13 +00:00
|
|
|
return strings.TrimSpace(helpText)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *AgentForceLeaveCommand) Synopsis() string {
|
2015-09-14 20:13:52 +00:00
|
|
|
return "Force a member into the 'left' state"
|
2015-09-11 19:31:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *AgentForceLeaveCommand) Run(args []string) int {
|
2015-09-14 20:13:52 +00:00
|
|
|
flags := c.Meta.FlagSet("force-leave", FlagSetClient)
|
2015-09-11 19:31:13 +00:00
|
|
|
flags.Usage = func() { c.Ui.Output(c.Help()) }
|
|
|
|
if err := flags.Parse(args); err != nil {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that we got exactly one node
|
2015-09-14 20:13:52 +00:00
|
|
|
args = flags.Args()
|
|
|
|
if len(args) != 1 {
|
2015-09-11 19:31:13 +00:00
|
|
|
c.Ui.Error(c.Help())
|
|
|
|
return 1
|
|
|
|
}
|
2015-09-14 20:13:52 +00:00
|
|
|
node := args[0]
|
2015-09-11 19:31:13 +00:00
|
|
|
|
|
|
|
// Get the HTTP client
|
2015-09-14 20:13:52 +00:00
|
|
|
client, err := c.Meta.Client()
|
2015-09-11 19:31:13 +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 19:31:13 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call force-leave on the node
|
|
|
|
if err := client.Agent().ForceLeave(node); err != nil {
|
2015-09-14 20:13:52 +00:00
|
|
|
c.Ui.Error(fmt.Sprintf("Error force-leaving node %s: %s", node, err))
|
2015-09-11 19:31:13 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|