當前位置: 首頁>>代碼示例>>Golang>>正文


Golang environs.NewFromAttrs函數代碼示例

本文整理匯總了Golang中launchpad/net/juju-core/environs.NewFromAttrs函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewFromAttrs函數的具體用法?Golang NewFromAttrs怎麽用?Golang NewFromAttrs使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewFromAttrs函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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, &current.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)
}
開發者ID:prabhakhar,項目名稱:juju-core,代碼行數:60,代碼來源:livetests.go

示例2: SetUpSuite

func (t *LiveTests) SetUpSuite(c *C) {
	t.LoggingSuite.SetUpSuite(c)
	// Get an authenticated Goose client to extract some configuration parameters for the test environment.
	cred, err := identity.CompleteCredentialsFromEnv()
	c.Assert(err, IsNil)
	client := client.NewClient(cred, identity.AuthUserPass, nil)
	err = client.Authenticate()
	c.Assert(err, IsNil)
	publicBucketURL, err := client.MakeServiceURL("object-store", nil)
	c.Assert(err, IsNil)
	attrs := makeTestConfig()
	attrs["public-bucket-url"] = publicBucketURL
	t.Config = attrs
	e, err := environs.NewFromAttrs(t.Config)
	c.Assert(err, IsNil)

	// Environ.PublicStorage() is read only.
	// For testing, we create a specific storage instance which is authorised to write to
	// the public storage bucket so that we can upload files for testing.
	t.writeablePublicStorage = openstack.WritablePublicStorage(e)
	// Put some fake tools in place so that tests that are simply
	// starting instances without any need to check if those instances
	// are running will find them in the public bucket.
	putFakeTools(c, t.writeablePublicStorage)
	t.LiveTests.SetUpSuite(c)
}
開發者ID:prabhakhar,項目名稱:juju-core,代碼行數:26,代碼來源:live_test.go

示例3: SetUpSuite

func (t *LiveTests) SetUpSuite(c *C) {
	t.LoggingSuite.SetUpSuite(c)
	e, err := environs.NewFromAttrs(t.TestConfig.Config)
	c.Assert(err, IsNil, Commentf("opening environ %#v", t.TestConfig.Config))
	c.Assert(e, NotNil)
	t.Env = e
	c.Logf("environment configuration: %#v", publicAttrs(e))
}
開發者ID:CSRedRat,項目名稱:juju-core,代碼行數:8,代碼來源:livetests.go

示例4: 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")
}
開發者ID:prabhakhar,項目名稱:juju-core,代碼行數:8,代碼來源:tests.go

示例5: TestPublicBucketFromEnv

func (s *publicBucketSuite) TestPublicBucketFromEnv(c *C) {
	config := makeTestConfig(s.cred)
	config["public-bucket-url"] = "http://127.0.0.1/public-bucket"
	var err error
	s.env, err = environs.NewFromAttrs(config)
	c.Assert(err, IsNil)
	url, err := s.env.PublicStorage().URL("")
	c.Assert(err, IsNil)
	c.Assert(url, Equals, "http://127.0.0.1/public-bucket/juju-dist/")
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:10,代碼來源:local_test.go

示例6: TestNewUnknownEnviron

func (OpenSuite) TestNewUnknownEnviron(c *C) {
	env, err := environs.NewFromAttrs(map[string]interface{}{
		"name":            "foo",
		"type":            "wondercloud",
		"authorized-keys": "i-am-a-key",
		"ca-cert":         testing.CACert,
		"ca-private-key":  "",
	})
	c.Assert(err, ErrorMatches, "no registered provider for.*")
	c.Assert(env, IsNil)
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:11,代碼來源:open_test.go

示例7: TestPublicBucketFromKeystone

func (s *publicBucketSuite) TestPublicBucketFromKeystone(c *C) {
	config := makeTestConfig(s.cred)
	config["public-bucket-url"] = ""
	var err error
	s.env, err = environs.NewFromAttrs(config)
	c.Assert(err, IsNil)
	url, err := s.env.PublicStorage().URL("")
	c.Assert(err, IsNil)
	swiftURL, err := openstack.GetSwiftURL(s.env)
	c.Assert(err, IsNil)
	c.Assert(url, Equals, fmt.Sprintf("%s/juju-dist/", swiftURL))
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:12,代碼來源:local_test.go

示例8: setupEnv

func (s *ConfigDeprecationSuite) setupEnv(c *gc.C, deprecatedKey, value string) {
	s.setupEnvCredentials()
	attrs := map[string]interface{}{
		"name":            "testenv",
		"type":            "openstack",
		"control-bucket":  "x",
		"authorized-keys": "fakekey",
		deprecatedKey:     value,
	}
	_, err := environs.NewFromAttrs(attrs)
	c.Assert(err, gc.IsNil)
}
開發者ID:rif,項目名稱:golang-stuff,代碼行數:12,代碼來源:config_test.go

示例9: TestConnStateDoesNotUpdateExistingSecrets

func (cs *NewConnSuite) TestConnStateDoesNotUpdateExistingSecrets(c *C) {
	attrs := map[string]interface{}{
		"name":            "erewhemos",
		"type":            "dummy",
		"state-server":    true,
		"authorized-keys": "i-am-a-key",
		"secret":          "pork",
		"admin-secret":    "some secret",
		"ca-cert":         coretesting.CACert,
		"ca-private-key":  coretesting.CAKey,
	}
	env, err := environs.NewFromAttrs(attrs)
	c.Assert(err, IsNil)
	err = environs.Bootstrap(env, constraints.Value{})
	c.Assert(err, IsNil)

	// Make a new Conn, which will push the secrets.
	conn, err := juju.NewConn(env)
	c.Assert(err, IsNil)
	defer conn.Close()

	// Make another env with a different secret.
	attrs["secret"] = "squirrel"
	env1, err := environs.NewFromAttrs(attrs)
	c.Assert(err, IsNil)

	// Connect with the new env and check that the secret has not changed
	conn, err = juju.NewConn(env1)
	c.Assert(err, IsNil)
	defer conn.Close()
	cfg, err := conn.State.EnvironConfig()
	c.Assert(err, IsNil)
	c.Assert(cfg.UnknownAttrs()["secret"], Equals, "pork")

	// Reset the admin password so the state db can be reused.
	err = conn.State.SetAdminMongoPassword("")
	c.Assert(err, IsNil)
}
開發者ID:rif,項目名稱:golang-stuff,代碼行數:38,代碼來源:conn_test.go

示例10: SetUpTest

func (t *MongoToolsSuite) SetUpTest(c *C) {
	t.LoggingSuite.SetUpTest(c)
	env, err := environs.NewFromAttrs(map[string]interface{}{
		"name":            "test",
		"type":            "dummy",
		"state-server":    false,
		"authorized-keys": "i-am-a-key",
		"ca-cert":         testing.CACert,
		"ca-private-key":  "",
	})
	c.Assert(err, IsNil)
	t.env = env
	t.dataDir = c.MkDir()
}
開發者ID:rif,項目名稱:golang-stuff,代碼行數:14,代碼來源:mongo_test.go

示例11: TestNewConnWithoutAdminSecret

func (*NewConnSuite) TestNewConnWithoutAdminSecret(c *C) {
	attrs := map[string]interface{}{
		"name":            "erewhemos",
		"type":            "dummy",
		"state-server":    true,
		"authorized-keys": "i-am-a-key",
		"secret":          "pork",
		"admin-secret":    "really",
		"ca-cert":         coretesting.CACert,
		"ca-private-key":  coretesting.CAKey,
	}
	env, err := environs.NewFromAttrs(attrs)
	c.Assert(err, IsNil)
	err = environs.Bootstrap(env, constraints.Value{})
	c.Assert(err, IsNil)

	delete(attrs, "admin-secret")
	env1, err := environs.NewFromAttrs(attrs)
	c.Assert(err, IsNil)
	conn, err := juju.NewConn(env1)
	c.Check(conn, IsNil)
	c.Assert(err, ErrorMatches, "cannot connect without admin-secret")
}
開發者ID:rif,項目名稱:golang-stuff,代碼行數:23,代碼來源:conn_test.go

示例12: SetUpTest

func (s *StorageSuite) SetUpTest(c *gc.C) {
	s.LoggingSuite.SetUpTest(c)
	env, err := environs.NewFromAttrs(map[string]interface{}{
		"name":            "test",
		"type":            "dummy",
		"state-server":    false,
		"authorized-keys": "i-am-a-key",
		"ca-cert":         testing.CACert,
		"ca-private-key":  "",
	})
	c.Assert(err, gc.IsNil)
	s.env = env
	s.dataDir = c.MkDir()
}
開發者ID:hivetech,項目名稱:judo.legacy,代碼行數:14,代碼來源:storage_test.go

示例13: TestNewDummyEnviron

func (OpenSuite) TestNewDummyEnviron(c *C) {
	// matches *Settings.Map()
	config := map[string]interface{}{
		"name":            "foo",
		"type":            "dummy",
		"state-server":    false,
		"authorized-keys": "i-am-a-key",
		"admin-secret":    "foo",
		"ca-cert":         testing.CACert,
		"ca-private-key":  "",
	}
	env, err := environs.NewFromAttrs(config)
	c.Assert(err, IsNil)
	c.Assert(env.Bootstrap(constraints.Value{}), IsNil)
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:15,代碼來源:open_test.go

示例14: TestConnWithPassword

func (cs *NewConnSuite) TestConnWithPassword(c *C) {
	env, err := environs.NewFromAttrs(map[string]interface{}{
		"name":            "erewhemos",
		"type":            "dummy",
		"state-server":    true,
		"authorized-keys": "i-am-a-key",
		"secret":          "squirrel",
		"admin-secret":    "nutkin",
		"ca-cert":         coretesting.CACert,
		"ca-private-key":  coretesting.CAKey,
	})
	c.Assert(err, IsNil)
	err = environs.Bootstrap(env, constraints.Value{})
	c.Assert(err, IsNil)

	// Check that Bootstrap has correctly used a hash
	// of the admin password.
	info, _, err := env.StateInfo()
	c.Assert(err, IsNil)
	info.Password = utils.PasswordHash("nutkin")
	st, err := state.Open(info, state.DefaultDialOpts())
	c.Assert(err, IsNil)
	st.Close()

	// Check that we can connect with the original environment.
	conn, err := juju.NewConn(env)
	c.Assert(err, IsNil)
	conn.Close()

	// Check that the password has now been changed to the original
	// admin password.
	info.Password = "nutkin"
	st1, err := state.Open(info, state.DefaultDialOpts())
	c.Assert(err, IsNil)
	st1.Close()

	// Check that we can still connect with the original
	// environment.
	conn, err = juju.NewConn(env)
	c.Assert(err, IsNil)
	defer conn.Close()

	// Reset the admin password so the state db can be reused.
	err = conn.State.SetAdminMongoPassword("")
	c.Assert(err, IsNil)
}
開發者ID:rif,項目名稱:golang-stuff,代碼行數:46,代碼來源:conn_test.go

示例15: Reset

func (s *ToolsSuite) Reset(c *C, attrs map[string]interface{}) {
	version.Current = s.origCurrentVersion
	dummy.Reset()
	final := map[string]interface{}{
		"name":            "test",
		"type":            "dummy",
		"state-server":    false,
		"authorized-keys": "i-am-a-key",
		"ca-cert":         testing.CACert,
		"ca-private-key":  "",
	}
	for k, v := range attrs {
		final[k] = v
	}
	env, err := environs.NewFromAttrs(final)
	c.Assert(err, IsNil)
	s.env = env
	envtesting.RemoveAllTools(c, s.env)
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:19,代碼來源:tools_test.go


注:本文中的launchpad/net/juju-core/environs.NewFromAttrs函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。