// Config returns the environment configuration for the environment // with the given name. If the configuration is not // found, an errors.NotFoundError is returned. func (envs *Environs) Config(name string) (*config.Config, error) { if name == "" { name = envs.Default if name == "" { return nil, errors.New("no default model found") } } attrs, ok := envs.rawEnvirons[name] if !ok { return nil, errors.NotFoundf("model %q", name) } if err := validateEnvironmentKind(attrs); err != nil { return nil, errors.Trace(err) } // Check that we don't have any disallowed fields in new configs used for bootstrap. for _, attr := range disallowedWithBootstrap { if _, ok := attrs[attr]; ok { return nil, fmt.Errorf("attribute %q is not allowed in bootstrap configurations", attr) } } // If deprecated config attributes are used, log warnings so the user can know // that they need to be fixed. // We also look up what any new values might be so we can tell the user. newAttrs := config.ProcessDeprecatedAttributes(attrs) envs.logDeprecatedWarnings(attrs, newAttrs, config.ToolsMetadataURLKey, config.AgentMetadataURLKey) // null has been renamed to manual (with an alias for existing config). if oldType, _ := attrs["type"].(string); oldType == "null" { logger.Warningf( "Provider type \"null\" has been renamed to \"manual\".\n" + "Please update your model configuration.", ) } // lxc-use-clone has been renamed to lxc-clone envs.logDeprecatedWarnings(attrs, newAttrs, config.LxcUseClone, config.LxcClone) // provisioner-safe-mode has been renamed to provisioner-harvest-mode, so log warnings to the user envs.logDeprecatedWarnings(attrs, newAttrs, config.ProvisionerSafeModeKey, config.ProvisionerHarvestModeKey) // tools-stream has been renamed to agent-stream, so log warnings to the user envs.logDeprecatedWarnings(attrs, newAttrs, config.ToolsStreamKey, config.AgentStreamKey) // Block attributes only matter if they have been used envs.logBlockDeprecationWarnings(attrs) cfg, err := config.New(config.UseDefaults, attrs) if err != nil { return nil, err } return cfg, nil }
// EnvironmentSet implements the server-side part of the // set-environment CLI command. func (c *Client) EnvironmentSet(args params.EnvironmentSet) error { if err := c.check.ChangeAllowed(); err != nil { return errors.Trace(err) } // Make sure we don't allow changing agent-version. checkAgentVersion := func(updateAttrs map[string]interface{}, removeAttrs []string, oldConfig *config.Config) error { if v, found := updateAttrs["agent-version"]; found { oldVersion, _ := oldConfig.AgentVersion() if v != oldVersion.String() { return fmt.Errorf("agent-version cannot be changed") } } return nil } // Replace any deprecated attributes with their new values. attrs := config.ProcessDeprecatedAttributes(args.Config) // TODO(waigani) 2014-3-11 #1167616 // Add a txn retry loop to ensure that the settings on disk have not // changed underneath us. return c.api.state.UpdateEnvironConfig(attrs, nil, checkAgentVersion) }
// ModelSet implements the server-side part of the // set-model-config CLI command. func (c *ModelConfigAPI) ModelSet(args params.ModelSet) error { if err := c.checkCanWrite(); err != nil { return err } if err := c.check.ChangeAllowed(); err != nil { return errors.Trace(err) } // Make sure we don't allow changing agent-version. checkAgentVersion := func(updateAttrs map[string]interface{}, removeAttrs []string, oldConfig *config.Config) error { if v, found := updateAttrs["agent-version"]; found { oldVersion, _ := oldConfig.AgentVersion() if v != oldVersion.String() { return errors.New("agent-version cannot be changed") } } return nil } // Replace any deprecated attributes with their new values. attrs := config.ProcessDeprecatedAttributes(args.Config) return c.backend.UpdateModelConfig(attrs, nil, checkAgentVersion) }