// validCloudRegion checks that region is a valid region in cloud, or cloud
// for the current model if cloud is not specified.
501240
func (c *defaultsCommand) validCloudRegion(cloudName, maybeRegion string) (bool, error) {
	root, err := c.newAPIRoot()
	if err != nil {
		return false, errors.Trace(err)
	}
	cc := c.newCloudAPI(root)
	defer cc.Close()

	// We have a single value - it may be a cloud or a region.
	if cloudName == "" && maybeRegion != "" {
		// First try and interpret as a cloud.
		maybeCloud := maybeRegion
		if !names.IsValidCloud(maybeCloud) {
			return false, errors.NotValidf("cloud %q", maybeCloud)
		}
		// Ensure that the cloud actually exists on the controller.
		cTag := names.NewCloudTag(maybeCloud)
		_, err := cc.Cloud(cTag)
		if err != nil && !errors.IsNotFound(err) {
			return false, errors.Trace(err)
		}
		if err == nil {
			c.cloudName = maybeCloud
			return true, nil
		}
	}

	var cTag names.CloudTag
	// If a cloud is not specified, use the controller
	// cloud if that's the only one, else ask the user
	// which cloud should be used.
	if cloudName == "" {
		cTag, err = c.maybeGetDefaultControllerCloud(cc)
		if err != nil {
			return false, errors.Trace(err)
		}
	} else {
		if !names.IsValidCloud(cloudName) {
			return false, errors.Errorf("invalid cloud %q", cloudName)
		}
		cTag = names.NewCloudTag(cloudName)
	}
	cloud, err := cc.Cloud(cTag)
	if err != nil {
		return false, errors.Trace(err)
	}

	isCloudRegion := false
	for _, r := range cloud.Regions {
		if r.Name == maybeRegion {
			c.cloudName = cTag.Id()
			c.regionName = maybeRegion
			isCloudRegion = true
			break
		}
	}
	return isCloudRegion, nil
}
727546
func (r Network_Storage_MassDataMigration_CrossRegion_Country_Xref) GetValidCountriesForRegion(locationGroupName *string) (resp []datatypes.Network_Storage_MassDataMigration_CrossRegion_Country_Xref, err error) {
	params := []interface{}{
		locationGroupName,
	}
	err = r.Session.DoRequest("SoftLayer_Network_Storage_MassDataMigration_CrossRegion_Country_Xref", "getValidCountriesForRegion", params, &r.Options, &resp)
	return
}
1339717
func MarshalCloud(cloud Cloud) ([]byte, error) {
	return yaml.Marshal(cloudToInternal(cloud, true))
}
1302860
func IsValidRegion(r string) bool {
	for _, v := range ValidRegions {
		if r == string(v) {
			return true
		}
	}
	return false
}
994390
func (p *environProvider) FinalizeCloud(
	ctx environs.FinalizeCloudContext,
	in cloud.Cloud,
) (cloud.Cloud, error) {
	var endpoint string
	resolveEndpoint := func(name string, ep *string) error {
		// If the name doesn't equal "localhost" then we shouldn't resolve
		// the end point, instead we should just accept what we already have.
		if name != lxdnames.DefaultCloud || *ep != "" {
			return nil
		}
		if endpoint == "" {
			// The cloud endpoint is empty, which means
			// that we should connect to the local LXD.
			hostAddress, err := p.getLocalHostAddress(ctx)
			if err != nil {
				return errors.Trace(err)
			}
			endpoint = hostAddress
		}
		*ep = endpoint
		return nil
	}

	// If any of the endpoints point to localhost, go through and backfill the
	// cloud spec with local host addresses.
	if err := resolveEndpoint(in.Name, &in.Endpoint); err != nil {
		return cloud.Cloud{}, errors.Trace(err)
	}
	for i, k := range in.Regions {
		if err := resolveEndpoint(k.Name, &in.Regions[i].Endpoint); err != nil {
			return cloud.Cloud{}, errors.Trace(err)
		}
	}
	// If the provider type is not named localhost and there is no region, set the
	// region to be a default region
	if in.Name != lxdnames.DefaultCloud && len(in.Regions) == 0 {
		in.Regions = append(in.Regions, cloud.Region{
			Name:     lxdnames.DefaultRemoteRegion,
			Endpoint: in.Endpoint,
		})
	}
	return in, nil
}
1045280
func ValidComponent(el ClusterComponent, components []ClusterComponent) bool {
	for _, v := range components {
		if el == v {
			return true
		}
	}
	return false
}
593796
func ValidateZones(zones []string, cloud AWSCloud) error {
	azs, err := cloud.DescribeAvailabilityZones()
	if err != nil {
		return err
	}

	zoneMap := make(map[string]*ec2.AvailabilityZone)
	for _, z := range azs {
		name := aws.StringValue(z.ZoneName)
		zoneMap[name] = z
	}

	for _, zone := range zones {
		z := zoneMap[zone]
		if z == nil {
			var knownZones []string
			for z := range zoneMap {
				knownZones = append(knownZones, z)
			}

			glog.Infof("Known zones: %q", strings.Join(knownZones, ","))
			return fmt.Errorf("Zone is not a recognized AZ: %q (check you have specified a valid zone?)", zone)
		}

		for _, message := range z.Messages {
			glog.Warningf("Zone %q has message: %q", zone, aws.StringValue(message.Message))
		}

		if aws.StringValue(z.State) != "available" {
			glog.Warningf("Zone %q has state %q", zone, aws.StringValue(z.State))
		}
	}

	return nil
}
1206667
func (e *Environ) Region() (simplestreams.CloudSpec, error) {
	return e.cloudSpec(e.cloud().Region)
}
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
}
929667
func queryCloud(clouds []string, defCloud string, scanner *bufio.Scanner, w io.Writer) (string, error) {
	list := strings.Join(clouds, "\n")
	if _, err := fmt.Fprint(w, "Clouds\n", list, "\n\n"); err != nil {
		return "", errors.Trace(err)
	}

	// add support for a default (empty) selection.
	clouds = append(clouds, "")

	verify := interact.MatchOptions(clouds, "Invalid cloud.")

	query := fmt.Sprintf("Select a cloud [%s]: ", defCloud)
	cloud, err := interact.QueryVerify(query, scanner, w, w, verify)
	if err != nil {
		return "", errors.Trace(err)
	}
	if cloud == "" {
		return defCloud, nil
	}
	if ok := names.IsValidCloud(cloud); !ok {
		return "", errors.NotValidf("cloud name %q", cloud)
	}

	cloudName, ok := interact.FindMatch(cloud, clouds)
	if !ok {
		// should be impossible
		return "", errors.Errorf("invalid cloud name chosen: %s", cloud)
	}

	return cloudName, nil
}
945776
func (r *RollingUpdateInstanceGroup) ValidateCluster(rollingUpdateData *RollingUpdateCluster, cluster *api.Cluster, instanceGroupList *api.InstanceGroupList) error {
	if _, err := validation.ValidateCluster(cluster, instanceGroupList, rollingUpdateData.K8sClient); err != nil {
		return fmt.Errorf("cluster %q did not pass validation: %v", cluster.Name, err)
	}

	return 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
}
954991
func ValidModelStatus(status Status) bool {
	switch status {
	case
		Available,
		Busy,
		Destroying,
		Error:
		return true
	default:
		return false
	}
}
858740
func (c *RegionCache) DropRegion(id RegionVerID) {
	c.mu.Lock()
	defer c.mu.Unlock()
	c.dropRegionFromCache(id)
}
1274156
func MaybeInvalidateCredential(err error, ctx context.ProviderCallContext) bool {
	if ctx == nil {
		return false
	}
	if !hasDenialStatusCode(err) {
		return false
	}

	invalidateErr := ctx.InvalidateCredential("azure cloud denied access")
	if invalidateErr != nil {
		logger.Warningf("could not invalidate stored azure cloud credential on the controller: %v", invalidateErr)
	}
	return true
}
267670
func createCloudOp(cloud cloud.Cloud) txn.Op {
	authTypes := make([]string, len(cloud.AuthTypes))
	for i, authType := range cloud.AuthTypes {
		authTypes[i] = string(authType)
	}
	regions := make(map[string]cloudRegionSubdoc)
	for _, region := range cloud.Regions {
		regions[utils.EscapeKey(region.Name)] = cloudRegionSubdoc{
			region.Endpoint,
			region.IdentityEndpoint,
			region.StorageEndpoint,
		}
	}
	return txn.Op{
		C:      cloudsC,
		Id:     cloud.Name,
		Assert: txn.DocMissing,
		Insert: &cloudDoc{
			Name:             cloud.Name,
			Type:             cloud.Type,
			AuthTypes:        authTypes,
			Endpoint:         cloud.Endpoint,
			IdentityEndpoint: cloud.IdentityEndpoint,
			StorageEndpoint:  cloud.StorageEndpoint,
			Regions:          regions,
			CACertificates:   cloud.CACertificates,
		},
	}
}
1301365
func (a *Azure) ValidConfig() bool {
	return a.SubscriptionID != "" && a.ClientID != "" && a.ClientSecret != "" && a.TenantID != ""
}