// DetectRegions implements environs.CloudRegionDetector.
495473
func (*environProvider) DetectRegions() ([]cloud.Region, error) {
	// For now we just return a hard-coded "localhost" region,
	// i.e. the local LXD daemon. We may later want to detect
	// locally-configured remotes.
	return []cloud.Region{{Name: lxdnames.DefaultLocalRegion}}, nil
}
747184
func isValidRegionCode(regionCode string) bool {
	_, contains := readFromSupportedRegions(regionCode)
	return len(regionCode) != 0 && contains
}
1247178
func (c *Client) RegionInfo(regionIdentity string) (*Region, error) {
	var region Region
	return &region, c.Get(&region, "/regions/"+regionIdentity)
}
409610
func (environProviderCredentials) DetectCredentials() (*cloud.CloudCredential, error) {
	clientConfigFunc, err := clientconfig.NewClientConfigReader(CAASProviderType)
	if err != nil {
		return nil, errors.Trace(err)
	}
	caasConfig, err := clientConfigFunc(nil, "", "", nil)
	if err != nil {
		return nil, errors.Trace(err)
	}

	if len(caasConfig.Contexts) == 0 {
		return nil, errors.NotFoundf("k8s cluster definitions")
	}

	defaultContext := caasConfig.Contexts[caasConfig.CurrentContext]
	result := &cloud.CloudCredential{
		AuthCredentials:   caasConfig.Credentials,
		DefaultCredential: defaultContext.CredentialName,
	}
	return result, nil
}
806581
func (p environProviderCredentials) detectLocalCredentials(certPEM, keyPEM []byte) (*cloud.Credential, error) {
	svr, err := p.serverFactory.LocalServer()
	if err != nil {
		return nil, errors.NewNotFound(err, "failed to connect to local LXD")
	}

	label := fmt.Sprintf("LXD credential %q", lxdnames.DefaultCloud)
	certCredential, err := p.finalizeLocalCredential(
		ioutil.Discard, svr, string(certPEM), string(keyPEM), label,
	)
	return certCredential, errors.Trace(err)
}
821477
func IsErrNoRegionPath(err error) bool {
	return err != nil && strings.Contains(err.Error(), errNoRegionPath)
}
696910
func (s *RegionService) AddRegion(p *AddRegionParams) (*AddRegionResponse, error) {
	resp, err := s.cs.newRequest("addRegion", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r AddRegionResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	return &r, nil
}
16328
func (c *Client) GetRegions() (*RegionsResponse, error) {
	r, err := c.Get("stats/regions", nil)
	if err != nil {
		return nil, err
	}

	var rr *RegionsResponse
	if err := decodeJSON(&rr, r.Body); err != nil {
		return nil, err
	}

	return rr, nil
}
1301881
func BuiltInClouds() (map[string]jujucloud.Cloud, error) {
	allClouds := make(map[string]jujucloud.Cloud)
	for _, providerType := range environs.RegisteredProviders() {
		p, err := environs.Provider(providerType)
		if err != nil {
			return nil, errors.Trace(err)
		}
		detector, ok := p.(environs.CloudDetector)
		if !ok {
			continue
		}
		clouds, err := detector.DetectClouds()
		if err != nil {
			return nil, errors.Annotatef(
				err, "detecting clouds for provider %q",
				providerType,
			)
		}
		for _, cloud := range clouds {
			allClouds[cloud.Name] = cloud
		}
	}
	return allClouds, nil
}
527773
func (e *CloudWatchExecutor) handleGetRegions(ctx context.Context, parameters *simplejson.Json, queryContext *tsdb.TsdbQuery) ([]suggestData, error) {
	dsInfo := e.getDsInfo("default")
	profile := dsInfo.Profile
	if cache, ok := regionCache.Load(profile); ok {
		if cache2, ok2 := cache.([]suggestData); ok2 {
			return cache2, nil
		}
	}

	regions := []string{
		"ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1",
		"eu-central-1", "eu-north-1", "eu-west-1", "eu-west-2", "eu-west-3", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-west-1", "us-west-2",
		"cn-north-1", "cn-northwest-1", "us-gov-east-1", "us-gov-west-1", "us-isob-east-1", "us-iso-east-1",
	}
	err := e.ensureClientSession("default")
	if err != nil {
		return nil, err
	}
	r, err := e.ec2Svc.DescribeRegions(&ec2.DescribeRegionsInput{})
	if err != nil {
		// ignore error for backward compatibility
		plog.Error("Failed to get regions", "error", err)
	} else {
		for _, region := range r.Regions {
			exists := false

			for _, existingRegion := range regions {
				if existingRegion == *region.RegionName {
					exists = true
					break
				}
			}

			if !exists {
				regions = append(regions, *region.RegionName)
			}
		}
	}
	sort.Strings(regions)

	result := make([]suggestData, 0)
	for _, region := range regions {
		result = append(result, suggestData{Text: region, Value: region})
	}
	regionCache.Store(profile, result)

	return result, nil
}
1139391
func (s *AccountAggregationSource) SetAllAwsRegions(v bool) *AccountAggregationSource {
	s.AllAwsRegions = &v
	return s
}
18702
func (p kubernetesEnvironProvider) DetectClouds() ([]cloud.Cloud, error) {
	clouds := []cloud.Cloud{}
	mk8sCloud, _, _, err := p.builtinCloudGetter(p.cmdRunner)
	if err == nil {
		clouds = append(clouds, mk8sCloud)
		return clouds, nil
	}
	if errors.IsNotFound(err) {
		err = errors.Annotatef(err, "microk8s is not installed")
	}
	logger.Debugf("failed to query local microk8s: %s", err.Error())
	return clouds, nil
}
188128
func GetRegion(d *schema.ResourceData, config *Config) string {
	if v, ok := d.GetOk("region"); ok {
		return v.(string)
	}

	return config.Region
}
760253
func (c OpenstackCredentials) DetectCredentials() (*cloud.CloudCredential, error) {
	result := cloud.CloudCredential{
		AuthCredentials: make(map[string]cloud.Credential),
	}

	// Try just using environment variables
	creds, user, region, err := c.detectCredential()
	if err == nil {
		result.DefaultRegion = region
		result.AuthCredentials[user] = *creds
	}

	// Now look for .novarc file in home dir.
	novarc := filepath.Join(utils.Home(), ".novarc")
	novaInfo, err := ini.LooseLoad(novarc)
	if err != nil {
		return nil, errors.Annotate(err, "loading novarc file")
	}
	stripExport := regexp.MustCompile(`(?i)^\s*export\s*`)
	keyValues := novaInfo.Section(ini.DEFAULT_SECTION).KeysHash()
	if len(keyValues) > 0 {
		for k, v := range keyValues {
			k = stripExport.ReplaceAllString(k, "")
			os.Setenv(k, v)
		}
		creds, user, region, err := c.detectCredential()
		if err == nil {
			result.DefaultRegion = region
			result.AuthCredentials[user] = *creds
		}
	}
	if len(result.AuthCredentials) == 0 {
		return nil, errors.NotFoundf("openstack credentials")
	}
	return &result, 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
}
284940
func (c *defaultsCommand) parseCloudRegion(args []string) ([]string, error) {
	var cloud, maybeRegion string
	cr := args[0]
	// Must have no more than one slash and it must not be at the beginning or end.
	if strings.Count(cr, "/") == 1 && !strings.HasPrefix(cr, "/") && !strings.HasSuffix(cr, "/") {
		elems := strings.Split(cr, "/")
		cloud, maybeRegion = elems[0], elems[1]
	} else {
		// The arg may be either a cloud name or region or yaml file.
		// We will see below if the value corresponds to a
		// cloud on the controller, in which case it is interpretted
		// as a cloud, else it is considered a region.
		maybeRegion = cr
	}

	// Ensure we exit early when we have a settings file or key=value.
	info, err := os.Stat(maybeRegion)
	isFile := err == nil && !info.IsDir()
	// TODO(redir) 2016-10-05 #1627162
	// We don't disallow "=" in region names, but probably should.
	if isFile || strings.Contains(maybeRegion, "=") {
		return args, nil
	}

	valid, err := c.validCloudRegion(cloud, maybeRegion)
	if err != nil {
		return nil, errors.Trace(err)
	}
	if !valid {
		return args, nil
	}
	return args[1:], nil
}
1230045
func (st *State) regionSpec() (*environs.CloudRegionSpec, error) {
	model, err := st.Model()
	if err != nil {
		return nil, errors.Trace(err)
	}
	rspec := &environs.CloudRegionSpec{
		Cloud:  model.Cloud(),
		Region: model.CloudRegion(),
	}
	return rspec, nil
}