本文整理汇总了Golang中github.com/juju/juju/environs/config.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: MakeConfig
// MakeConfig creates a functional environConfig for a test.
func MakeConfig(c *gc.C, attrs testing.Attrs) *environConfig {
cfg, err := config.New(config.NoDefaults, attrs)
c.Assert(err, gc.IsNil)
env, err := environs.Prepare(cfg, testing.Context(c), configstore.NewMem())
c.Assert(err, gc.IsNil)
return env.(*joyentEnviron).Ecfg()
}
开发者ID:zhouqt,项目名称:juju,代码行数:8,代码来源:export_test.go
示例2: TestUpdateToolsAvailabilityNoMatches
func (s *AgentToolsSuite) TestUpdateToolsAvailabilityNoMatches(c *gc.C) {
fakeModelConfig := func(_ *state.Model) (*config.Config, error) {
sConfig := coretesting.FakeConfig()
sConfig = sConfig.Merge(coretesting.Attrs{
"agent-version": "2.5.0",
})
return config.New(config.NoDefaults, sConfig)
}
s.PatchValue(&modelConfig, fakeModelConfig)
// No new tools available.
fakeToolFinder := func(_ environs.Environ, _ int, _ int, _ string, _ coretools.Filter) (coretools.List, error) {
return nil, errors.NotFoundf("tools")
}
// Update should never be called.
fakeUpdate := func(_ *state.Model, v version.Number) error {
c.Fail()
return nil
}
cfg, err := config.New(config.NoDefaults, coretesting.FakeConfig())
c.Assert(err, jc.ErrorIsNil)
err = updateToolsAvailability(&mockState{configGetter{cfg}}, getDummyEnviron, fakeToolFinder, fakeUpdate)
c.Assert(err, jc.ErrorIsNil)
}
开发者ID:bac,项目名称:juju,代码行数:26,代码来源:agenttools_test.go
示例3: TestUpdateToolsAvailability
func (s *AgentToolsSuite) TestUpdateToolsAvailability(c *gc.C) {
fakeModelConfig := func(_ *state.Model) (*config.Config, error) {
sConfig := coretesting.FakeConfig()
sConfig = sConfig.Merge(coretesting.Attrs{
"agent-version": "2.5.0",
})
return config.New(config.NoDefaults, sConfig)
}
s.PatchValue(&modelConfig, fakeModelConfig)
fakeToolFinder := func(_ environs.Environ, _ int, _ int, _ string, _ coretools.Filter) (coretools.List, error) {
ver := version.Binary{Number: version.Number{Major: 2, Minor: 5, Patch: 2}}
olderVer := version.Binary{Number: version.Number{Major: 2, Minor: 5, Patch: 1}}
t := coretools.Tools{Version: ver, URL: "http://example.com", Size: 1}
tOld := coretools.Tools{Version: olderVer, URL: "http://example.com", Size: 1}
return coretools.List{&t, &tOld}, nil
}
var ver version.Number
fakeUpdate := func(_ *state.Model, v version.Number) error {
ver = v
return nil
}
cfg, err := config.New(config.NoDefaults, coretesting.FakeConfig())
c.Assert(err, jc.ErrorIsNil)
err = updateToolsAvailability(&mockState{configGetter{cfg}}, getDummyEnviron, fakeToolFinder, fakeUpdate)
c.Assert(err, jc.ErrorIsNil)
c.Assert(ver, gc.Not(gc.Equals), version.Zero)
c.Assert(ver, gc.Equals, version.Number{Major: 2, Minor: 5, Patch: 2})
}
开发者ID:bac,项目名称:juju,代码行数:32,代码来源:agenttools_test.go
示例4: TestBootstrapWithDefaultSeries
func (t *LiveTests) TestBootstrapWithDefaultSeries(c *gc.C) {
if !t.HasProvisioner {
c.Skip("HasProvisioner is false; cannot test deployment")
}
current := version.Current
other := current
other.Series = "quantal"
if current == other {
other.Series = "precise"
}
dummyCfg, err := config.New(config.NoDefaults, dummy.SampleConfig().Merge(coretesting.Attrs{
"state-server": false,
"name": "dummy storage",
}))
dummyenv, err := environs.Prepare(dummyCfg, coretesting.Context(c), configstore.NewMem())
c.Assert(err, gc.IsNil)
defer dummyenv.Destroy()
t.Destroy(c)
attrs := t.TestConfig.Merge(coretesting.Attrs{"default-series": other.Series})
cfg, err := config.New(config.NoDefaults, attrs)
c.Assert(err, gc.IsNil)
env, err := environs.Prepare(cfg, coretesting.Context(c), t.ConfigStore)
c.Assert(err, gc.IsNil)
defer environs.Destroy(env, t.ConfigStore)
currentName := envtools.StorageName(current)
otherName := envtools.StorageName(other)
envStorage := env.Storage()
dummyStorage := dummyenv.Storage()
defer envStorage.Remove(otherName)
_, err = sync.Upload(dummyStorage, ¤t.Number)
c.Assert(err, gc.IsNil)
// This will only work while cross-compiling across releases is safe,
// which depends on external elements. Tends to be safe for the last
// few releases, but we may have to refactor some day.
err = storageCopy(dummyStorage, currentName, envStorage, otherName)
c.Assert(err, gc.IsNil)
err = bootstrap.Bootstrap(coretesting.Context(c), env, environs.BootstrapParams{})
c.Assert(err, gc.IsNil)
st := t.Env.(testing.GetStater).GetStateInAPIServer()
// Wait for machine agent to come up on the bootstrap
// machine and ensure it deployed the proper series.
m0, err := st.Machine("0")
c.Assert(err, gc.IsNil)
mw0 := newMachineToolWaiter(m0)
defer mw0.Stop()
waitAgentTools(c, mw0, other)
}
开发者ID:klyachin,项目名称:juju,代码行数:58,代码来源:livetests.go
示例5: TestValidateAcceptsUnchangedConfig
func (*configSuite) TestValidateAcceptsUnchangedConfig(c *gc.C) {
attrs := makeAzureConfigMap(c)
provider := azureEnvironProvider{}
oldConfig, err := config.New(config.NoDefaults, attrs)
c.Assert(err, jc.ErrorIsNil)
newConfig, err := config.New(config.NoDefaults, attrs)
c.Assert(err, jc.ErrorIsNil)
result, err := provider.Validate(newConfig, oldConfig)
c.Assert(err, jc.ErrorIsNil)
c.Check(result.Name(), gc.Equals, attrs["name"])
}
开发者ID:Pankov404,项目名称:juju,代码行数:11,代码来源:config_test.go
示例6: TestValidateChecksConfigChanges
func (*configSuite) TestValidateChecksConfigChanges(c *gc.C) {
provider := azureEnvironProvider{}
oldConfig, err := config.New(config.NoDefaults, makeConfigMap(nil))
c.Assert(err, jc.ErrorIsNil)
newAttrs := makeConfigMap(map[string]interface{}{
"name": "different-name",
})
newConfig, err := config.New(config.NoDefaults, newAttrs)
c.Assert(err, jc.ErrorIsNil)
_, err = provider.Validate(newConfig, oldConfig)
c.Check(err, gc.NotNil)
}
开发者ID:Pankov404,项目名称:juju,代码行数:12,代码来源:config_test.go
示例7: TestPrepareUseSSHStorage
func (s *providerSuite) TestPrepareUseSSHStorage(c *gc.C) {
minimal := manual.MinimalConfigValues()
minimal["use-sshstorage"] = false
testConfig, err := config.New(config.UseDefaults, minimal)
c.Assert(err, jc.ErrorIsNil)
_, err = manual.ProviderInstance.PrepareForBootstrap(envtesting.BootstrapContext(c), testConfig)
c.Assert(err, gc.ErrorMatches, "use-sshstorage must not be specified")
minimal["use-sshstorage"] = true
testConfig, err = config.New(config.UseDefaults, minimal)
c.Assert(err, jc.ErrorIsNil)
_, err = manual.ProviderInstance.PrepareForBootstrap(envtesting.BootstrapContext(c), testConfig)
c.Assert(err, jc.ErrorIsNil)
}
开发者ID:imoapps,项目名称:juju,代码行数:14,代码来源:provider_test.go
示例8: assertGetImageMetadataSources
func (s *localServerSuite) assertGetImageMetadataSources(c *gc.C, stream, officialSourcePath string) {
// Create a config that matches s.TestConfig but with the specified stream.
envAttrs := s.TestConfig
if stream != "" {
envAttrs = envAttrs.Merge(coretesting.Attrs{"image-stream": stream})
}
cfg, err := config.New(config.NoDefaults, envAttrs)
c.Assert(err, gc.IsNil)
env, err := environs.New(cfg)
c.Assert(err, gc.IsNil)
sources, err := imagemetadata.GetMetadataSources(env)
c.Assert(err, gc.IsNil)
c.Assert(sources, gc.HasLen, 4)
var urls = make([]string, len(sources))
for i, source := range sources {
url, err := source.URL("")
c.Assert(err, gc.IsNil)
urls[i] = url
}
// The image-metadata-url ends with "/juju-dist-test/".
c.Check(strings.HasSuffix(urls[0], "/juju-dist-test/"), jc.IsTrue)
// The control bucket URL contains the bucket name.
c.Check(strings.Contains(urls[1], openstack.ControlBucketName(env)+"/images"), jc.IsTrue)
// The product-streams URL ends with "/imagemetadata".
c.Check(strings.HasSuffix(urls[2], "/imagemetadata/"), jc.IsTrue)
c.Assert(urls[3], gc.Equals, fmt.Sprintf("http://cloud-images.ubuntu.com/%s/", officialSourcePath))
}
开发者ID:klyachin,项目名称:juju,代码行数:27,代码来源:local_test.go
示例9: SetUpTest
func (s *ToolsMetadataSuite) SetUpTest(c *gc.C) {
s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
s.AddCleanup(dummy.Reset)
cfg, err := config.New(config.UseDefaults, map[string]interface{}{
"name": "erewhemos",
"type": "dummy",
"uuid": coretesting.ModelTag.Id(),
"controller-uuid": coretesting.ControllerTag.Id(),
"conroller": true,
})
c.Assert(err, jc.ErrorIsNil)
env, err := bootstrap.Prepare(
modelcmd.BootstrapContextNoVerify(coretesting.Context(c)),
jujuclienttesting.NewMemStore(),
bootstrap.PrepareParams{
ControllerConfig: coretesting.FakeControllerConfig(),
ControllerName: cfg.Name(),
ModelConfig: cfg.AllAttrs(),
Cloud: dummy.SampleCloudSpec(),
AdminSecret: "admin-secret",
},
)
c.Assert(err, jc.ErrorIsNil)
s.env = env
loggo.GetLogger("").SetLogLevel(loggo.INFO)
// Switch the default tools location.
s.publicStorageDir = c.MkDir()
s.PatchValue(&tools.DefaultBaseURL, s.publicStorageDir)
}
开发者ID:bac,项目名称:juju,代码行数:30,代码来源:toolsmetadata_test.go
示例10: TestNewAPIState
func (cs *NewAPIStateSuite) TestNewAPIState(c *gc.C) {
cfg, err := config.New(config.NoDefaults, dummy.SampleConfig())
c.Assert(err, jc.ErrorIsNil)
ctx := envtesting.BootstrapContext(c)
env, err := environs.Prepare(cfg, ctx, configstore.NewMem())
c.Assert(err, jc.ErrorIsNil)
storageDir := c.MkDir()
cs.PatchValue(&envtools.DefaultBaseURL, storageDir)
stor, err := filestorage.NewFileStorageWriter(storageDir)
c.Assert(err, jc.ErrorIsNil)
envtesting.UploadFakeTools(c, stor, "released", "released")
err = bootstrap.Bootstrap(ctx, env, bootstrap.BootstrapParams{})
c.Assert(err, jc.ErrorIsNil)
cfg = env.Config()
cfg, err = cfg.Apply(map[string]interface{}{
"secret": "fnord",
})
c.Assert(err, jc.ErrorIsNil)
err = env.SetConfig(cfg)
c.Assert(err, jc.ErrorIsNil)
st, err := juju.NewAPIState(dummy.AdminUserTag(), env, api.DialOpts{})
c.Assert(st, gc.NotNil)
// the secrets will not be updated, as they already exist
attrs, err := st.Client().EnvironmentGet()
c.Assert(attrs["secret"], gc.Equals, "pork")
c.Assert(st.Close(), gc.IsNil)
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:33,代码来源:api_test.go
示例11: getEnvironConfig
func getEnvironConfig(c *gc.C, attrs map[string]interface{}) *environConfig {
testConfig, err := config.New(config.UseDefaults, attrs)
c.Assert(err, jc.ErrorIsNil)
envConfig, err := manualProvider{}.validate(testConfig, nil)
c.Assert(err, jc.ErrorIsNil)
return envConfig
}
开发者ID:Pankov404,项目名称:juju,代码行数:7,代码来源:config_test.go
示例12: TestPrepareGeneratesDifferentAdminSecrets
func (*OpenSuite) TestPrepareGeneratesDifferentAdminSecrets(c *gc.C) {
baselineAttrs := dummy.SampleConfig().Merge(testing.Attrs{
"state-server": false,
"name": "erewhemos",
}).Delete(
"admin-secret",
)
cfg, err := config.New(config.NoDefaults, baselineAttrs)
c.Assert(err, gc.IsNil)
ctx := testing.Context(c)
env0, err := environs.Prepare(cfg, ctx, configstore.NewMem())
c.Assert(err, gc.IsNil)
adminSecret0 := env0.Config().AdminSecret()
c.Assert(adminSecret0, gc.HasLen, 32)
c.Assert(adminSecret0, gc.Matches, "^[0-9a-f]*$")
env1, err := environs.Prepare(cfg, ctx, configstore.NewMem())
c.Assert(err, gc.IsNil)
adminSecret1 := env1.Config().AdminSecret()
c.Assert(adminSecret1, gc.HasLen, 32)
c.Assert(adminSecret1, gc.Matches, "^[0-9a-f]*$")
c.Assert(adminSecret1, gc.Not(gc.Equals), adminSecret0)
}
开发者ID:jiasir,项目名称:juju,代码行数:25,代码来源:open_test.go
示例13: mockTestingEnvConfig
// mockTestingEnvConfig prepares an environment configuration using
// the mock provider which does not support networking.
func mockTestingEnvConfig(c *gc.C) *config.Config {
cfg, err := config.New(config.NoDefaults, mockConfig())
c.Assert(err, jc.ErrorIsNil)
env, err := environs.Prepare(cfg, modelcmd.BootstrapContext(coretesting.Context(c)), configstore.NewMem())
c.Assert(err, jc.ErrorIsNil)
return env.Config()
}
开发者ID:exekias,项目名称:juju,代码行数:9,代码来源:addresser_test.go
示例14: testingEnvConfig
// testingEnvConfig prepares an environment configuration using
// the dummy provider.
func testingEnvConfig(c *gc.C) *config.Config {
cfg, err := config.New(config.NoDefaults, dummy.SampleConfig())
c.Assert(err, jc.ErrorIsNil)
env, err := environs.Prepare(cfg, envcmd.BootstrapContext(testing.Context(c)), configstore.NewMem())
c.Assert(err, jc.ErrorIsNil)
return env.Config()
}
开发者ID:imoapps,项目名称:juju,代码行数:9,代码来源:undertaker_test.go
示例15: TestFirewallMode
func (s *ConfigSuite) TestFirewallMode(c *gc.C) {
for i, test := range firewallModeTests {
c.Logf("test %d: %s", i, test.configFirewallMode)
attrs := dummy.SampleConfig()
if test.configFirewallMode != "" {
attrs = attrs.Merge(testing.Attrs{
"firewall-mode": test.configFirewallMode,
})
}
cfg, err := config.New(config.NoDefaults, attrs)
if err != nil {
c.Assert(err, gc.ErrorMatches, test.errorMsg)
continue
}
ctx := testing.Context(c)
env, err := environs.Prepare(cfg, ctx, configstore.NewMem())
if test.errorMsg != "" {
c.Assert(err, gc.ErrorMatches, test.errorMsg)
continue
}
c.Assert(err, gc.IsNil)
defer env.Destroy()
firewallMode := env.Config().FirewallMode()
c.Assert(firewallMode, gc.Equals, test.firewallMode)
s.TearDownTest(c)
}
}
开发者ID:kapilt,项目名称:juju,代码行数:29,代码来源:config_test.go
示例16: Prepare
// Prepare prepares a new environment based on the provided configuration.
// If the environment is already prepared, it behaves like New.
func Prepare(cfg *config.Config, ctx BootstrapContext, store configstore.Storage) (Environ, error) {
if p, err := Provider(cfg.Type()); err != nil {
return nil, err
} else if info, err := store.ReadInfo(cfg.Name()); errors.IsNotFound(errors.Cause(err)) {
info = store.CreateInfo(cfg.Name())
if env, err := prepare(ctx, cfg, info, p); err == nil {
return env, decorateAndWriteInfo(info, env.Config())
} else {
if err := info.Destroy(); err != nil {
logger.Warningf("cannot destroy newly created environment info: %v", err)
}
return nil, err
}
} else if err != nil {
return nil, errors.Annotatef(err, "error reading environment info %q", cfg.Name())
} else if !info.Initialized() {
return nil,
errors.Errorf(
"found uninitialized environment info for %q; environment preparation probably in progress or interrupted",
cfg.Name(),
)
} else if len(info.BootstrapConfig()) == 0 {
return nil, errors.New("found environment info but no bootstrap config")
} else {
cfg, err = config.New(config.NoDefaults, info.BootstrapConfig())
if err != nil {
return nil, errors.Annotate(err, "cannot parse bootstrap config")
}
return New(cfg)
}
}
开发者ID:zhouqt,项目名称:juju,代码行数:35,代码来源:open.go
示例17: makeTestEnv
func (s *BootstrapSuite) makeTestEnv(c *gc.C) {
attrs := dummy.SampleConfig().Merge(
testing.Attrs{
"agent-version": version.Current.Number.String(),
"bootstrap-timeout": "123",
},
).Delete("admin-secret", "ca-private-key")
cfg, err := config.New(config.NoDefaults, attrs)
c.Assert(err, jc.ErrorIsNil)
provider, err := environs.Provider(cfg.Type())
c.Assert(err, jc.ErrorIsNil)
env, err := provider.PrepareForBootstrap(nullContext(), cfg)
c.Assert(err, jc.ErrorIsNil)
envtesting.MustUploadFakeTools(s.toolsStorage, cfg.AgentStream(), cfg.AgentStream())
inst, _, _, err := jujutesting.StartInstance(env, "0")
c.Assert(err, jc.ErrorIsNil)
s.instanceId = inst.Id()
addresses, err := inst.Addresses()
c.Assert(err, jc.ErrorIsNil)
s.bootstrapName = network.SelectPublicAddress(addresses)
s.envcfg = env.Config()
s.b64yamlEnvcfg = b64yaml(s.envcfg.AllAttrs()).encode()
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:25,代码来源:bootstrap_test.go
示例18: ConfigForName
// ConfigForName returns the configuration for the environment with
// the given name from the default environments file. If the name is
// blank, the default environment will be used. If the configuration
// is not found, an errors.NotFoundError is returned. If the given
// store contains an entry for the environment and it has associated
// bootstrap config, that configuration will be returned.
// ConfigForName also returns where the configuration was sourced from
// (this is also valid even when there is an error.
func ConfigForName(name string, store configstore.Storage) (*config.Config, ConfigSource, error) {
envs, err := ReadEnvirons("")
if err != nil {
return nil, ConfigFromNowhere, err
}
if name == "" {
name = envs.Default
}
// TODO(rog) 2013-10-04 https://bugs.github.com/juju/juju/+bug/1235217
// Don't fall back to reading from environments.yaml
// when we can be sure that everyone has a
// .jenv file for their currently bootstrapped environments.
if name != "" {
info, err := store.ReadInfo(name)
if err == nil {
if len(info.BootstrapConfig()) == 0 {
return nil, ConfigFromNowhere, EmptyConfig{fmt.Errorf("environment has no bootstrap configuration data")}
}
logger.Debugf("ConfigForName found bootstrap config %#v", info.BootstrapConfig())
cfg, err := config.New(config.NoDefaults, info.BootstrapConfig())
return cfg, ConfigFromInfo, err
}
if err != nil && !errors.IsNotFound(err) {
return nil, ConfigFromInfo, fmt.Errorf("cannot read environment info for %q: %v", name, err)
}
}
cfg, err := envs.Config(name)
return cfg, ConfigFromEnvirons, err
}
开发者ID:klyachin,项目名称:juju,代码行数:37,代码来源:open.go
示例19: TestDestroy
func (*OpenSuite) TestDestroy(c *gc.C) {
cfg, err := config.New(config.NoDefaults, dummy.SampleConfig().Merge(
testing.Attrs{
"state-server": false,
"name": "erewhemos",
},
))
c.Assert(err, gc.IsNil)
store := configstore.NewMem()
// Prepare the environment and sanity-check that
// the config storage info has been made.
ctx := testing.Context(c)
e, err := environs.Prepare(cfg, ctx, store)
c.Assert(err, gc.IsNil)
_, err = store.ReadInfo(e.Config().Name())
c.Assert(err, gc.IsNil)
err = environs.Destroy(e, store)
c.Assert(err, gc.IsNil)
// Check that the environment has actually been destroyed
// and that the config info has been destroyed too.
_, err = e.StateServerInstances()
c.Assert(err, gc.ErrorMatches, "environment has been destroyed")
_, err = store.ReadInfo(e.Config().Name())
c.Assert(err, jc.Satisfies, errors.IsNotFound)
}
开发者ID:jiasir,项目名称:juju,代码行数:28,代码来源:open_test.go
示例20: ModelConfig
// ModelConfig returns the complete config for the model represented
// by this state.
func (st *State) ModelConfig() (*config.Config, error) {
modelSettings, err := readSettings(st, settingsC, modelGlobalKey)
if err != nil {
return nil, errors.Trace(err)
}
return config.New(config.NoDefaults, modelSettings.Map())
}
开发者ID:bac,项目名称:juju,代码行数:9,代码来源:modelconfig.go
注:本文中的github.com/juju/juju/environs/config.New函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论