本文整理汇总了Golang中launchpad/net/juju-core/environs.Bootstrap函数的典型用法代码示例。如果您正苦于以下问题:Golang Bootstrap函数的具体用法?Golang Bootstrap怎么用?Golang Bootstrap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Bootstrap函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestBootstrap
func (t *Tests) TestBootstrap(c *C) {
// TODO tests for Bootstrap(true)
e := t.Open(c)
err := environs.Bootstrap(e, false, panicWrite)
c.Assert(err, IsNil)
info, err := e.StateInfo()
c.Assert(info, NotNil)
c.Check(info.Addrs, Not(HasLen), 0)
err = environs.Bootstrap(e, false, panicWrite)
c.Assert(err, ErrorMatches, "environment is already bootstrapped")
e2 := t.Open(c)
err = environs.Bootstrap(e2, false, panicWrite)
c.Assert(err, ErrorMatches, "environment is already bootstrapped")
info2, err := e2.StateInfo()
c.Check(info2, DeepEquals, info)
err = e2.Destroy(nil)
c.Assert(err, IsNil)
// Open again because Destroy invalidates old environments.
e3 := t.Open(c)
err = environs.Bootstrap(e3, false, panicWrite)
c.Assert(err, IsNil)
err = environs.Bootstrap(e3, false, panicWrite)
c.Assert(err, NotNil)
}
示例2: TestBootstrapNeedsSettings
func (s *bootstrapSuite) TestBootstrapNeedsSettings(c *gc.C) {
env := newEnviron("bar", noKeysDefined)
cleanup := setDummyStorage(c, env)
defer cleanup()
fixEnv := func(key string, value interface{}) {
cfg, err := env.Config().Apply(map[string]interface{}{
key: value,
})
c.Assert(err, gc.IsNil)
env.cfg = cfg
}
err := environs.Bootstrap(env, constraints.Value{})
c.Assert(err, gc.ErrorMatches, "environment configuration has no admin-secret")
fixEnv("admin-secret", "whatever")
err = environs.Bootstrap(env, constraints.Value{})
c.Assert(err, gc.ErrorMatches, "environment configuration has no ca-cert")
fixEnv("ca-cert", testing.CACert)
err = environs.Bootstrap(env, constraints.Value{})
c.Assert(err, gc.ErrorMatches, "environment configuration has no ca-private-key")
fixEnv("ca-private-key", testing.CAKey)
err = environs.Bootstrap(env, constraints.Value{})
c.Assert(err, gc.IsNil)
}
示例3: TestBootstrapUploadTools
func (s *bootstrapSuite) TestBootstrapUploadTools(c *C) {
env := newEnviron("foo", nil, nil)
err := environs.Bootstrap(env, false, nil)
c.Assert(err, IsNil)
c.Assert(env.bootstrapCount, Equals, 1)
c.Assert(env.uploadTools, Equals, false)
env = newEnviron("foo", nil, nil)
err = environs.Bootstrap(env, true, nil)
c.Assert(err, IsNil)
c.Assert(env.bootstrapCount, Equals, 1)
c.Assert(env.uploadTools, Equals, true)
}
示例4: 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
}
示例5: TestBootstrapEmptyConstraints
func (s *bootstrapSuite) TestBootstrapEmptyConstraints(c *gc.C) {
env := newEnviron("foo", useDefaultKeys)
err := environs.Bootstrap(env, constraints.Value{})
c.Assert(err, gc.IsNil)
c.Assert(env.bootstrapCount, gc.Equals, 1)
c.Assert(env.constraints, gc.DeepEquals, constraints.Value{})
}
示例6: TestBootstrapWithDefaultSeries
func (t *LiveTests) TestBootstrapWithDefaultSeries(c *C) {
if !t.HasProvisioner {
c.Skip("HasProvisioner is false; cannot test deployment")
}
current := version.Current
other := current
other.Series = "precise"
if current == other {
other.Series = "quantal"
}
cfg := t.Env.Config()
cfg, err := cfg.Apply(map[string]interface{}{"default-series": other.Series})
c.Assert(err, IsNil)
env, err := environs.New(cfg)
c.Assert(err, IsNil)
dummyenv, err := environs.NewFromAttrs(map[string]interface{}{
"type": "dummy",
"name": "dummy storage",
"secret": "pizza",
"state-server": false,
})
c.Assert(err, IsNil)
defer dummyenv.Destroy(nil)
currentPath := environs.ToolsStoragePath(current)
otherPath := environs.ToolsStoragePath(other)
envStorage := env.Storage()
dummyStorage := dummyenv.Storage()
defer envStorage.Remove(otherPath)
_, err = environs.PutTools(dummyStorage, ¤t.Number)
c.Assert(err, 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, currentPath, envStorage, otherPath)
c.Assert(err, IsNil)
err = environs.Bootstrap(env, false, panicWrite)
c.Assert(err, IsNil)
defer env.Destroy(nil)
conn, err := juju.NewConn(env)
c.Assert(err, IsNil)
defer conn.Close()
// Wait for machine agent to come up on the bootstrap
// machine and ensure it deployed the proper series.
m0, err := conn.State.Machine("0")
c.Assert(err, IsNil)
mw0 := newMachineToolWaiter(m0)
defer mw0.Stop()
waitAgentTools(c, mw0, other)
}
示例7: TestStartInstanceWithoutPublicIP
// If the environment is configured not to require a public IP address for nodes,
// bootstrapping and starting an instance should occur without any attempt to
// allocate a public address.
func (s *localServerSuite) TestStartInstanceWithoutPublicIP(c *C) {
cleanup := s.srv.Service.Nova.RegisterControlPoint(
"addFloatingIP",
func(sc hook.ServiceControl, args ...interface{}) error {
return fmt.Errorf("add floating IP should not have been called")
},
)
defer cleanup()
cleanup = s.srv.Service.Nova.RegisterControlPoint(
"addServerFloatingIP",
func(sc hook.ServiceControl, args ...interface{}) error {
return fmt.Errorf("add server floating IP should not have been called")
},
)
defer cleanup()
cfg, err := s.Env.Config().Apply(map[string]interface{}{
"use-floating-ip": false,
})
c.Assert(err, IsNil)
env, err := environs.New(cfg)
c.Assert(err, IsNil)
err = environs.Bootstrap(env, constraints.Value{})
c.Assert(err, IsNil)
inst, _ := testing.StartInstance(c, env, "100")
err = s.Env.StopInstances([]instance.Instance{inst})
c.Assert(err, IsNil)
}
示例8: TestBootstrapFuncKeyGeneration
func (s *bootstrapSuite) TestBootstrapFuncKeyGeneration(c *C) {
env := newEnviron("foo", nil, nil)
var savedCert, savedKey []byte
err := environs.Bootstrap(env, false, func(name string, cert, key []byte) error {
savedCert = cert
savedKey = key
return nil
})
c.Assert(err, IsNil)
c.Assert(env.bootstrapCount, Equals, 1)
_, _, err = cert.ParseCertAndKey(env.certPEM, env.keyPEM)
c.Assert(err, IsNil)
// Check that the cert and key have been set correctly in the configuration
cfgCertPEM, cfgCertOK := env.cfg.CACert()
cfgKeyPEM, cfgKeyOK := env.cfg.CAPrivateKey()
c.Assert(cfgCertOK, Equals, true)
c.Assert(cfgKeyOK, Equals, true)
c.Assert(cfgCertPEM, DeepEquals, savedCert)
c.Assert(cfgKeyPEM, DeepEquals, savedKey)
caCert, _, err := cert.ParseCertAndKey(cfgCertPEM, cfgKeyPEM)
c.Assert(err, IsNil)
c.Assert(caCert.Subject.CommonName, Equals, `juju-generated CA for environment foo`)
verifyCert(c, env.certPEM, cfgCertPEM)
}
示例9: 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)
}
示例10: TestBootstrapKeyGeneration
func (s *bootstrapSuite) TestBootstrapKeyGeneration(c *C) {
env := newEnviron("foo", nil, nil)
err := environs.Bootstrap(env, false, nil)
c.Assert(err, IsNil)
c.Assert(env.bootstrapCount, Equals, 1)
_, _, err = cert.ParseCertAndKey(env.certPEM, env.keyPEM)
c.Assert(err, IsNil)
// Check that the generated CA key has been written correctly.
caCertPEM, err := ioutil.ReadFile(filepath.Join(os.Getenv("HOME"), ".juju", "foo-cert.pem"))
c.Assert(err, IsNil)
caKeyPEM, err := ioutil.ReadFile(filepath.Join(os.Getenv("HOME"), ".juju", "foo-private-key.pem"))
c.Assert(err, IsNil)
// Check that the cert and key have been set correctly in the configuration
cfgCertPEM, cfgCertOK := env.cfg.CACert()
cfgKeyPEM, cfgKeyOK := env.cfg.CAPrivateKey()
c.Assert(cfgCertOK, Equals, true)
c.Assert(cfgKeyOK, Equals, true)
c.Assert(cfgCertPEM, DeepEquals, caCertPEM)
c.Assert(cfgKeyPEM, DeepEquals, caKeyPEM)
caCert, _, err := cert.ParseCertAndKey(cfgCertPEM, cfgKeyPEM)
c.Assert(err, IsNil)
c.Assert(caCert.Subject.CommonName, Equals, `juju-generated CA for environment foo`)
verifyCert(c, env.certPEM, caCertPEM)
}
示例11: TestBootstrapSpecifiedConstraints
func (s *bootstrapSuite) TestBootstrapSpecifiedConstraints(c *gc.C) {
env := newEnviron("foo", useDefaultKeys)
cons := constraints.MustParse("cpu-cores=2 mem=4G")
err := environs.Bootstrap(env, cons)
c.Assert(err, gc.IsNil)
c.Assert(env.bootstrapCount, gc.Equals, 1)
c.Assert(env.constraints, gc.DeepEquals, cons)
}
示例12: TestBootstrapExistingKey
func (s *bootstrapSuite) TestBootstrapExistingKey(c *C) {
env := newEnviron("foo", []byte(testing.CACert), []byte(testing.CAKey))
err := environs.Bootstrap(env, false, panicWrite)
c.Assert(err, IsNil)
c.Assert(env.bootstrapCount, Equals, 1)
verifyCert(c, env.certPEM, []byte(testing.CACert))
}
示例13: BootstrapOnce
func (t *LiveTests) BootstrapOnce(c *C) {
if t.bootstrapped {
return
}
err := environs.Bootstrap(t.Env, true, panicWrite)
c.Assert(err, IsNil)
t.bootstrapped = true
}
示例14: TestBootstrapWithoutAdminSecret
func (t *Tests) TestBootstrapWithoutAdminSecret(c *C) {
m := t.Env.Config().AllAttrs()
delete(m, "admin-secret")
env, err := environs.NewFromAttrs(m)
c.Assert(err, IsNil)
err = environs.Bootstrap(env, false, panicWrite)
c.Assert(err, ErrorMatches, ".*admin-secret is required for bootstrap")
}
示例15: TestStartInstanceHardwareCharacteristics
func (s *localServerSuite) TestStartInstanceHardwareCharacteristics(c *C) {
err := environs.Bootstrap(s.Env, constraints.Value{})
c.Assert(err, IsNil)
_, hc := testing.StartInstanceWithConstraints(c, s.Env, "100", constraints.MustParse("mem=1024"))
c.Check(*hc.Arch, Equals, "amd64")
c.Check(*hc.Mem, Equals, uint64(2048))
c.Check(*hc.CpuCores, Equals, uint64(1))
c.Assert(hc.CpuPower, IsNil)
}