mirror of https://github.com/status-im/consul.git
Simplifies members command to not fetch segments.
This commit is contained in:
parent
e76eeadf13
commit
74d635e9c6
|
@ -65,32 +65,15 @@ func (c *MembersCommand) Run(args []string) int {
|
|||
return 1
|
||||
}
|
||||
|
||||
// Check if we queried a server and need to query for members in all segments.
|
||||
var members []*consulapi.AgentMember
|
||||
if !wan && segment == "" {
|
||||
self, err := client.Agent().Self()
|
||||
if err != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error retrieving agent info: %s", err))
|
||||
return 1
|
||||
}
|
||||
if self["Config"]["Server"].(bool) {
|
||||
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
|
||||
}
|
||||
// Make the request.
|
||||
opts := consulapi.MembersOpts{
|
||||
Segment: segment,
|
||||
WAN: wan,
|
||||
}
|
||||
members, err := client.Agent().MembersOpts(opts)
|
||||
if err != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error retrieving members: %s", err))
|
||||
return 1
|
||||
}
|
||||
|
||||
// Filter the results
|
||||
|
@ -99,9 +82,9 @@ func (c *MembersCommand) Run(args []string) int {
|
|||
member := members[i]
|
||||
if member.Tags["segment"] == "" {
|
||||
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()
|
||||
if !statusRe.MatchString(statusString) {
|
||||
|
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue