open-nomad/api/regions.go
Tim Gross f8a133a810
cli: ensure -stale flag is respected by nomad operator debug (#11678)
When a cluster doesn't have a leader, the `nomad operator debug`
command can safely use stale queries to gracefully degrade the
consistency of almost all its queries. The query parameter for these
API calls was not being set by the command.

Some `api` package queries do not include `QueryOptions` because
they target a specific agent, but they can potentially be forwarded to
other agents. If there is no leader, these forwarded queries will
fail. Provide methods to call these APIs with `QueryOptions`.
2021-12-15 10:44:03 -05:00

25 lines
567 B
Go

package api
import "sort"
// Regions is used to query the regions in the cluster.
type Regions struct {
client *Client
}
// Regions returns a handle on the regions endpoints.
func (c *Client) Regions() *Regions {
return &Regions{client: c}
}
// List returns a list of all of the regions from the server
// that serves the request. It is never forwarded to a leader.
func (r *Regions) List() ([]string, error) {
var resp []string
if _, err := r.client.query("/v1/regions", &resp, nil); err != nil {
return nil, err
}
sort.Strings(resp)
return resp, nil
}