本文整理汇总了Golang中launchpad/net/juju-core/environs.NewFromName函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFromName函数的具体用法?Golang NewFromName怎么用?Golang NewFromName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewFromName函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SetUpTest
func (s *syncToolsSuite) SetUpTest(c *C) {
s.LoggingSuite.SetUpTest(c)
s.origVersion = version.Current
// It's important that this be v1 to match the test data.
version.Current.Number = version.MustParse("1.2.3")
// Create a target environments.yaml and make sure its environment is empty.
s.home = testing.MakeFakeHome(c, `
environments:
test-target:
type: dummy
state-server: false
authorized-keys: "not-really-one"
`)
var err error
s.targetEnv, err = environs.NewFromName("test-target")
c.Assert(err, IsNil)
envtesting.RemoveAllTools(c, s.targetEnv)
// Create a source storage.
s.storage, err = envtesting.NewEC2HTTPTestStorage("127.0.0.1")
c.Assert(err, IsNil)
// Create a local tools directory.
s.localStorage = c.MkDir()
// Populate both with the public tools.
for _, vers := range vAll {
s.storage.PutBinary(vers)
putBinary(c, s.localStorage, vers)
}
s.origLocation = defaultToolsLocation
defaultToolsLocation = s.storage.Location()
}
示例2: NewConnFromName
// NewConnFromName returns a Conn pointing at the environName environment, or the
// default environment if not specified.
func NewConnFromName(environName string) (*Conn, error) {
environ, err := environs.NewFromName(environName)
if err != nil {
return nil, err
}
return NewConn(environ)
}
示例3: Run
func (c *DestroyEnvironmentCommand) Run(_ *cmd.Context) error {
environ, err := environs.NewFromName(c.EnvName)
if err != nil {
return err
}
return environ.Destroy(nil)
}
示例4: Run
// Run connects to the environment specified on the command line and bootstraps
// a juju in that environment if none already exists.
func (c *BootstrapCommand) Run(_ *cmd.Context) error {
environ, err := environs.NewFromName(c.EnvName)
if err != nil {
return err
}
return environs.Bootstrap(environ, c.UploadTools, nil)
}
示例5: TestNewFromNameGetDefault
func (OpenSuite) TestNewFromNameGetDefault(c *C) {
defer testing.MakeFakeHome(c, testing.SingleEnvConfig, testing.SampleCertName).Restore()
e, err := environs.NewFromName("")
c.Assert(err, IsNil)
c.Assert(e.Name(), Equals, "erewhemos")
}
示例6: build
func build() error {
environ, err := environs.NewFromName("")
if err != nil {
return err
}
err = environs.Bootstrap(environ, true, nil)
if err != nil {
return err
}
conn, err := juju.NewConn(environ)
if err != nil {
return err
}
repo := &charm.LocalRepository{filepath.Dir(os.Args[0])}
curl := charm.MustParseURL("local:precise/builddb")
ch, err := conn.PutCharm(curl, repo, false)
if err != nil {
return err
}
service, err := conn.AddService("builddb", ch)
if err != nil {
return err
}
if err := service.SetExposed(); err != nil {
return err
}
units, err := conn.AddUnits(service, 1)
if err != nil {
return err
}
log.Printf("builddb: Waiting for unit to reach %q status...", state.UnitStarted)
unit := units[0]
last, info, err := unit.Status()
if err != nil {
return err
}
logStatus(last, info)
for last != state.UnitStarted {
time.Sleep(2 * time.Second)
if err := unit.Refresh(); err != nil {
return err
}
status, info, err := unit.Status()
if err != nil {
return err
}
if status != last {
logStatus(status, info)
last = status
}
}
addr, ok := unit.PublicAddress()
if !ok {
return fmt.Errorf("cannot retrieve files: build unit lacks a public-address")
}
log.Printf("builddb: Built files published at http://%s", addr)
log.Printf("builddb: Remember to destroy the environment when you're done...")
return nil
}
示例7: makeEmptyFakeHome
// makeEmptyFakeHome creates a faked home without tools.
func makeEmptyFakeHome(c *gc.C) (environs.Environ, *coretesting.FakeHome) {
fake := coretesting.MakeFakeHome(c, envConfig)
dummy.Reset()
env, err := environs.NewFromName("peckham")
c.Assert(err, gc.IsNil)
envtesting.RemoveAllTools(c, env)
return env, fake
}
示例8: TestNewConnFromName
func (*NewConnSuite) TestNewConnFromName(c *C) {
home := c.MkDir()
defer os.Setenv("HOME", os.Getenv("HOME"))
os.Setenv("HOME", home)
conn, err := juju.NewConnFromName("")
c.Assert(conn, IsNil)
c.Assert(err, ErrorMatches, ".*: no such file or directory")
if err := os.Mkdir(filepath.Join(home, ".juju"), 0755); err != nil {
c.Fatal("Could not create directory structure")
}
envs := filepath.Join(home, ".juju", "environments.yaml")
err = ioutil.WriteFile(envs, []byte(`
default:
erewhemos
environments:
erewhemos:
type: dummy
state-server: true
authorized-keys: i-am-a-key
admin-secret: conn-from-name-secret
`), 0644)
err = ioutil.WriteFile(filepath.Join(home, ".juju", "erewhemos-cert.pem"), []byte(coretesting.CACert), 0600)
c.Assert(err, IsNil)
err = ioutil.WriteFile(filepath.Join(home, ".juju", "erewhemos-private-key.pem"), []byte(coretesting.CAKey), 0600)
c.Assert(err, IsNil)
// Just run through a few operations on the dummy provider and verify that
// they behave as expected.
conn, err = juju.NewConnFromName("")
c.Assert(err, ErrorMatches, "dummy environment not bootstrapped")
environ, err := environs.NewFromName("")
c.Assert(err, IsNil)
err = environs.Bootstrap(environ, false, panicWrite)
c.Assert(err, IsNil)
conn, err = juju.NewConnFromName("")
c.Assert(err, IsNil)
defer conn.Close()
c.Assert(conn.Environ, NotNil)
c.Assert(conn.Environ.Name(), Equals, "erewhemos")
c.Assert(conn.State, NotNil)
// Reset the admin password so the state db can be reused.
err = conn.State.SetAdminMongoPassword("")
c.Assert(err, IsNil)
// Close the conn (thereby closing its state) a couple of times to
// verify that multiple closes will not panic. We ignore the error,
// as the underlying State will return an error the second
// time.
conn.Close()
conn.Close()
}
示例9: TestVerifyStorageFails
func (s *verifyStorageSuite) TestVerifyStorageFails(c *C) {
defer testing.MakeFakeHome(c, existingEnv, "existing").Restore()
environ, err := environs.NewFromName("test")
c.Assert(err, IsNil)
storage := environ.Storage()
someError := errors.Unauthorizedf("you shall not pass")
dummy.Poison(storage, "bootstrap-verify", someError)
err = environs.VerifyStorage(storage)
c.Assert(err, Equals, environs.VerifyStorageError)
}
示例10: TestEnsureCertificate
func (*EnvironsCertSuite) TestEnsureCertificate(c *C) {
defer testing.MakeFakeHome(c, testing.SingleEnvConfig).Restore()
env, err := environs.NewFromName(testing.SampleEnvName)
c.Assert(err, IsNil)
writeCalled := false
created, err := environs.EnsureCertificate(env, func(name string, cert, key []byte) error {
writeCalled = true
return nil
})
c.Assert(err, IsNil)
c.Assert(created, Equals, environs.CertCreated)
c.Assert(writeCalled, Equals, true)
}
示例11: TestCheckEnvironment
func (s *checkEnvironmentSuite) TestCheckEnvironment(c *C) {
defer testing.MakeFakeHome(c, checkEnv, "existing").Restore()
environ, err := environs.NewFromName("test")
c.Assert(err, IsNil)
// VerifyStorage is sufficient for our tests and much simpler
// than Bootstrap which calls it.
storage := environ.Storage()
err = environs.VerifyStorage(storage)
c.Assert(err, IsNil)
err = environs.CheckEnvironment(environ)
c.Assert(err, IsNil)
}
示例12: Run
// Run connects to the environment specified on the command line and bootstraps
// a juju in that environment if none already exists. If there is as yet no environments.yaml file,
// the user is informed how to create one.
func (c *BootstrapCommand) Run(context *cmd.Context) error {
environ, err := environs.NewFromName(c.EnvName)
if err != nil {
if os.IsNotExist(err) {
out := context.Stderr
fmt.Fprintln(out, "No juju environment configuration file exists.")
fmt.Fprintln(out, "Please create a configuration by running:")
fmt.Fprintln(out, " juju init -w")
fmt.Fprintln(out, "then edit the file to configure your juju environment.")
fmt.Fprintln(out, "You can then re-run bootstrap.")
}
return err
}
// TODO: if in verbose mode, write out to Stdout if a new cert was created.
_, err = environs.EnsureCertificate(environ, environs.WriteCertAndKey)
if err != nil {
return err
}
// If we are using a local provider, always upload tools.
if environ.Config().Type() == provider.Local {
c.UploadTools = true
}
if c.UploadTools {
// Force version.Current, for consistency with subsequent upgrade-juju
// (see UpgradeJujuCommand).
forceVersion := uploadVersion(version.Current.Number, nil)
cfg := environ.Config()
series := getUploadSeries(cfg, c.Series)
tools, err := uploadTools(environ.Storage(), &forceVersion, series...)
if err != nil {
return err
}
cfg, err = cfg.Apply(map[string]interface{}{
"agent-version": tools.Version.Number.String(),
})
if err == nil {
err = environ.SetConfig(cfg)
}
if err != nil {
return fmt.Errorf("failed to update environment configuration: %v", err)
}
}
err = c.ensureToolsAvailability(environ, context)
if err != nil {
return err
}
return environs.Bootstrap(environ, c.Constraints)
}
示例13: TestVerifyStorage
func (s *verifyStorageSuite) TestVerifyStorage(c *C) {
defer testing.MakeFakeHome(c, existingEnv, "existing").Restore()
environ, err := environs.NewFromName("test")
c.Assert(err, IsNil)
storage := environ.Storage()
err = environs.VerifyStorage(storage)
c.Assert(err, IsNil)
reader, err := storage.Get("bootstrap-verify")
c.Assert(err, IsNil)
defer reader.Close()
contents, err := ioutil.ReadAll(reader)
c.Assert(err, IsNil)
c.Check(string(contents), Equals,
"juju-core storage writing verified: ok\n")
}
示例14: SetUpTest
func (s *syncToolsSuite) SetUpTest(c *gc.C) {
s.LoggingSuite.SetUpTest(c)
// Create a target environments.yaml and make sure its environment is empty.
s.home = coretesting.MakeFakeHome(c, `
environments:
test-target:
type: dummy
state-server: false
authorized-keys: "not-really-one"
`)
var err error
s.targetEnv, err = environs.NewFromName("test-target")
c.Assert(err, gc.IsNil)
envtesting.RemoveAllTools(c, s.targetEnv)
s.origSyncTools = syncTools
}
示例15: Run
func (c *DestroyEnvironmentCommand) Run(ctx *cmd.Context) error {
environ, err := environs.NewFromName(c.EnvName)
if err != nil {
return err
}
if !c.assumeYes {
var answer string
fmt.Fprintf(ctx.Stdout, destroyEnvMsg[1:], environ.Name(), environ.Config().Type())
fmt.Fscanln(ctx.Stdin, &answer) // ignore error, treat as "n"
answer = strings.ToLower(answer)
if answer != "y" && answer != "yes" {
return errors.New("Environment destruction aborted")
}
}
return environ.Destroy(nil)
}