Simplifies members command to not fetch segments.

This commit is contained in:
James Phillips 2017-09-05 11:46:44 -07:00
parent e76eeadf13
commit 74d635e9c6
No known key found for this signature in database
GPG Key ID: 77183E682AC5FC11
2 changed files with 12 additions and 45 deletions

View File

@ -65,32 +65,15 @@ func (c *MembersCommand) Run(args []string) int {
return 1 return 1
} }
// Check if we queried a server and need to query for members in all segments. // Make the request.
var members []*consulapi.AgentMember opts := consulapi.MembersOpts{
if !wan && segment == "" { Segment: segment,
self, err := client.Agent().Self() WAN: wan,
if err != nil { }
c.UI.Error(fmt.Sprintf("Error retrieving agent info: %s", err)) members, err := client.Agent().MembersOpts(opts)
return 1 if err != nil {
} c.UI.Error(fmt.Sprintf("Error retrieving members: %s", err))
if self["Config"]["Server"].(bool) { return 1
segmentMembers, err := getSegmentMembers(client)
if err != nil {
c.UI.Error(fmt.Sprintf("Error retrieving members in segments: %s", err))
return 1
}
members = segmentMembers
}
} else {
var err error
members, err = client.Agent().MembersOpts(consulapi.MembersOpts{
WAN: wan,
Segment: segment,
})
if err != nil {
c.UI.Error(fmt.Sprintf("Error retrieving members: %s", err))
return 1
}
} }
// Filter the results // Filter the results
@ -99,9 +82,9 @@ func (c *MembersCommand) Run(args []string) int {
member := members[i] member := members[i]
if member.Tags["segment"] == "" { if member.Tags["segment"] == "" {
member.Tags["segment"] = "<default>" member.Tags["segment"] = "<default>"
if member.Tags["role"] == "consul" { }
member.Tags["segment"] = "<all>" if member.Tags["role"] == "consul" {
} member.Tags["segment"] = "<all>"
} }
statusString := serf.MemberStatus(member.Status).String() statusString := serf.MemberStatus(member.Status).String()
if !statusRe.MatchString(statusString) { if !statusRe.MatchString(statusString) {

View File

@ -1,16 +0,0 @@
// +build !ent
package command
import consulapi "github.com/hashicorp/consul/api"
// getSegmentMembers returns an empty list since network segments are not
// supported in OSS Consul.
func getSegmentMembers(client *consulapi.Client) ([]*consulapi.AgentMember, error) {
members, err := client.Agent().MembersOpts(consulapi.MembersOpts{})
if err != nil {
return nil, err
}
return members, nil
}