Skip to content

Commit

Permalink
Merge pull request #4321 from hashicorp/f-network-info
Browse files Browse the repository at this point in the history
Display bind/advertise addresses on agent startup
  • Loading branch information
dadgar authored May 24, 2018
2 parents 267a858 + df70a93 commit 5803932
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions command/agent/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,8 @@ func (c *Command) Run(args []string) int {
info["log level"] = config.LogLevel
info["server"] = strconv.FormatBool(config.Server.Enabled)
info["region"] = fmt.Sprintf("%s (DC: %s)", config.Region, config.Datacenter)
info["bind addrs"] = c.getBindAddrSynopsis()
info["advertise addrs"] = c.getAdvertiseAddrSynopsis()

// Sort the keys for output
infoKeys := make([]string, 0, len(info))
Expand Down Expand Up @@ -843,6 +845,50 @@ func (c *Command) startupJoin(config *Config) error {
return nil
}

// getBindAddrSynopsis returns a string that describes the addresses the agent
// is bound to.
func (c *Command) getBindAddrSynopsis() string {
if c == nil || c.agent == nil || c.agent.config == nil || c.agent.config.normalizedAddrs == nil {
return ""
}

b := new(strings.Builder)
fmt.Fprintf(b, "HTTP: %s", c.agent.config.normalizedAddrs.HTTP)

if c.agent.server != nil {
if c.agent.config.normalizedAddrs.RPC != "" {
fmt.Fprintf(b, "; RPC: %s", c.agent.config.normalizedAddrs.RPC)
}
if c.agent.config.normalizedAddrs.Serf != "" {
fmt.Fprintf(b, "; Serf: %s", c.agent.config.normalizedAddrs.Serf)
}
}

return b.String()
}

// getAdvertiseAddrSynopsis returns a string that describes the addresses the agent
// is advertising.
func (c *Command) getAdvertiseAddrSynopsis() string {
if c == nil || c.agent == nil || c.agent.config == nil || c.agent.config.AdvertiseAddrs == nil {
return ""
}

b := new(strings.Builder)
fmt.Fprintf(b, "HTTP: %s", c.agent.config.AdvertiseAddrs.HTTP)

if c.agent.server != nil {
if c.agent.config.AdvertiseAddrs.RPC != "" {
fmt.Fprintf(b, "; RPC: %s", c.agent.config.AdvertiseAddrs.RPC)
}
if c.agent.config.AdvertiseAddrs.Serf != "" {
fmt.Fprintf(b, "; Serf: %s", c.agent.config.AdvertiseAddrs.Serf)
}
}

return b.String()
}

func (c *Command) Synopsis() string {
return "Runs a Nomad agent"
}
Expand Down

0 comments on commit 5803932

Please sign in to comment.