// loadZone determines the managed zone for the provided domain and
// credentials.
329077
func loadZone(ctxt context.Context, gsa *gserviceaccount.GServiceAccount, dnsService *dns.Service) (string, error) {
	// list managed zones
	res, err := dnsService.ManagedZones.List(*flagProject).Do()
	if err != nil {
		return "", err
	}

	if len(res.ManagedZones) == 0 {
		return "", fmt.Errorf("no managed zones in project %q", *flagProject)
	}

	// find the managed zone with the longest dns name matching the domain flag
	zone := res.ManagedZones[0]
	for _, z := range res.ManagedZones {
		if strings.HasSuffix(*flagDomain, zone.DnsName) && len(z.DnsName) > len(zone.DnsName) {
			zone = z
		}
	}
	if !strings.HasSuffix(*flagDomain, zone.DnsName) {
		return "", fmt.Errorf("can not find the managed zone name in project %q for domain %q", *flagProject, *flagDomain)
	}

	return zone.Name, nil
}
568541
func (e *environ) AvailabilityZones(ctx context.ProviderCallContext) ([]common.AvailabilityZone, error) {
	e.availabilityZonesMutex.Lock()
	defer e.availabilityZonesMutex.Unlock()
	if e.availabilityZones == nil {
		filter := ec2.NewFilter()
		filter.Add("region-name", e.cloud.Region)
		resp, err := ec2AvailabilityZones(e.ec2, filter)
		if err != nil {
			return nil, maybeConvertCredentialError(err, ctx)
		}
		logger.Debugf("availability zones: %+v", resp)
		e.availabilityZones = make([]common.AvailabilityZone, len(resp.Zones))
		for i, z := range resp.Zones {
			e.availabilityZones[i] = &ec2AvailabilityZone{z}
		}
	}
	return e.availabilityZones, nil
}
492574
func (vs *VSphere) Zones() (cloudprovider.Zones, bool) {
	if vs.isZoneEnabled() {
		return vs, true
	}
	klog.V(1).Info("The vSphere cloud provider does not support zones")
	return nil, false
}
264892
func (os *OpenStack) GetZone() (cloudprovider.Zone, error) {
	md, err := getMetadata()
	if err != nil {
		return cloudprovider.Zone{}, err
	}

	zone := cloudprovider.Zone{
		FailureDomain: md.AvailabilityZone,
		Region:        os.region,
	}
	glog.V(1).Infof("Current zone is %v", zone)

	return zone, nil
}
512637
func (c *Client) GetDomain(authZone string) (*Domain, error) {
	domainName := authZone[0 : len(authZone)-1]
	resource := fmt.Sprintf("%s%s", "/dns/managed/name?domainname=", domainName)

	resp, err := c.sendRequest(http.MethodGet, resource, nil)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	domain := &Domain{}
	err = json.NewDecoder(resp.Body).Decode(&domain)
	if err != nil {
		return nil, err
	}

	return domain, nil
}
5323
func (h *DeployHandler) randomZone(region string) string {
	h.zonesMu.RLock()
	defer h.zonesMu.RUnlock()
	zones, ok := h.zones[region]
	if !ok {
		return fallbackZone
	}
	return region + zones[rand.Intn(len(zones))]
}
552979
func (d *DNSProvider) getZone(domain string) (*response, error) {
	if d.config.AuthSid == "" {
		return nil, fmt.Errorf("must be logged in to get zone")
	}

	return d.postRequest("dns-zone-get", url.Values{"domain": {dns01.UnFqdn(domain)}})
}
444168
func NewZone(name, file string) *Zone {
	z := &Zone{
		origin:         dns.Fqdn(name),
		origLen:        dns.CountLabel(dns.Fqdn(name)),
		file:           filepath.Clean(file),
		Tree:           &tree.Tree{},
		Expired:        new(bool),
		reloadShutdown: make(chan bool),
		LastReloaded:   time.Now(),
	}
	*z.Expired = false

	return z
}
1057257
func (az *Cloud) GetZoneByProviderID(ctx context.Context, providerID string) (cloudprovider.Zone, error) {
	// Returns nil for unmanaged nodes because azure cloud provider couldn't fetch information for them.
	if az.IsNodeUnmanagedByProviderID(providerID) {
		klog.V(2).Infof("GetZoneByProviderID: omitting unmanaged node %q", providerID)
		return cloudprovider.Zone{}, nil
	}

	nodeName, err := az.vmSet.GetNodeNameByProviderID(providerID)
	if err != nil {
		return cloudprovider.Zone{}, err
	}

	return az.GetZoneByNodeName(ctx, nodeName)
}
360166
func (c *Client) GetZone(authFQDN string) (*Zone, error) {
	authZone, err := dns01.FindZoneByFqdn(authFQDN)
	if err != nil {
		return nil, err
	}

	authZoneName := dns01.UnFqdn(authZone)

	reqURL := *c.BaseURL
	reqURL.Path += "get-zone-info.json"

	q := reqURL.Query()
	q.Add("domain-name", authZoneName)
	reqURL.RawQuery = q.Encode()

	result, err := c.doRequest(http.MethodGet, &reqURL)
	if err != nil {
		return nil, err
	}

	var zone Zone

	if len(result) > 0 {
		if err = json.Unmarshal(result, &zone); err != nil {
			return nil, fmt.Errorf("zone unmarshaling error: %v", err)
		}
	}

	if zone.Name == authZoneName {
		return &zone, nil
	}

	return nil, fmt.Errorf("zone %s not found for authFQDN %s", authZoneName, authFQDN)
}
472374
func (api *API) EditZone(zoneID string, zoneOpts ZoneOptions) (Zone, error) {
	res, err := api.makeRequest("PATCH", "/zones/"+zoneID, zoneOpts)
	if err != nil {
		return Zone{}, errors.Wrap(err, errMakeRequestError)
	}
	var r ZoneResponse
	err = json.Unmarshal(res, &r)
	if err != nil {
		return Zone{}, errors.Wrap(err, errUnmarshalError)
	}

	return r.Result, nil
}
115043
func ConfigureAvailabilityZone(managerConfig container.ManagerConfig, machineZone AvailabilityZoner) (container.ManagerConfig, error) {
	availabilityZone, err := machineZone.AvailabilityZone()
	if err != nil {
		return nil, errors.Trace(err)
	}
	managerConfig[container.ConfigAvailabilityZone] = availabilityZone

	return managerConfig, nil
}
1227847
func ValidateAvailabilityZone(env ZonedEnviron, ctx context.ProviderCallContext, zone string) error {
	zones, err := env.AvailabilityZones(ctx)
	if err != nil {
		return err
	}
	for _, z := range zones {
		if z.Name() == zone {
			if z.Available() {
				return nil
			}
			return errors.Errorf("availability zone %q is unavailable", zone)
		}
	}
	return errors.NotValidf("availability zone %q", zone)
}
794720
func (m *metadata) GetZone(ctx context.Context) (cloudprovider.Zone, error) {
	zone := cloudprovider.Zone{}

	if m.zone == "" {
		zoneName, err := m.get(metadataTypeZone)
		if err != nil {
			return zone, fmt.Errorf("could not get zone: %v", err)
		}

		m.zone = zoneName
	}

	klog.V(2).Infof("Current zone is %v", zone)
	zone.FailureDomain = m.zone
	zone.Region = m.zone

	return zone, nil
}
362139
func Zone() (string, error) {
	zone, err := getTrimmed("instance/zone")
	// zone is of the form "projects/<projNum>/zones/<zoneName>".
	if err != nil {
		return "", err
	}
	return zone[strings.LastIndex(zone, "/")+1:], nil
}
172643
func (s *BaseConfigurationItem) SetAvailabilityZone(v string) *BaseConfigurationItem {
	s.AvailabilityZone = &v
	return s
}
1122827
func (g *Cloud) GetZone(ctx context.Context) (cloudprovider.Zone, error) {
	return cloudprovider.Zone{
		FailureDomain: g.localZone,
		Region:        g.region,
	}, nil
}