Makes the all segments query explict, and the default for consul members.

This commit is contained in:
James Phillips 2017-09-05 12:22:20 -07:00
parent 0b44abd9db
commit c629773b40
No known key found for this signature in database
GPG key ID: 77183E682AC5FC11
7 changed files with 27 additions and 12 deletions

View file

@ -58,6 +58,7 @@ type delegate interface {
GetLANCoordinate() (lib.CoordinateSet, error) GetLANCoordinate() (lib.CoordinateSet, error)
Leave() error Leave() error
LANMembers() []serf.Member LANMembers() []serf.Member
LANMembersAllSegments() ([]serf.Member, error)
LANSegmentMembers(segment string) ([]serf.Member, error) LANSegmentMembers(segment string) ([]serf.Member, error)
LocalMember() serf.Member LocalMember() serf.Member
JoinLAN(addrs []string) (n int, err error) JoinLAN(addrs []string) (n int, err error)

View file

@ -167,14 +167,12 @@ func (s *HTTPServer) AgentMembers(resp http.ResponseWriter, req *http.Request) (
if wan { if wan {
members = s.agent.WANMembers() members = s.agent.WANMembers()
} else { } else {
// If the segment is blank when querying a client, use the agent's
// segment instead of the empty string.
if !s.agent.config.Server && segment == "" {
segment = s.agent.config.Segment
}
var err error var err error
members, err = s.agent.delegate.LANSegmentMembers(segment) if segment == api.AllSegments {
members, err = s.agent.delegate.LANMembersAllSegments()
} else {
members, err = s.agent.delegate.LANSegmentMembers(segment)
}
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -201,6 +201,11 @@ func (c *Client) LANMembers() []serf.Member {
return c.serf.Members() return c.serf.Members()
} }
// LANMembersAllSegments returns members from all segments.
func (c *Client) LANMembersAllSegments() ([]serf.Member, error) {
return c.serf.Members(), nil
}
// LANSegmentMembers only returns our own segment's members, because clients // LANSegmentMembers only returns our own segment's members, because clients
// can't be in multiple segments. // can't be in multiple segments.
func (c *Client) LANSegmentMembers(segment string) ([]serf.Member, error) { func (c *Client) LANSegmentMembers(segment string) ([]serf.Member, error) {

View file

@ -9,6 +9,11 @@ import (
"github.com/hashicorp/serf/serf" "github.com/hashicorp/serf/serf"
) )
// LANMembersAllSegments returns members from all segments.
func (s *Server) LANMembersAllSegments() ([]serf.Member, error) {
return s.LANMembers(), nil
}
// LANSegmentMembers is used to return the members of the given LAN segment. // LANSegmentMembers is used to return the members of the given LAN segment.
func (s *Server) LANSegmentMembers(segment string) ([]serf.Member, error) { func (s *Server) LANSegmentMembers(segment string) ([]serf.Member, error) {
if segment == "" { if segment == "" {

View file

@ -44,12 +44,16 @@ type AgentMember struct {
DelegateCur uint8 DelegateCur uint8
} }
// AllSegments is used to select for all segments in MembersOpts.
const AllSegments = "_all"
// MembersOpts is used for querying member information. // MembersOpts is used for querying member information.
type MembersOpts struct { type MembersOpts struct {
// WAN is whether to show members from the WAN. // WAN is whether to show members from the WAN.
WAN bool WAN bool
// Segment is the LAN segment to show members. // Segment is the LAN segment to show members for. Setting this to the
// AllSegments value above will show members in all segments.
Segment string Segment string
} }

View file

@ -44,7 +44,7 @@ func (c *MembersCommand) Run(args []string) int {
f.StringVar(&statusFilter, "status", ".*", f.StringVar(&statusFilter, "status", ".*",
"If provided, output is filtered to only nodes matching the regular "+ "If provided, output is filtered to only nodes matching the regular "+
"expression for status.") "expression for status.")
f.StringVar(&segment, "segment", "", f.StringVar(&segment, "segment", consulapi.AllSegments,
"(Enterprise-only) If provided, output is filtered to only nodes in"+ "(Enterprise-only) If provided, output is filtered to only nodes in"+
"the given segment.") "the given segment.")

View file

@ -44,9 +44,11 @@ The table below shows this endpoint's support for
members (which is the default). This is only eligible for agents running in members (which is the default). This is only eligible for agents running in
**server mode**. This is specified as part of the URL as a query parameter. **server mode**. This is specified as part of the URL as a query parameter.
- `segment` `(string: "")` - (Enterprise-only) Specifies the segment to list members in. If left blank, - `segment` `(string: "")` - (Enterprise-only) Specifies the segment to list members for.
this will query for the default segment when connecting to a server and the agent's If left blank, this will query for the default segment when connecting to a server and
own segment when connecting to a client (clients can only be part of one network segment). the agent's own segment when connecting to a client (clients can only be part of one
network segment). When querying a server, setting this to the special string `_all`
will show members in all segments.
### Sample Request ### Sample Request