hub.fastgit.org/hashicorp/consul.git@v1.4.5/command/operator/autopilot/get/operator_autopilot_get.go (about)

     1  package get
     2  
     3  import (
     4  	"flag"
     5  	"fmt"
     6  
     7  	"github.com/hashicorp/consul/api"
     8  	"github.com/hashicorp/consul/command/flags"
     9  	"github.com/mitchellh/cli"
    10  )
    11  
    12  func New(ui cli.Ui) *cmd {
    13  	c := &cmd{UI: ui}
    14  	c.init()
    15  	return c
    16  }
    17  
    18  type cmd struct {
    19  	UI    cli.Ui
    20  	flags *flag.FlagSet
    21  	http  *flags.HTTPFlags
    22  	help  string
    23  }
    24  
    25  func (c *cmd) init() {
    26  	c.flags = flag.NewFlagSet("", flag.ContinueOnError)
    27  	c.http = &flags.HTTPFlags{}
    28  	flags.Merge(c.flags, c.http.ClientFlags())
    29  	flags.Merge(c.flags, c.http.ServerFlags())
    30  	c.help = flags.Usage(help, c.flags)
    31  }
    32  
    33  func (c *cmd) Run(args []string) int {
    34  	if err := c.flags.Parse(args); err != nil {
    35  		if err == flag.ErrHelp {
    36  			return 0
    37  		}
    38  		c.UI.Error(fmt.Sprintf("Failed to parse args: %v", err))
    39  		return 1
    40  	}
    41  
    42  	// Set up a client.
    43  	client, err := c.http.APIClient()
    44  	if err != nil {
    45  		c.UI.Error(fmt.Sprintf("Error initializing client: %s", err))
    46  		return 1
    47  	}
    48  
    49  	// Fetch the current configuration.
    50  	opts := &api.QueryOptions{
    51  		AllowStale: c.http.Stale(),
    52  	}
    53  	config, err := client.Operator().AutopilotGetConfiguration(opts)
    54  	if err != nil {
    55  		c.UI.Error(fmt.Sprintf("Error querying Autopilot configuration: %s", err))
    56  		return 1
    57  	}
    58  	c.UI.Output(fmt.Sprintf("CleanupDeadServers = %v", config.CleanupDeadServers))
    59  	c.UI.Output(fmt.Sprintf("LastContactThreshold = %v", config.LastContactThreshold.String()))
    60  	c.UI.Output(fmt.Sprintf("MaxTrailingLogs = %v", config.MaxTrailingLogs))
    61  	c.UI.Output(fmt.Sprintf("ServerStabilizationTime = %v", config.ServerStabilizationTime.String()))
    62  	c.UI.Output(fmt.Sprintf("RedundancyZoneTag = %q", config.RedundancyZoneTag))
    63  	c.UI.Output(fmt.Sprintf("DisableUpgradeMigration = %v", config.DisableUpgradeMigration))
    64  	c.UI.Output(fmt.Sprintf("UpgradeVersionTag = %q", config.UpgradeVersionTag))
    65  
    66  	return 0
    67  }
    68  
    69  func (c *cmd) Synopsis() string {
    70  	return synopsis
    71  }
    72  
    73  func (c *cmd) Help() string {
    74  	return c.help
    75  }
    76  
    77  const synopsis = "Display the current Autopilot configuration"
    78  const help = `
    79  Usage: consul operator autopilot get-config [options]
    80  
    81    Displays the current Autopilot configuration.
    82  `