open-nomad/command/server_force_leave.go

74 lines
1.7 KiB
Go
Raw Normal View History

2015-09-11 19:31:13 +00:00
package command
import (
"fmt"
"strings"
2018-05-11 19:19:16 +00:00
"github.com/posener/complete"
2015-09-11 19:31:13 +00:00
)
type ServerForceLeaveCommand struct {
Meta
2015-09-11 19:31:13 +00:00
}
func (c *ServerForceLeaveCommand) Help() string {
2015-09-11 19:31:13 +00:00
helpText := `
2018-03-21 00:37:28 +00:00
Usage: nomad server force-leave [options] <node>
2015-09-11 19:31:13 +00:00
Forces an server to enter the "left" state. This can be used to
2015-09-11 19:31:13 +00:00
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.
General Options:
2015-09-11 19:31:13 +00:00
` + generalOptionsUsage()
2015-09-11 19:31:13 +00:00
return strings.TrimSpace(helpText)
}
func (c *ServerForceLeaveCommand) Synopsis() string {
return "Force a server into the 'left' state"
2015-09-11 19:31:13 +00:00
}
2018-05-11 19:19:16 +00:00
func (c *ServerForceLeaveCommand) AutocompleteFlags() complete.Flags {
return c.Meta.AutocompleteFlags(FlagSetClient)
}
func (c *ServerForceLeaveCommand) AutocompleteArgs() complete.Predictor {
return complete.PredictNothing
}
func (c *ServerForceLeaveCommand) Name() string { return "server force-leave" }
func (c *ServerForceLeaveCommand) Run(args []string) int {
flags := c.Meta.FlagSet(c.Name(), 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
args = flags.Args()
if len(args) != 1 {
c.Ui.Error("This command takes one argument: <node>")
c.Ui.Error(commandErrorText(c))
2015-09-11 19:31:13 +00:00
return 1
}
node := args[0]
2015-09-11 19:31:13 +00:00
// Get the HTTP client
client, err := c.Meta.Client()
2015-09-11 19:31:13 +00:00
if err != nil {
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 {
c.Ui.Error(fmt.Sprintf("Error force-leaving server %s: %s", node, err))
2015-09-11 19:31:13 +00:00
return 1
}
return 0
}