Makes the all segments query explict, and the default for `consul members`.
This commit is contained in:
parent
0b44abd9db
commit
c629773b40
|
@ -58,6 +58,7 @@ type delegate interface {
|
|||
GetLANCoordinate() (lib.CoordinateSet, error)
|
||||
Leave() error
|
||||
LANMembers() []serf.Member
|
||||
LANMembersAllSegments() ([]serf.Member, error)
|
||||
LANSegmentMembers(segment string) ([]serf.Member, error)
|
||||
LocalMember() serf.Member
|
||||
JoinLAN(addrs []string) (n int, err error)
|
||||
|
|
|
@ -167,14 +167,12 @@ func (s *HTTPServer) AgentMembers(resp http.ResponseWriter, req *http.Request) (
|
|||
if wan {
|
||||
members = s.agent.WANMembers()
|
||||
} 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
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -201,6 +201,11 @@ func (c *Client) LANMembers() []serf.Member {
|
|||
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
|
||||
// can't be in multiple segments.
|
||||
func (c *Client) LANSegmentMembers(segment string) ([]serf.Member, error) {
|
||||
|
|
|
@ -9,6 +9,11 @@ import (
|
|||
"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.
|
||||
func (s *Server) LANSegmentMembers(segment string) ([]serf.Member, error) {
|
||||
if segment == "" {
|
||||
|
|
|
@ -44,12 +44,16 @@ type AgentMember struct {
|
|||
DelegateCur uint8
|
||||
}
|
||||
|
||||
// AllSegments is used to select for all segments in MembersOpts.
|
||||
const AllSegments = "_all"
|
||||
|
||||
// MembersOpts is used for querying member information.
|
||||
type MembersOpts struct {
|
||||
// WAN is whether to show members from the WAN.
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ func (c *MembersCommand) Run(args []string) int {
|
|||
f.StringVar(&statusFilter, "status", ".*",
|
||||
"If provided, output is filtered to only nodes matching the regular "+
|
||||
"expression for status.")
|
||||
f.StringVar(&segment, "segment", "",
|
||||
f.StringVar(&segment, "segment", consulapi.AllSegments,
|
||||
"(Enterprise-only) If provided, output is filtered to only nodes in"+
|
||||
"the given segment.")
|
||||
|
||||
|
|
|
@ -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
|
||||
**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,
|
||||
this will query for the default segment when connecting to a server and the agent's
|
||||
own segment when connecting to a client (clients can only be part of one network segment).
|
||||
- `segment` `(string: "")` - (Enterprise-only) Specifies the segment to list members for.
|
||||
If left blank, this will query for the default segment when connecting to a server and
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue