本文整理汇总了Golang中launchpad/net/juju-core/environs/config.Config类的典型用法代码示例。如果您正苦于以下问题:Golang Config类的具体用法?Golang Config怎么用?Golang Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Config类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Open
func (p *environProvider) Open(cfg *config.Config) (environs.Environ, error) {
p.mu.Lock()
defer p.mu.Unlock()
name := cfg.Name()
ecfg, err := p.newConfig(cfg)
if err != nil {
return nil, err
}
state := p.state[name]
if state == nil {
if ecfg.stateServer() && len(p.state) != 0 {
var old string
for oldName := range p.state {
old = oldName
break
}
panic(fmt.Errorf("cannot share a state between two dummy environs; old %q; new %q", old, name))
}
state = newState(name, p.ops, ecfg.FirewallMode())
p.state[name] = state
}
env := &environ{
state: state,
ecfgUnlocked: ecfg,
}
if err := env.checkBroken("Open"); err != nil {
return nil, err
}
return env, nil
}
示例2: bootstrapAddressAndStorage
// bootstrapAddressAndStorage finishes up the setup of the environment in
// situations where there is no machine agent running yet.
func (env *localEnviron) bootstrapAddressAndStorage(cfg *config.Config) error {
// If we get to here, it is because we haven't yet bootstrapped an
// environment, and saved the config in it, or we are running a command
// from the command line, so it is ok to work on the assumption that we
// have direct access to the directories.
if err := env.config.createDirs(); err != nil {
return err
}
bridgeAddress, err := env.findBridgeAddress()
if err != nil {
return err
}
logger.Debugf("found %q as address for %q", bridgeAddress, lxcBridgeName)
cfg, err = cfg.Apply(map[string]interface{}{
"bootstrap-ip": bridgeAddress,
})
if err != nil {
logger.Errorf("failed to apply new addresses to config: %v", err)
return err
}
config, err := provider.newConfig(cfg)
if err != nil {
logger.Errorf("failed to create new environ config: %v", err)
return err
}
env.config = config
return env.setupLocalStorage()
}
示例3: Validate
// Validate ensures that config is a valid configuration for this
// provider like specified in the EnvironProvider interface.
func (prov azureEnvironProvider) Validate(cfg, oldCfg *config.Config) (*config.Config, error) {
// Validate base configuration change before validating Azure specifics.
err := config.Validate(cfg, oldCfg)
if err != nil {
return nil, err
}
validated, err := cfg.ValidateUnknownAttrs(configFields, configDefaults)
if err != nil {
return nil, err
}
envCfg := new(azureEnvironConfig)
envCfg.Config = cfg
envCfg.attrs = validated
cert := envCfg.managementCertificate()
if cert == "" {
certPath := envCfg.attrs["management-certificate-path"].(string)
pemData, err := ioutil.ReadFile(certPath)
if err != nil {
return nil, fmt.Errorf("invalid management-certificate-path: %s", err)
}
envCfg.attrs["management-certificate"] = string(pemData)
}
delete(envCfg.attrs, "management-certificate-path")
if envCfg.location() == "" {
return nil, fmt.Errorf("environment has no location; you need to set one. E.g. 'West US'")
}
if (envCfg.publicStorageAccountName() == "") != (envCfg.publicStorageContainerName() == "") {
return nil, fmt.Errorf("public-storage-account-name and public-storage-container-name must be specified both or none of them")
}
return cfg.Apply(envCfg.attrs)
}
示例4: initVersions
// initVersions collects state relevant to an upgrade decision. The returned
// agent and client versions, and the list of currently available tools, will
// always be accurate; the chosen version, and the flag indicating development
// mode, may remain blank until uploadTools or validate is called.
func (c *UpgradeJujuCommand) initVersions(cfg *config.Config, env environs.Environ) (*upgradeVersions, error) {
agent, ok := cfg.AgentVersion()
if !ok {
// Can't happen. In theory.
return nil, fmt.Errorf("incomplete environment configuration")
}
if c.Version == agent {
return nil, errUpToDate
}
client := version.Current.Number
available, err := environs.FindAvailableTools(env, client.Major)
if err != nil {
if !errors.IsNotFoundError(err) {
return nil, err
}
if !c.UploadTools {
if c.Version == version.Zero {
return nil, errUpToDate
}
return nil, err
}
}
dev := c.Development || cfg.Development() || agent.IsDev() || client.IsDev()
return &upgradeVersions{
dev: dev,
agent: agent,
client: client,
chosen: c.Version,
tools: available,
}, nil
}
示例5: Validate
func (prov maasEnvironProvider) Validate(cfg, oldCfg *config.Config) (*config.Config, error) {
// Validate base configuration change before validating MAAS specifics.
err := config.Validate(cfg, oldCfg)
if err != nil {
return nil, err
}
validated, err := cfg.ValidateUnknownAttrs(configFields, configDefaults)
if err != nil {
return nil, err
}
envCfg := new(maasEnvironConfig)
envCfg.Config = cfg
envCfg.attrs = validated
server := envCfg.MAASServer()
serverURL, err := url.Parse(server)
if err != nil || serverURL.Scheme == "" || serverURL.Host == "" {
return nil, fmt.Errorf("malformed maas-server URL '%v': %s", server, err)
}
oauth := envCfg.MAASOAuth()
if strings.Count(oauth, ":") != 2 {
return nil, errMalformedMaasOAuth
}
return cfg.Apply(envCfg.attrs)
}
示例6: Open
func (maasEnvironProvider) Open(cfg *config.Config) (environs.Environ, error) {
logger.Debugf("opening environment %q.", cfg.Name())
env, err := NewEnviron(cfg)
if err != nil {
return nil, err
}
return env, nil
}
示例7: base64yaml
func base64yaml(m *config.Config) string {
data, err := goyaml.Marshal(m.AllAttrs())
if err != nil {
// can't happen, these values have been validated a number of times
panic(err)
}
return base64.StdEncoding.EncodeToString(data)
}
示例8: checkEnvironConfig
// checkEnvironConfig returns an error if the config is definitely invalid.
func checkEnvironConfig(cfg *config.Config) error {
if cfg.AdminSecret() != "" {
return fmt.Errorf("admin-secret should never be written to the state")
}
if _, ok := cfg.AgentVersion(); !ok {
return fmt.Errorf("agent-version must always be set in state")
}
return nil
}
示例9: getUploadSeries
// getUploadSeries returns the supplied series with duplicates removed if
// non-empty; otherwise it returns a default list of series we should
// probably upload, based on cfg.
func getUploadSeries(cfg *config.Config, series []string) []string {
unique := set.NewStrings(series...)
if unique.IsEmpty() {
unique.Add(version.Current.Series)
unique.Add(config.DefaultSeries)
unique.Add(cfg.DefaultSeries())
}
return unique.Values()
}
示例10: Open
func (p environProvider) Open(cfg *config.Config) (environs.Environ, error) {
log.Printf("environs/openstack: opening environment %q", cfg.Name())
e := new(environ)
err := e.SetConfig(cfg)
if err != nil {
return nil, err
}
return e, nil
}
示例11: NewEnviron
func NewEnviron(cfg *config.Config) (*maasEnviron, error) {
env := new(maasEnviron)
err := env.SetConfig(cfg)
if err != nil {
return nil, err
}
env.name = cfg.Name()
env.storageUnlocked = NewStorage(env)
return env, nil
}
示例12: Open
func (p environProvider) Open(cfg *config.Config) (environs.Environ, error) {
log.Infof("environs/ec2: opening environment %q", cfg.Name())
e := new(environ)
err := e.SetConfig(cfg)
if err != nil {
return nil, err
}
e.name = cfg.Name()
return e, nil
}
示例13: Open
// Open is specified in the EnvironProvider interface.
func (prov azureEnvironProvider) Open(cfg *config.Config) (environs.Environ, error) {
logger.Debugf("opening environment %q.", cfg.Name())
// We can't return NewEnviron(cfg) directly here because otherwise,
// when err is not nil, we end up with a non-nil returned environ and
// this breaks the loop in cmd/jujud/upgrade.go:run() (see
// http://golang.org/doc/faq#nil_error for the gory details).
environ, err := NewEnviron(cfg)
if err != nil {
return nil, err
}
return environ, nil
}
示例14: Validate
func (p *environProvider) Validate(cfg, old *config.Config) (valid *config.Config, err error) {
// Check for valid changes for the base config values.
if err := config.Validate(cfg, old); err != nil {
return nil, err
}
validated, err := cfg.ValidateUnknownAttrs(configFields, configDefaults)
if err != nil {
return nil, err
}
// Apply the coerced unknown values back into the config.
return cfg.Apply(validated)
}
示例15: getStateInfo
// composeStateInfo puts together the state.Info and api.Info for the given
// config, with the given state-server host names.
// The given config absolutely must have a CACert.
func getStateInfo(config *config.Config, hostnames []string) (*state.Info, *api.Info) {
cert, hasCert := config.CACert()
if !hasCert {
panic(errors.New("getStateInfo: config has no CACert"))
}
return &state.Info{
Addrs: composeAddresses(hostnames, config.StatePort()),
CACert: cert,
}, &api.Info{
Addrs: composeAddresses(hostnames, config.APIPort()),
CACert: cert,
}
}