本文整理汇总了Golang中github.com/juju/juju/environs.NewFromName函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFromName函数的具体用法?Golang NewFromName怎么用?Golang NewFromName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewFromName函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestNewFromNameWithInvalidEnvironConfig
func (*OpenSuite) TestNewFromNameWithInvalidEnvironConfig(c *gc.C) {
store := configstore.NewMem()
e, err := environs.NewFromName("erewhemos", store)
c.Assert(err, gc.Equals, environs.ErrNotBootstrapped)
c.Assert(e, gc.IsNil)
}
开发者ID:jiasir,项目名称:juju,代码行数:7,代码来源:open_test.go
示例2: Run
func (c *DestroyEnvironmentCommand) Run(ctx *cmd.Context) (result error) {
store, err := configstore.Default()
if err != nil {
return fmt.Errorf("cannot open environment info storage: %v", err)
}
environ, err := environs.NewFromName(c.envName, store)
if err != nil {
if environs.IsEmptyConfig(err) {
// Delete the .jenv file and call it done.
ctx.Infof("removing empty environment file")
return environs.DestroyInfo(c.envName, store)
}
return err
}
if !c.assumeYes {
fmt.Fprintf(ctx.Stdout, destroyEnvMsg, environ.Name(), environ.Config().Type())
scanner := bufio.NewScanner(ctx.Stdin)
scanner.Scan()
err := scanner.Err()
if err != nil && err != io.EOF {
return fmt.Errorf("Environment destruction aborted: %s", err)
}
answer := strings.ToLower(scanner.Text())
if answer != "y" && answer != "yes" {
return errors.New("environment destruction aborted")
}
}
// If --force is supplied, then don't attempt to use the API.
// This is necessary to destroy broken environments, where the
// API server is inaccessible or faulty.
if !c.force {
defer func() {
if result == nil {
return
}
logger.Errorf(`failed to destroy environment %q
If the environment is unusable, then you may run
juju destroy-environment --force
to forcefully destroy the environment. Upon doing so, review
your environment provider console for any resources that need
to be cleaned up.
`, c.envName)
}()
apiclient, err := juju.NewAPIClientFromName(c.envName)
if err != nil {
return fmt.Errorf("cannot connect to API: %v", err)
}
defer apiclient.Close()
err = apiclient.DestroyEnvironment()
if err != nil && !params.IsCodeNotImplemented(err) {
return fmt.Errorf("destroying environment: %v", err)
}
}
return environs.Destroy(environ, store)
}
开发者ID:klyachin,项目名称:juju,代码行数:60,代码来源:destroyenvironment.go
示例3: assertEnvironNotDestroyed
func assertEnvironNotDestroyed(c *gc.C, env environs.Environ, store configstore.Storage) {
info, err := store.ReadInfo(env.Config().Name())
c.Assert(err, gc.IsNil)
c.Assert(info.Initialized(), jc.IsTrue)
_, err = environs.NewFromName(env.Config().Name(), store)
c.Assert(err, gc.IsNil)
}
开发者ID:jiasir,项目名称:juju,代码行数:8,代码来源:destroyenvironment_test.go
示例4: TestNewFromName
func (*OpenSuite) TestNewFromName(c *gc.C) {
store := configstore.NewMem()
ctx := testing.Context(c)
e, err := environs.PrepareFromName("erewhemos", ctx, store)
c.Assert(err, gc.IsNil)
e, err = environs.NewFromName("erewhemos", store)
c.Assert(err, gc.IsNil)
c.Assert(e.Config().Name(), gc.Equals, "erewhemos")
}
开发者ID:jiasir,项目名称:juju,代码行数:10,代码来源:open_test.go
示例5: NewConnFromName
// NewConnFromName returns a Conn pointing at the environName environment, or the
// default environment if not specified.
func NewConnFromName(environName string) (*Conn, error) {
store, err := configstore.Default()
if err != nil {
return nil, err
}
environ, err := environs.NewFromName(environName, store)
if err != nil {
return nil, err
}
return NewConn(environ)
}
开发者ID:rogpeppe,项目名称:juju,代码行数:13,代码来源:conn.go
示例6: 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)
}
开发者ID:jiasir,项目名称:juju,代码行数:17,代码来源:open_test.go
示例7: run
func (s *BootstrapSuite) run(c *gc.C, test bootstrapTest) (restore gitjujutesting.Restorer) {
// Create home with dummy provider and remove all
// of its envtools.
env := resetJujuHome(c, "peckham")
// Although we're testing PrepareEndpointsForCaching interactions
// separately in the juju package, here we just ensure it gets
// called with the right arguments.
prepareCalled := false
addrConnectedTo := "localhost:17070"
restore = gitjujutesting.PatchValue(
&prepareEndpointsForCaching,
func(info configstore.EnvironInfo, hps [][]network.HostPort, addr network.HostPort) (_, _ []string, _ bool) {
prepareCalled = true
addrs, hosts, changed := juju.PrepareEndpointsForCaching(info, hps, addr)
// Because we're bootstrapping the addresses will always
// change, as there's no .jenv file saved yet.
c.Assert(changed, jc.IsTrue)
return addrs, hosts, changed
},
)
if test.version != "" {
useVersion := strings.Replace(test.version, "%LTS%", config.LatestLtsSeries(), 1)
origVersion := version.Current
version.Current = version.MustParseBinary(useVersion)
restore = restore.Add(func() {
version.Current = origVersion
})
}
if test.hostArch != "" {
origArch := arch.HostArch
arch.HostArch = func() string {
return test.hostArch
}
restore = restore.Add(func() {
arch.HostArch = origArch
})
}
// Run command and check for uploads.
opc, errc := cmdtesting.RunCommand(cmdtesting.NullContext(c), envcmd.Wrap(new(BootstrapCommand)), test.args...)
// Check for remaining operations/errors.
if test.err != "" {
err := <-errc
c.Assert(err, gc.NotNil)
stripped := strings.Replace(err.Error(), "\n", "", -1)
c.Check(stripped, gc.Matches, test.err)
return restore
}
if !c.Check(<-errc, gc.IsNil) {
return restore
}
opBootstrap := (<-opc).(dummy.OpBootstrap)
c.Check(opBootstrap.Env, gc.Equals, "peckham")
c.Check(opBootstrap.Args.Constraints, gc.DeepEquals, test.constraints)
c.Check(opBootstrap.Args.Placement, gc.Equals, test.placement)
opFinalizeBootstrap := (<-opc).(dummy.OpFinalizeBootstrap)
c.Check(opFinalizeBootstrap.Env, gc.Equals, "peckham")
c.Check(opFinalizeBootstrap.InstanceConfig.Tools, gc.NotNil)
if test.upload != "" {
c.Check(opFinalizeBootstrap.InstanceConfig.Tools.Version.String(), gc.Equals, test.upload)
}
store, err := configstore.Default()
c.Assert(err, jc.ErrorIsNil)
// Check a CA cert/key was generated by reloading the environment.
env, err = environs.NewFromName("peckham", store)
c.Assert(err, jc.ErrorIsNil)
_, hasCert := env.Config().CACert()
c.Check(hasCert, jc.IsTrue)
_, hasKey := env.Config().CAPrivateKey()
c.Check(hasKey, jc.IsTrue)
info, err := store.ReadInfo("peckham")
c.Assert(err, jc.ErrorIsNil)
c.Assert(info, gc.NotNil)
c.Assert(prepareCalled, jc.IsTrue)
c.Assert(info.APIEndpoint().Addresses, gc.DeepEquals, []string{addrConnectedTo})
return restore
}
开发者ID:kakamessi99,项目名称:juju,代码行数:83,代码来源:bootstrap_test.go
示例8: run
func (test bootstrapTest) run(c *gc.C) {
// Create home with dummy provider and remove all
// of its envtools.
env := resetJujuHome(c)
if test.version != "" {
useVersion := strings.Replace(test.version, "%LTS%", config.LatestLtsSeries(), 1)
origVersion := version.Current
version.Current = version.MustParseBinary(useVersion)
defer func() { version.Current = origVersion }()
}
if test.hostArch != "" {
origVersion := arch.HostArch
arch.HostArch = func() string {
return test.hostArch
}
defer func() { arch.HostArch = origVersion }()
}
if test.upload == "" {
usefulVersion := version.Current
usefulVersion.Series = config.PreferredSeries(env.Config())
envtesting.AssertUploadFakeToolsVersions(c, env.Storage(), usefulVersion)
}
// Run command and check for uploads.
opc, errc := cmdtesting.RunCommand(cmdtesting.NullContext(c), envcmd.Wrap(new(BootstrapCommand)), test.args...)
// Check for remaining operations/errors.
if test.err != "" {
err := <-errc
stripped := strings.Replace(err.Error(), "\n", "", -1)
c.Check(stripped, gc.Matches, test.err)
return
}
if !c.Check(<-errc, gc.IsNil) {
return
}
opPutBootstrapVerifyFile := (<-opc).(dummy.OpPutFile)
c.Check(opPutBootstrapVerifyFile.Env, gc.Equals, "peckham")
c.Check(opPutBootstrapVerifyFile.FileName, gc.Equals, environs.VerificationFilename)
opBootstrap := (<-opc).(dummy.OpBootstrap)
c.Check(opBootstrap.Env, gc.Equals, "peckham")
c.Check(opBootstrap.Args.Constraints, gc.DeepEquals, test.constraints)
c.Check(opBootstrap.Args.Placement, gc.Equals, test.placement)
c.Check(opBootstrap.Args.KeepBroken, gc.Equals, test.keepBroken)
opFinalizeBootstrap := (<-opc).(dummy.OpFinalizeBootstrap)
c.Check(opFinalizeBootstrap.Env, gc.Equals, "peckham")
c.Check(opFinalizeBootstrap.MachineConfig.Tools, gc.NotNil)
if test.upload != "" {
c.Check(opFinalizeBootstrap.MachineConfig.Tools.Version.String(), gc.Equals, test.upload)
}
store, err := configstore.Default()
c.Assert(err, gc.IsNil)
// Check a CA cert/key was generated by reloading the environment.
env, err = environs.NewFromName("peckham", store)
c.Assert(err, gc.IsNil)
_, hasCert := env.Config().CACert()
c.Check(hasCert, gc.Equals, true)
_, hasKey := env.Config().CAPrivateKey()
c.Check(hasKey, gc.Equals, true)
info, err := store.ReadInfo("peckham")
c.Assert(err, gc.IsNil)
c.Assert(info, gc.NotNil)
c.Assert(info.APIEndpoint().Addresses, gc.DeepEquals, []string{"localhost:17070"})
}
开发者ID:zhouqt,项目名称:juju,代码行数:70,代码来源:bootstrap_test.go
示例9: run
func (test bootstrapTest) run(c *gc.C) {
// Create home with dummy provider and remove all
// of its envtools.
env := resetJujuHome(c)
if test.version != "" {
useVersion := strings.Replace(test.version, "%LTS%", config.LatestLtsSeries(), 1)
origVersion := version.Current
version.Current = version.MustParseBinary(useVersion)
defer func() { version.Current = origVersion }()
}
if test.hostArch != "" {
origVersion := arch.HostArch
arch.HostArch = func() string {
return test.hostArch
}
defer func() { arch.HostArch = origVersion }()
}
uploadCount := len(test.uploads)
if uploadCount == 0 {
usefulVersion := version.Current
usefulVersion.Series = config.PreferredSeries(env.Config())
envtesting.AssertUploadFakeToolsVersions(c, env.Storage(), usefulVersion)
}
// Run command and check for uploads.
opc, errc := runCommand(nullContext(c), envcmd.Wrap(new(BootstrapCommand)), test.args...)
// Check for remaining operations/errors.
if test.err != "" {
err := <-errc
stripped := strings.Replace(err.Error(), "\n", "", -1)
c.Check(stripped, gc.Matches, test.err)
return
}
if !c.Check(<-errc, gc.IsNil) {
return
}
if uploadCount > 0 {
for i := 0; i < uploadCount; i++ {
c.Check((<-opc).(dummy.OpPutFile).Env, gc.Equals, "peckham")
}
list, err := envtools.FindTools(
env, version.Current.Major, version.Current.Minor, coretools.Filter{}, envtools.DoNotAllowRetry)
c.Check(err, gc.IsNil)
c.Logf("found: " + list.String())
urls := list.URLs()
c.Check(urls, gc.HasLen, len(test.uploads))
for _, v := range test.uploads {
v := strings.Replace(v, "%LTS%", config.LatestLtsSeries(), 1)
c.Logf("seeking: " + v)
vers := version.MustParseBinary(v)
_, found := urls[vers]
c.Check(found, gc.Equals, true)
}
}
if len(test.uploads) > 0 {
indexFile := (<-opc).(dummy.OpPutFile)
c.Check(indexFile.FileName, gc.Equals, "tools/streams/v1/index.json")
productFile := (<-opc).(dummy.OpPutFile)
c.Check(productFile.FileName, gc.Equals, "tools/streams/v1/com.ubuntu.juju:released:tools.json")
}
opPutBootstrapVerifyFile := (<-opc).(dummy.OpPutFile)
c.Check(opPutBootstrapVerifyFile.Env, gc.Equals, "peckham")
c.Check(opPutBootstrapVerifyFile.FileName, gc.Equals, environs.VerificationFilename)
opPutBootstrapInitFile := (<-opc).(dummy.OpPutFile)
c.Check(opPutBootstrapInitFile.Env, gc.Equals, "peckham")
c.Check(opPutBootstrapInitFile.FileName, gc.Equals, "provider-state")
opBootstrap := (<-opc).(dummy.OpBootstrap)
c.Check(opBootstrap.Env, gc.Equals, "peckham")
c.Check(opBootstrap.Args.Constraints, gc.DeepEquals, test.constraints)
c.Check(opBootstrap.Args.Placement, gc.Equals, test.placement)
store, err := configstore.Default()
c.Assert(err, gc.IsNil)
// Check a CA cert/key was generated by reloading the environment.
env, err = environs.NewFromName("peckham", store)
c.Assert(err, gc.IsNil)
_, hasCert := env.Config().CACert()
c.Check(hasCert, gc.Equals, true)
_, hasKey := env.Config().CAPrivateKey()
c.Check(hasKey, gc.Equals, true)
}
开发者ID:klyachin,项目名称:juju,代码行数:87,代码来源:bootstrap_test.go
注:本文中的github.com/juju/juju/environs.NewFromName函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论