本文整理匯總了Golang中github.com/juju/juju/environs.ConfigForName函數的典型用法代碼示例。如果您正苦於以下問題:Golang ConfigForName函數的具體用法?Golang ConfigForName怎麽用?Golang ConfigForName使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ConfigForName函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Config
// Config returns the configuration for the environment; obtaining bootstrap
// information from the API if necessary. If callers already have an active
// client API connection, it will be used. Otherwise, a new API connection will
// be used if necessary.
func (c *ModelCommandBase) Config(store configstore.Storage, client ModelGetter) (*config.Config, error) {
if c.modelName == "" {
return nil, errors.Trace(ErrNoModelSpecified)
}
cfg, _, err := environs.ConfigForName(c.modelName, store)
if err == nil {
return cfg, nil
} else if !environs.IsEmptyConfig(err) {
return nil, errors.Trace(err)
}
if client == nil {
client, err = c.NewModelGetter()
if err != nil {
return nil, errors.Trace(err)
}
defer client.Close()
}
bootstrapCfg, err := client.ModelGet()
if err != nil {
return nil, errors.Trace(err)
}
return config.New(config.NoDefaults, bootstrapCfg)
}
示例2: TestConfigForNameDefault
func (*OpenSuite) TestConfigForNameDefault(c *gc.C) {
testing.WriteEnvironments(c, testing.SingleEnvConfig)
cfg, source, err := environs.ConfigForName("", configstore.NewMem())
c.Assert(err, gc.IsNil)
c.Assert(cfg.Name(), gc.Equals, "erewhemos")
c.Assert(source, gc.Equals, environs.ConfigFromEnvirons)
}
示例3: Config
func (c *EnvCommandBase) Config(store configstore.Storage) (*config.Config, error) {
if c.envName == "" {
return nil, errors.Trace(ErrNoEnvironmentSpecified)
}
cfg, _, err := environs.ConfigForName(c.envName, store)
return cfg, err
}
示例4: TestConfigForNameFromInfo
func (*OpenSuite) TestConfigForNameFromInfo(c *gc.C) {
testing.WriteEnvironments(c, testing.SingleEnvConfig)
store := configstore.NewMem()
cfg, source, err := environs.ConfigForName("", store)
c.Assert(err, gc.IsNil)
c.Assert(source, gc.Equals, environs.ConfigFromEnvirons)
info := store.CreateInfo("test-config")
var attrs testing.Attrs = cfg.AllAttrs()
attrs = attrs.Merge(testing.Attrs{
"name": "test-config",
})
info.SetBootstrapConfig(attrs)
err = info.Write()
c.Assert(err, gc.IsNil)
cfg, source, err = environs.ConfigForName("test-config", store)
c.Assert(err, gc.IsNil)
c.Assert(source, gc.Equals, environs.ConfigFromInfo)
c.Assert(testing.Attrs(cfg.AllAttrs()), gc.DeepEquals, attrs)
}
示例5: TestNewFromNameWithInvalidInfo
func (*OpenSuite) TestNewFromNameWithInvalidInfo(c *gc.C) {
store := configstore.NewMem()
cfg, _, err := environs.ConfigForName("erewhemos", store)
c.Assert(err, gc.IsNil)
info := store.CreateInfo("erewhemos")
// The configuration from environments.yaml is invalid
// because it doesn't contain the state-id attribute which
// the dummy environment adds at Prepare time.
info.SetBootstrapConfig(cfg.AllAttrs())
err = info.Write()
c.Assert(err, gc.IsNil)
e, err := environs.NewFromName("erewhemos", store)
c.Assert(err, gc.ErrorMatches, "environment is not prepared")
c.Assert(e, gc.IsNil)
}
示例6: TestConfigForNameNoDefault
func (*OpenSuite) TestConfigForNameNoDefault(c *gc.C) {
cfg, source, err := environs.ConfigForName("", configstore.NewMem())
c.Assert(err, gc.ErrorMatches, "no default environment found")
c.Assert(cfg, gc.IsNil)
c.Assert(source, gc.Equals, environs.ConfigFromEnvirons)
}
示例7: TestConfigForName
func (*OpenSuite) TestConfigForName(c *gc.C) {
cfg, source, err := environs.ConfigForName("erewhemos", configstore.NewMem())
c.Assert(err, gc.IsNil)
c.Assert(source, gc.Equals, environs.ConfigFromEnvirons)
c.Assert(cfg.Name(), gc.Equals, "erewhemos")
}
示例8: checkProviderType
}
if strings.Contains(err.Error(), apiserver.UpgradeInProgressError.Error()) {
ctx.Infof("Waiting for API to become available")
continue
}
return err
}
return err
}
var environType = func(envName string) (string, error) {
store, err := configstore.Default()
if err != nil {
return "", errors.Trace(err)
}
cfg, _, err := environs.ConfigForName(envName, store)
if err != nil {
return "", errors.Trace(err)
}
return cfg.Type(), nil
}
// checkProviderType ensures the provider type is okay.
func checkProviderType(envName string) error {
envType, err := environType(envName)
if err != nil {
return errors.Trace(err)
}
featureflag.SetFlagsFromEnvironment(osenv.JujuFeatureFlagEnvKey)
flag, ok := provisionalProviders[envType]
示例9: Config
func (c *EnvCommandBase) Config(store configstore.Storage) (*config.Config, error) {
cfg, _, err := environs.ConfigForName(c.envName, store)
return cfg, err
}
示例10: Run
func (c *restoreCommand) Run(ctx *cmd.Context) error {
if c.showDescription {
fmt.Fprintf(ctx.Stdout, "%s\n", c.Info().Purpose)
return nil
}
if err := c.Log.Start(ctx); err != nil {
return err
}
agentConf, err := extractConfig(c.backupFile)
if err != nil {
return fmt.Errorf("cannot extract configuration from backup file: %v", err)
}
progress("extracted credentials from backup file")
store, err := configstore.Default()
if err != nil {
return err
}
cfg, _, err := environs.ConfigForName(c.EnvName, store)
if err != nil {
return err
}
env, err := rebootstrap(cfg, ctx, c.Constraints)
if err != nil {
return fmt.Errorf("cannot re-bootstrap environment: %v", err)
}
progress("connecting to newly bootstrapped instance")
conn, err := juju.NewAPIConn(env, api.DefaultDialOpts())
if err != nil {
return fmt.Errorf("cannot connect to bootstrap instance: %v", err)
}
progress("restoring bootstrap machine")
newInstId, machine0Addr, err := restoreBootstrapMachine(conn, c.backupFile, agentConf)
if err != nil {
return fmt.Errorf("cannot restore bootstrap machine: %v", err)
}
progress("restored bootstrap machine")
// Update the environ state to point to the new instance.
if err := bootstrap.SaveState(env.Storage(), &bootstrap.BootstrapState{
StateInstances: []instance.Id{newInstId},
}); err != nil {
return fmt.Errorf("cannot update environ bootstrap state storage: %v", err)
}
// Construct our own state info rather than using juju.NewConn so
// that we can avoid storage eventual-consistency issues
// (and it's faster too).
caCert, ok := cfg.CACert()
if !ok {
return fmt.Errorf("configuration has no CA certificate")
}
progress("opening state")
st, err := state.Open(&state.Info{
Info: mongo.Info{
Addrs: []string{fmt.Sprintf("%s:%d", machine0Addr, cfg.StatePort())},
CACert: caCert,
},
Tag: agentConf.Credentials.Tag,
Password: agentConf.Credentials.Password,
}, mongo.DefaultDialOpts(), environs.NewStatePolicy())
if err != nil {
return fmt.Errorf("cannot open state: %v", err)
}
progress("updating all machines")
if err := updateAllMachines(st, machine0Addr); err != nil {
return fmt.Errorf("cannot update machines: %v", err)
}
return nil
}