// GetRegions returns a list of all available Vultr regions
172515
func (c *Client) GetRegions() ([]Region, error) {
	var regionMap map[string]Region
	if err := c.get(`regions/list`, &regionMap); err != nil {
		return nil, err
	}

	var regionList []Region
	for _, os := range regionMap {
		regionList = append(regionList, os)
	}
	sort.Sort(regions(regionList))
	return regionList, nil
}
48070
func getRegionFromZones(zones []string) (string, error) {
	regions := sets.String{}
	if len(zones) < 1 {
		return "", fmt.Errorf("no zones specified")
	}
	for _, zone := range zones {
		// Zone expected format {locale}-{region}-{zone}
		splitZone := strings.Split(zone, "-")
		if len(splitZone) != 3 {
			return "", fmt.Errorf("zone in unexpected format, expected: {locale}-{region}-{zone}, got: %v", zone)
		}
		regions.Insert(strings.Join(splitZone[0:2], "-"))
	}
	if regions.Len() != 1 {
		return "", fmt.Errorf("multiple or no regions gotten from zones, got: %v", regions)
	}
	return regions.UnsortedList()[0], nil
}
19650
func (v *ListTypeVersioningV2) GetStrings() (o []string) {
	if v != nil && v.Strings != nil {
		return v.Strings
	}

	return
}
429406
func (p Partition) Regions() map[string]Region {
	rs := map[string]Region{}
	for id, r := range p.p.Regions {
		rs[id] = Region{
			id:   id,
			desc: r.Description,
			p:    p.p,
		}
	}

	return rs
}
1034785
func FindRegion(cluster *kops.Cluster) (string, error) {

	zones := []string{}
	for _, subnet := range cluster.Spec.Subnets {
		zones = append(zones, subnet.Zone)
	}
	return getRegionByZones(zones)

}
159841
func (l *Client) GetSegments(table string) ([]*Segment, error) {
	res := ApiResp{}
	data := []*Segment{}
	params := url.Values{}

	params.Add("table", table)

	// make the request
	err := l.Get(segmentListEndpoint, params, nil, &res, &data)
	if err != nil {
		return data, err
	}

	return data, nil
}
1157708
func (s *Service) AddOnRegionCapabilityList(ctx context.Context, lr *ListRange) (AddOnRegionCapabilityListResult, error) {
	var addOnRegionCapability AddOnRegionCapabilityListResult
	return addOnRegionCapability, s.Get(ctx, &addOnRegionCapability, fmt.Sprintf("/addon-region-capabilities"), nil, lr)
}
690135
func (ud *UltraDns) GetRRsets(zName string, offset, limit int) ([]RRSet, ResultInfo, error) {
	var Res struct {
		ZName  string     `json:"zoneName"`
		QInfo  QueryInfo  `json:"queryInfo"`
		RInfo  ResultInfo `json:"resultInfo"`
		RRSets []RRSet    `json:"rrSets"`
	}

	_, body, err := ud.Client.Get(UltraHost+"/v1/zones/"+zName+"/rrsets").
		Query("offset="+strconv.Itoa(offset)).
		Query("&limit="+strconv.Itoa(limit)).
		Set("Authorization", ud.tokenHeader).End()
	if err != nil {
		return Res.RRSets, Res.RInfo, errors.New("Authentication Failed")
	}

	errr := json.Unmarshal([]byte(body), &Res)
	if errr != nil {
		return Res.RRSets, Res.RInfo, errors.New("Unmarshal Error")
	}

	return Res.RRSets, Res.RInfo, nil
}
175679
func ZonesOfRegion(hc *http.Client, project, region string) (zones []string, err error) {
	s, err := compute.New(hc)
	if err != nil {
		return nil, err
	}
	zl, err := compute.NewZonesService(s).List(project).Do()
	if err != nil {
		return nil, fmt.Errorf("could not get a list of zones: %v", err)
	}
	if zl.NextPageToken != "" {
		return nil, errors.New("TODO: more than one page of zones found; use NextPageToken")
	}
	for _, z := range zl.Items {
		if path.Base(z.Region) != region {
			continue
		}
		zones = append(zones, z.Name)
	}
	return zones, nil
}
893404
func (gce *Cloud) GetAllZones() (sets.String, error) {
	// Fast-path for non-multizone
	if len(gce.managedZones) == 1 {
		return sets.NewString(gce.managedZones...), nil
	}

	// TODO: Caching, but this is currently only called when we are creating a volume,
	// which is a relatively infrequent operation, and this is only # zones API calls
	zones := sets.NewString()

	// TODO: Parallelize, although O(zones) so not too bad (N <= 3 typically)
	for _, zone := range gce.managedZones {
		// We only retrieve one page in each zone - we only care about existence
		listCall := gce.service.Instances.List(gce.projectID, zone)

		// No filter: We assume that a zone is either used or unused
		// We could only consider running nodes (like we do in List above),
		// but probably if instances are starting we still want to consider them.
		// I think we should wait until we have a reason to make the
		// call one way or the other; we generally can't guarantee correct
		// volume spreading if the set of zones is changing
		// (and volume spreading is currently only a heuristic).
		// Long term we want to replace GetAllZones (which primarily supports volume
		// spreading) with a scheduler policy that is able to see the global state of
		// volumes and the health of zones.

		// Just a minimal set of fields - we only care about existence
		listCall = listCall.Fields("items(name)")

		res, err := listCall.Do()
		if err != nil {
			return nil, err
		}
		if len(res.Items) != 0 {
			zones.Insert(zone)
		}
	}

	return zones, nil
}
915581
func (c *Client) RegionList(lr *ListRange) ([]Region, error) {
	req, err := c.NewRequest("GET", "/regions", nil, nil)
	if err != nil {
		return nil, err
	}

	if lr != nil {
		lr.SetHeader(req)
	}

	var regionsRes []Region
	return regionsRes, c.DoReq(req, &regionsRes)
}
1238918
func (p *propZone) GetRegionNameServers() []string {
	if p.Zone == nil {
		return []string{}
	}

	return p.Zone.GetRegionNameServers()
}
1054341
func GetRegion(profile string) (string, error) {
	home, err := homedir.Dir()
	if err != nil {
		return "", err
	}

	path := filepath.Join(home, ".aws", "config")
	cfg, err := goconfig.LoadConfigFile(path)
	if err != nil {
		return "", err
	}

	sectionName := "default"
	if profile != "" && profile != "default" {
		sectionName = fmt.Sprintf("profile %s", profile)
	}

	section, err := cfg.GetSection(sectionName)
	if err != nil {
		return "", fmt.Errorf("Could not find AWS region in %s", path)
	}

	return section["region"], nil
}
633336
func (ud *UltraDns) GetAllZones() ([]Zone, error) {
	var Res struct {
		QInfo QueryInfo  `json:"queryInfo"`
		RInfo ResultInfo `json:"resultInfo"`
		Zones []Zone     `json:"zones"`
	}

	_, body, err := ud.Client.Get(UltraHost+"/v1/zones").
		Set("Authorization", ud.tokenHeader).End()
	if err != nil {
		return Res.Zones, errors.New("Authentication Failed")
	}

	errr := json.Unmarshal([]byte(body), &Res)
	if errr != nil {
		return Res.Zones, errors.New("Unmarshal Error")
	}

	return Res.Zones, nil
}
918516
func queryRegion(cloud string, regions []jujucloud.Region, scanner *bufio.Scanner, w io.Writer) (string, error) {
	fmt.Fprintf(w, "Regions in %s:\n", cloud)
	names := jujucloud.RegionNames(regions)
	// add an empty string to allow for a default value. Also gives us an extra
	// line return after the list of names.
	names = append(names, "")
	if _, err := fmt.Fprintln(w, strings.Join(names, "\n")); err != nil {
		return "", errors.Trace(err)
	}
	verify := interact.MatchOptions(names, "Invalid region.")
	defaultRegion := regions[0].Name
	query := fmt.Sprintf("Select a region in %s [%s]: ", cloud, defaultRegion)
	region, err := interact.QueryVerify(query, scanner, w, w, verify)
	if err != nil {
		return "", errors.Trace(err)
	}
	if region == "" {
		return defaultRegion, nil
	}
	regionName, ok := interact.FindMatch(region, names)
	if !ok {
		// should be impossible
		return "", errors.Errorf("invalid region name chosen: %s", region)
	}

	return regionName, nil
}
1154885
func getRegionInURL(urlStr string) string {
	fields := strings.Split(urlStr, "/")
	for i, v := range fields {
		if v == "regions" && i < len(fields)-1 {
			return fields[i+1]
		}
	}
	return ""
}
1235537
func (s *Server) Regions() []string {
	s.peerLock.RLock()
	defer s.peerLock.RUnlock()

	regions := make([]string, 0, len(s.peers))
	for region := range s.peers {
		regions = append(regions, region)
	}
	sort.Strings(regions)
	return regions
}