// Clouds returns the details of all clouds supported by the controller.
519105
func (c *Client) Clouds() (map[names.CloudTag]jujucloud.Cloud, error) {
	var result params.CloudsResult
	if err := c.facade.FacadeCall("Clouds", nil, &result); err != nil {
		return nil, errors.Trace(err)
	}
	clouds := make(map[names.CloudTag]jujucloud.Cloud)
	for tagString, cloud := range result.Clouds {
		tag, err := names.ParseCloudTag(tagString)
		if err != nil {
			return nil, errors.Trace(err)
		}
		clouds[tag] = common.CloudFromParams(tag.Id(), cloud)
	}
	return clouds, nil
}
375915
func (m *CAASModel) Containers(providerIds ...string) ([]CloudContainer, error) {
	coll, closer := m.st.db().GetCollection(cloudContainersC)
	defer closer()

	var all []cloudContainerDoc
	err := coll.Find(bson.D{{"provider-id", bson.D{{"$in", providerIds}}}}).All(&all)
	if err != nil {
		return nil, errors.Trace(err)
	}
	var result []CloudContainer
	for _, doc := range all {
		unitKey := m.localID(doc.Id)
		// key is "u#<unitname>#charm"
		idx := len(unitKey) - len("#charm")
		result = append(result, &cloudContainer{doc: doc, unitName: unitKey[2:idx]})
	}
	return result, nil
}
474027
func (p *environProvider) DetectClouds() ([]cloud.Cloud, error) {
	configPath := filepath.Join(utils.Home(), ".config", "lxc", "config.yml")
	config, err := p.lxcConfigReader.ReadConfig(configPath)
	if err != nil {
		logger.Errorf("unable to read/parse LXC config file: %s", err)
	}

	clouds := []cloud.Cloud{localhostCloud}
	for name, remote := range config.Remotes {
		if remote.Protocol == lxdnames.ProviderType {
			clouds = append(clouds, cloud.Cloud{
				Name:        name,
				Type:        lxdnames.ProviderType,
				Endpoint:    remote.Addr,
				Description: "LXD Cluster",
				AuthTypes: []cloud.AuthType{
					cloud.CertificateAuthType,
				},
				Regions: []cloud.Region{{
					Name:     lxdnames.DefaultRemoteRegion,
					Endpoint: remote.Addr,
				}},
			})
		}
	}

	return clouds, nil
}
930862
func (c *Client) ModelDefaults(cloud string) (config.ModelDefaultAttributes, error) {
	if c.BestAPIVersion() < 6 {
		if cloud != "" {
			return nil, errors.Errorf("model defaults for cloud %s not supported for this version of Juju", cloud)
		}
		return c.legacyModelDefaults()
	}

	results := params.ModelDefaultsResults{}
	args := params.Entities{
		Entities: []params.Entity{{Tag: names.NewCloudTag(cloud).String()}},
	}
	err := c.facade.FacadeCall("ModelDefaultsForClouds", args, &results)
	if err != nil {
		return nil, errors.Trace(err)
	}
	if len(results.Results) != 1 {
		return nil, errors.Errorf("expected one result, got %d", len(results.Results))
	}
	result := results.Results[0]
	if result.Error != nil {
		return nil, errors.Trace(result.Error)
	}
	values := make(config.ModelDefaultAttributes)
	for name, val := range result.Config {
		setting := config.AttributeDefaultValues{
			Default:    val.Default,
			Controller: val.Controller,
		}
		for _, region := range val.Regions {
			setting.Regions = append(setting.Regions, config.RegionDefaultValue{
				Name:  region.RegionName,
				Value: region.Value})
		}
		values[name] = setting
	}
	return values, nil
}
1176718
func NewCloudController(ip, username, password, deploymentName string, cloudControllers CloudControllerJobs) (*CloudController, error) {
	return &CloudController{
		deploymentName:   deploymentName,
		cloudControllers: cloudControllers,
		ip:               ip,
		username:         username,
		password:         password,
	}, nil
}
763985
func ParseCloudMetadata(data []byte) (map[string]Cloud, error) {
	var metadata cloudSet
	if err := yaml.Unmarshal(data, &metadata); err != nil {
		return nil, errors.Annotate(err, "cannot unmarshal yaml cloud metadata")
	}

	// Translate to the exported type. For each cloud, we store
	// the first region for the cloud as its default region.
	clouds := make(map[string]Cloud)
	for name, cloud := range metadata.Clouds {
		details := cloudFromInternal(cloud)
		details.Name = name
		if details.Description == "" {
			var ok bool
			if details.Description, ok = defaultCloudDescription[name]; !ok {
				details.Description = defaultCloudDescription[cloud.Type]
			}
		}
		clouds[name] = details
	}
	return clouds, nil
}
1339717
func MarshalCloud(cloud Cloud) ([]byte, error) {
	return yaml.Marshal(cloudToInternal(cloud, true))
}
441636
func (_class SDNControllerClass) GetAllRecords(sessionID SessionRef) (_retval map[SDNControllerRef]SDNControllerRecord, _err error) {
	_method := "SDN_controller.get_all_records"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg)
	if _err != nil {
		return
	}
	_retval, _err = convertSDNControllerRefToSDNControllerRecordMapToGo(_method + " -> ", _result.Value)
	return
}
315564
func (cs *CSCloud) Instances() (cloudprovider.Instances, bool) {
	if cs.metadata != nil {
		return cs.metadata, true
	}

	if cs.client == nil {
		return nil, false
	}

	return cs, true
}
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)
}
628267
func (o *CloudControllerManagerOptions) Validate(allControllers, disabledByDefaultControllers []string) error {
	errors := []error{}

	errors = append(errors, o.Generic.Validate(allControllers, disabledByDefaultControllers)...)
	errors = append(errors, o.KubeCloudShared.Validate()...)
	errors = append(errors, o.ServiceController.Validate()...)
	errors = append(errors, o.SecureServing.Validate()...)
	errors = append(errors, o.InsecureServing.Validate()...)
	errors = append(errors, o.Authentication.Validate()...)
	errors = append(errors, o.Authorization.Validate()...)

	if len(o.KubeCloudShared.CloudProvider.Name) == 0 {
		errors = append(errors, fmt.Errorf("--cloud-provider cannot be empty"))
	}

	return utilerrors.NewAggregate(errors)
}
1061847
func (o *Me) CloudMgmtSystems(info *bambou.FetchingInfo) (CloudMgmtSystemsList, *bambou.Error) {

	var list CloudMgmtSystemsList
	err := bambou.CurrentSession().FetchChildren(o, CloudMgmtSystemIdentity, &list, info)
	return list, err
}
1325334
func (c *ApiController) GetBuildsAll() {
	log.Info("Get all builds")

	builds := models.GetAllBuilds()

	c.Data["json"] = builds
	c.ServeJson()
}
1271171
func (metadata *IndexMetadata) hasCloud(cloud CloudSpec) bool {
	for _, metadataCloud := range metadata.Clouds {
		if metadataCloud.equals(&cloud) {
			return true
		}
	}
	return len(metadata.Clouds) == 0
}
391045
func (api *CloudAPI) RemoveClouds(args params.Entities) (params.ErrorResults, error) {
	result := params.ErrorResults{
		Results: make([]params.ErrorResult, len(args.Entities)),
	}
	isAdmin, err := api.authorizer.HasPermission(permission.SuperuserAccess, api.ctlrBackend.ControllerTag())
	if err != nil && !errors.IsNotFound(err) {
		return result, errors.Trace(err)
	}
	for i, entity := range args.Entities {
		tag, err := names.ParseCloudTag(entity.Tag)
		if err != nil {
			result.Results[i].Error = common.ServerError(err)
			continue
		}
		// Ensure user has permission to remove the cloud.
		if !isAdmin {
			canAccess, err := api.canAccessCloud(tag.Id(), api.apiUser, permission.AdminAccess)
			if err != nil {
				result.Results[i].Error = common.ServerError(err)
				continue
			}
			if !canAccess {
				result.Results[i].Error = common.ServerError(common.ErrPerm)
				continue
			}
		}
		err = api.backend.RemoveCloud(tag.Id())
		result.Results[i].Error = common.ServerError(err)
	}
	return result, nil
}
1023623
func (e *Empire) Apps(q AppsQuery) ([]*App, error) {
	return apps(e.db, q)
}
749447
func (c *AddCloudCommand) Run(ctxt *cmd.Context) error {
	if c.CloudFile == "" && c.controllerName == "" {
		return c.runInteractive(ctxt)
	}

	var newCloud *jujucloud.Cloud
	var err error
	if c.CloudFile != "" {
		newCloud, err = c.readCloudFromFile(ctxt)
	} else {
		// No cloud file specified so we try and use a named
		// cloud that already has been added to the local cache.
		newCloud, err = cloudFromLocal(c.Cloud)
	}
	if err != nil {
		return errors.Trace(err)
	}

	if c.controllerName == "" {
		if !c.Local {
			ctxt.Infof(
				"There are no controllers running.\nAdding cloud to local cache so you can use it to bootstrap a controller.\n")
		}
		return addLocalCloud(c.cloudMetadataStore, *newCloud)
	}

	// A controller has been specified so upload the cloud details
	// plus a corresponding credential to the controller.
	api, err := c.addCloudAPIFunc()
	if err != nil {
		return err
	}
	defer api.Close()
	err = api.AddCloud(*newCloud)
	if err != nil && params.ErrCode(err) != params.CodeAlreadyExists {
		return err
	}
	// Add a credential for the newly added cloud.
	err = c.addCredentialToController(ctxt, *newCloud, api)
	if err != nil {
		return err
	}
	ctxt.Infof("Cloud %q added to controller %q.", c.Cloud, c.controllerName)
	return nil
}