// DefaultCloud returns the tag of the cloud that models will be
// created in by default.
435692
func (api *CloudAPIV4) DefaultCloud() (params.StringResult, error) {
	controllerModel, err := api.ctlrBackend.Model()
	if err != nil {
		return params.StringResult{}, err
	}
	return params.StringResult{
		Result: names.NewCloudTag(controllerModel.Cloud()).String(),
	}, nil
}
78334
func DefaultVentConfig() *VentConfig {
	return &VentConfig{
		DBAdapter:     types.PostgresDB,
		DBURL:         DefaultPostgresDBURL,
		DBSchema:      "vent",
		GRPCAddr:      "localhost:10997",
		HTTPAddr:      "0.0.0.0:8080",
		LogLevel:      "debug",
		DBBlockTx:     false,
		AnnounceEvery: time.Second * 5,
	}
}
859040
func (st *State) UpdateCloud(c cloud.Cloud) error {
	if err := validateCloud(c); err != nil {
		return errors.Trace(err)
	}

	if err := st.db().RunTransaction([]txn.Op{updateCloudOps(c)}); err != nil {
		if err == txn.ErrAborted {
			err = errors.NotFoundf("cloud %q", c.Name)
		}
		return errors.Trace(err)
	}
	return st.updateConfigDefaults(c.Name, c.Config, c.RegionConfig)
}
1219082
func (c *defaultsCommand) getDefaults(client defaultsCommandAPI, ctx *cmd.Context) error {
	cloudName := c.cloudName
	if client.BestAPIVersion() < 6 {
		cloudName = ""
	}
	attrs, err := client.ModelDefaults(cloudName)
	if err != nil {
		return err
	}

	valueForRegion := func(region string, regions []config.RegionDefaultValue) (config.RegionDefaultValue, bool) {
		for _, r := range regions {
			if r.Name == region {
				return r, true
			}
		}
		return config.RegionDefaultValue{}, false
	}

	// Filter by region if necessary.
	if c.regionName != "" {
		for attrName, attr := range attrs {
			if regionDefault, ok := valueForRegion(c.regionName, attr.Regions); !ok {
				delete(attrs, attrName)
			} else {
				attrForRegion := attr
				attrForRegion.Regions = []config.RegionDefaultValue{regionDefault}
				attrs[attrName] = attrForRegion
			}
		}
	}

	if c.key != "" {
		if value, ok := attrs[c.key]; ok {
			attrs = config.ModelDefaultAttributes{
				c.key: value,
			}
		} else {
			msg := fmt.Sprintf("there are no default model values for %q", c.key)
			if c.regionName != "" {
				msg += fmt.Sprintf(" in region %q", c.regionName)
			}
			return errors.New(msg)
		}
	}
	if c.regionName != "" && len(attrs) == 0 {
		return errors.New(fmt.Sprintf(
			"there are no default model values in region %q", c.regionName))
	}

	// If c.keys is empty, write out the whole lot.
	return c.out.Write(ctx, attrs)
}
1271171
func (metadata *IndexMetadata) hasCloud(cloud CloudSpec) bool {
	for _, metadataCloud := range metadata.Clouds {
		if metadataCloud.equals(&cloud) {
			return true
		}
	}
	return len(metadata.Clouds) == 0
}
1060390
func CreateGCECloudWithCloud(config *CloudConfig, c cloud.Cloud) (*Cloud, error) {
	gceCloud, err := CreateGCECloud(config)
	if err == nil {
		gceCloud.c = c
	}
	return gceCloud, err
}
61058
func (st *State) ModelConfigDefaultValues(cloudName string) (config.ModelDefaultAttributes, error) {
	cloud, err := st.Cloud(cloudName)
	if err != nil {
		return nil, errors.Trace(err)
	}

	result := make(config.ModelDefaultAttributes)
	// Juju defaults
	defaultAttrs, err := st.defaultInheritedConfig(cloudName)()
	if err != nil {
		return nil, errors.Trace(err)
	}
	for k, v := range defaultAttrs {
		result[k] = config.AttributeDefaultValues{Default: v}
	}
	// Controller config
	ciCfg, err := st.controllerInheritedConfig(cloudName)()
	if err != nil && !errors.IsNotFound(err) {
		return nil, errors.Trace(err)

	}
	for k, v := range ciCfg {
		if ds, ok := result[k]; ok {
			ds.Controller = v
			result[k] = ds
		} else {
			result[k] = config.AttributeDefaultValues{Controller: v}
		}
	}
	// Region config
	for _, region := range cloud.Regions {
		rspec := &environs.CloudRegionSpec{Cloud: cloudName, Region: region.Name}
		riCfg, err := st.regionInheritedConfig(rspec)()
		if err != nil {
			if errors.IsNotFound(err) {
				continue
			}
			return nil, errors.Trace(err)
		}
		for k, v := range riCfg {
			regCfg := config.RegionDefaultValue{Name: region.Name, Value: v}
			if ds, ok := result[k]; ok {
				ds.Regions = append(result[k].Regions, regCfg)
				result[k] = ds
			} else {
				result[k] = config.AttributeDefaultValues{Regions: []config.RegionDefaultValue{regCfg}}
			}
		}
	}
	return result, nil
}
427464
func (c *Client) GetCloudConfig(latest bool) (Cfg, error) {
	cfg := Cfg{}

	qs := "?latest=true"
	if !latest {
		qs = "?latest=false"
	}
	r := c.NewRequest("GET", "/configs"+qs)
	resp, err := c.DoRequest(r)
	if err != nil {
		return cfg, err
	}
	defer resp.Body.Close()

	resBody, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return cfg, err
	}
	return cfg, json.Unmarshal(resBody, &cfg)
}
1005674
func DefaultConfig() *Config {
	return &Config{
		ClusterName:      store.DefaultClusterName,
		Keylen:           DefaultKeyLen,
		RotationInterval: DefaultKeyRotationInterval,
		Subsystems:       []string{SubsystemGossip, SubsystemIPSec},
	}
}
623513
func (c *Client) UpdateCloudConfig(config string) error {
	r := c.NewRequest("POST", "/configs")
	in := struct {
		Name    string `json:"name"`
		Type    string `json:"type"`
		Content string `json:"content"`
	}{
		Name:    "default",
		Type:    "cloud",
		Content: config,
	}
	b, err := json.Marshal(&in)
	if err != nil {
		return err
	}

	r.body = bytes.NewBuffer(b)
	r.header["Content-Type"] = "application/json"

	resp, err := c.DoRequest(r)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	return nil
}
531713
func (c CloudstackClient) CreateTags(options *CreateTags) (CreateTagsResponse, error) {
	var resp CreateTagsResponse
	params := url.Values{}

	params.Set("resourceids", strings.Join(options.Resourceids, ","))
	params.Set("resourcetype", options.Resourcetype)
	for j, tag := range options.Tags {
		params.Set("tags["+strconv.Itoa(j+1)+"].key", tag.Key)
		params.Set("tags["+strconv.Itoa(j+1)+"].value", tag.Value)
	}

	if options.Customer != "" {
		params.Set("customer", options.Customer)
	}

	response, err := NewRequest(c, "createTags", params)
	if err != nil {
		return resp, err
	}

	resp = response.(CreateTagsResponse)
	return resp, err
}
646634
func (kl *Kubelet) defaultNodeStatusFuncs() []func(*v1.Node) error {
	// if cloud is not nil, we expect the cloud resource sync manager to exist
	var nodeAddressesFunc func() ([]v1.NodeAddress, error)
	if kl.cloud != nil {
		nodeAddressesFunc = kl.cloudResourceSyncManager.NodeAddresses
	}
	var validateHostFunc func() error
	if kl.appArmorValidator != nil {
		validateHostFunc = kl.appArmorValidator.ValidateHost
	}
	var setters []func(n *v1.Node) error
	setters = append(setters,
		nodestatus.NodeAddress(kl.nodeIP, kl.nodeIPValidator, kl.hostname, kl.hostnameOverridden, kl.externalCloudProvider, kl.cloud, nodeAddressesFunc),
		nodestatus.MachineInfo(string(kl.nodeName), kl.maxPods, kl.podsPerCore, kl.GetCachedMachineInfo, kl.containerManager.GetCapacity,
			kl.containerManager.GetDevicePluginResourceCapacity, kl.containerManager.GetNodeAllocatableReservation, kl.recordEvent),
		nodestatus.VersionInfo(kl.cadvisor.VersionInfo, kl.containerRuntime.Type, kl.containerRuntime.Version),
		nodestatus.DaemonEndpoints(kl.daemonEndpoints),
		nodestatus.Images(kl.nodeStatusMaxImages, kl.imageManager.GetImageList),
		nodestatus.GoRuntime(),
	)
	if utilfeature.DefaultFeatureGate.Enabled(features.AttachVolumeLimit) {
		setters = append(setters, nodestatus.VolumeLimits(kl.volumePluginMgr.ListVolumePluginWithLimits))
	}
	setters = append(setters,
		nodestatus.MemoryPressureCondition(kl.clock.Now, kl.evictionManager.IsUnderMemoryPressure, kl.recordNodeStatusEvent),
		nodestatus.DiskPressureCondition(kl.clock.Now, kl.evictionManager.IsUnderDiskPressure, kl.recordNodeStatusEvent),
		nodestatus.PIDPressureCondition(kl.clock.Now, kl.evictionManager.IsUnderPIDPressure, kl.recordNodeStatusEvent),
		nodestatus.ReadyCondition(kl.clock.Now, kl.runtimeState.runtimeErrors, kl.runtimeState.networkErrors, kl.runtimeState.storageErrors, validateHostFunc, kl.containerManager.Status, kl.recordNodeStatusEvent),
		nodestatus.VolumesInUse(kl.volumeManager.ReconcilerStatesHasBeenSynced, kl.volumeManager.GetVolumesInUse),
		nodestatus.RemoveOutOfDiskCondition(),
		// TODO(mtaufen): I decided not to move this setter for now, since all it does is send an event
		// and record state back to the Kubelet runtime object. In the future, I'd like to isolate
		// these side-effects by decoupling the decisions to send events and partial status recording
		// from the Node setters.
		kl.recordNodeSchedulableEvent,
	)
	return setters
}
1262488
func validateCloud(cloud cloud.Cloud) error {
	if cloud.Name == "" {
		return errors.NotValidf("empty Name")
	}
	if cloud.Type == "" {
		return errors.NotValidf("empty Type")
	}
	if len(cloud.AuthTypes) == 0 {
		return errors.NotValidf("empty auth-types")
	}
	// TODO(axw) we should ensure that the cloud auth-types is a subset
	// of the auth-types supported by the provider. To do that, we'll
	// need a new "policy".
	return nil
}
954381
func Default() gin.HandlerFunc {
	config := DefaultConfig()
	config.AllowAllOrigins = true
	return New(config)
}
493918
func (Pipe) Default(ctx *context.Context) error {
	for i := range ctx.Config.Dockers {
		var docker = &ctx.Config.Dockers[i]

		if docker.Image != "" {
			deprecate.Notice("docker.image")
			deprecate.Notice("docker.tag_templates")

			if len(docker.TagTemplates) == 0 {
				docker.TagTemplates = []string{"{{ .Version }}"}
			}

			for _, tag := range docker.TagTemplates {
				docker.ImageTemplates = append(
					docker.ImageTemplates,
					fmt.Sprintf("%s:%s", docker.Image, tag),
				)
			}
		}

		if docker.Binary != "" {
			deprecate.Notice("docker.binary")
			docker.Binaries = append(docker.Binaries, docker.Binary)
		}

		if docker.Goos == "" {
			docker.Goos = "linux"
		}
		if docker.Goarch == "" {
			docker.Goarch = "amd64"
		}
	}
	// only set defaults if there is exactly 1 docker setup in the config file.
	if len(ctx.Config.Dockers) != 1 {
		return nil
	}
	if len(ctx.Config.Dockers[0].Binaries) == 0 {
		ctx.Config.Dockers[0].Binaries = []string{
			ctx.Config.Builds[0].Binary,
		}
	}
	if ctx.Config.Dockers[0].Dockerfile == "" {
		ctx.Config.Dockers[0].Dockerfile = "Dockerfile"
	}
	return nil
}
154124
func (Pipe) Default(ctx *context.Context) error {
	for i := range ctx.Config.S3 {
		s3 := &ctx.Config.S3[i]
		if s3.Bucket == "" {
			continue
		}
		if s3.Folder == "" {
			s3.Folder = "{{ .ProjectName }}/{{ .Tag }}"
		}
		if s3.Region == "" {
			s3.Region = "us-east-1"
		}
		if s3.ACL == "" {
			s3.ACL = "private"
		}
	}
	return nil
}
165626
func (m *Model) SetCloudCredential(tag names.CloudCredentialTag) (bool, error) {
	cloud, err := m.st.Cloud(m.Cloud())
	if err != nil {
		return false, errors.Annotatef(err, "getting cloud %q", m.Cloud())
	}
	updating := true
	buildTxn := func(attempt int) ([]txn.Op, error) {
		if attempt > 0 {
			if err := m.Refresh(); err != nil {
				return nil, errors.Trace(err)
			}
		}
		if tag.Id() == m.doc.CloudCredential {
			updating = false
			return nil, jujutxn.ErrNoOperations
		}
		// Must be a valid credential that is already on the controller.
		credential, err := m.st.CloudCredential(tag)
		if err != nil {
			return nil, errors.Trace(err)
		}
		if !credential.IsValid() {
			return nil, errors.NotValidf("credential %q", tag.Id())
		}
		if err := validateCredentialForCloud(cloud, tag, credential); err != nil {
			return nil, errors.Trace(err)
		}
		return []txn.Op{{
			C:      modelsC,
			Id:     m.doc.UUID,
			Assert: txn.DocExists,
			Update: bson.D{{"$set", bson.D{{"cloud-credential", tag.Id()}}}},
		}}, nil
	}
	if err := m.st.db().Run(buildTxn); err != nil {
		return false, errors.Trace(err)
	}
	return updating, m.Refresh()
}