当前位置: 首页>>代码示例>>Golang>>正文


Golang agent.NewStateMachineConfig函数代码示例

本文整理汇总了Golang中github.com/juju/juju/agent.NewStateMachineConfig函数的典型用法代码示例。如果您正苦于以下问题:Golang NewStateMachineConfig函数的具体用法?Golang NewStateMachineConfig怎么用?Golang NewStateMachineConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewStateMachineConfig函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: AgentConfig

func (cfg *InstanceConfig) AgentConfig(
	tag names.Tag,
	toolsVersion version.Number,
) (agent.ConfigSetter, error) {
	// TODO for HAState: the stateHostAddrs and apiHostAddrs here assume that
	// if the instance is a stateServer then to use localhost.  This may be
	// sufficient, but needs thought in the new world order.
	var password string
	if cfg.MongoInfo == nil {
		password = cfg.APIInfo.Password
	} else {
		password = cfg.MongoInfo.Password
	}
	configParams := agent.AgentConfigParams{
		DataDir:           cfg.DataDir,
		LogDir:            cfg.LogDir,
		Jobs:              cfg.Jobs,
		Tag:               tag,
		UpgradedToVersion: toolsVersion,
		Password:          password,
		Nonce:             cfg.MachineNonce,
		StateAddresses:    cfg.stateHostAddrs(),
		APIAddresses:      cfg.ApiHostAddrs(),
		CACert:            cfg.MongoInfo.CACert,
		Values:            cfg.AgentEnvironment,
		PreferIPv6:        cfg.PreferIPv6,
		Environment:       cfg.APIInfo.EnvironTag,
	}
	if !cfg.Bootstrap {
		return agent.NewAgentConfig(configParams)
	}
	return agent.NewStateMachineConfig(configParams, *cfg.StateServingInfo)
}
开发者ID:Pankov404,项目名称:juju,代码行数:33,代码来源:instancecfg.go

示例2: writeStateAgentConfig

// writeStateAgentConfig creates and writes a state agent config.
func writeStateAgentConfig(
	c *gc.C, stateInfo *mongo.MongoInfo, dataDir string, tag names.Tag,
	password string, vers version.Binary, envTag names.EnvironTag) agent.ConfigSetterWriter {
	port := gitjujutesting.FindTCPPort()
	apiAddr := []string{fmt.Sprintf("localhost:%d", port)}
	conf, err := agent.NewStateMachineConfig(
		agent.AgentConfigParams{
			Paths:             agent.NewPathsWithDefaults(agent.Paths{DataDir: dataDir}),
			Tag:               tag,
			UpgradedToVersion: vers.Number,
			Password:          password,
			Nonce:             agent.BootstrapNonce,
			StateAddresses:    stateInfo.Addrs,
			APIAddresses:      apiAddr,
			CACert:            stateInfo.CACert,
			Environment:       envTag,
		},
		params.StateServingInfo{
			Cert:         coretesting.ServerCert,
			PrivateKey:   coretesting.ServerKey,
			CAPrivateKey: coretesting.CAKey,
			StatePort:    gitjujutesting.MgoServer.Port(),
			APIPort:      port,
		})
	c.Assert(err, jc.ErrorIsNil)
	conf.SetPassword(password)
	c.Assert(conf.Write(), gc.IsNil)
	return conf
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:30,代码来源:agent_test.go

示例3: TestAPIInfoAddsLocalhostWhenServingInfoPresentAndPreferIPv6On

func (*suite) TestAPIInfoAddsLocalhostWhenServingInfoPresentAndPreferIPv6On(c *gc.C) {
	attrParams := attributeParams
	attrParams.PreferIPv6 = true
	servingInfo := params.StateServingInfo{
		Cert:           "old cert",
		PrivateKey:     "old key",
		StatePort:      69,
		APIPort:        1492,
		SharedSecret:   "shared",
		SystemIdentity: "identity",
	}
	conf, err := agent.NewStateMachineConfig(attrParams, servingInfo)
	c.Assert(err, gc.IsNil)
	apiinfo := conf.APIInfo()
	c.Check(apiinfo.Addrs, gc.HasLen, len(attrParams.APIAddresses)+1)
	localhostAddressFound := false
	for _, eachApiAddress := range apiinfo.Addrs {
		if eachApiAddress == "[::1]:1492" {
			localhostAddressFound = true
			break
		}
		c.Check(eachApiAddress, gc.Not(gc.Equals), "localhost:1492")
	}
	c.Assert(localhostAddressFound, jc.IsTrue)
}
开发者ID:kapilt,项目名称:juju,代码行数:25,代码来源:agent_test.go

示例4: createFakeAgentConf

func (s *UpgradeMongoCommandSuite) createFakeAgentConf(c *gc.C, agentDir string, mongoVersion mongo.Version) {
	attributeParams := agent.AgentConfigParams{
		Paths: agent.Paths{
			DataDir: agentDir,
		},
		Tag:               names.NewMachineTag("0"),
		UpgradedToVersion: jujuversion.Current,
		Password:          "sekrit",
		CACert:            "ca cert",
		StateAddresses:    []string{"localhost:1234"},
		APIAddresses:      []string{"localhost:1235"},
		Nonce:             "a nonce",
		Controller:        testing.ControllerTag,
		Model:             testing.ModelTag,
	}

	servingInfo := params.StateServingInfo{
		Cert:           "cert",
		PrivateKey:     "key",
		CAPrivateKey:   "ca key",
		StatePort:      69,
		APIPort:        47,
		SharedSecret:   "shared",
		SystemIdentity: "identity",
	}
	conf, err := agent.NewStateMachineConfig(attributeParams, servingInfo)
	c.Check(err, jc.ErrorIsNil)
	conf.SetMongoVersion(mongoVersion)
	err = conf.Write()
	c.Check(err, jc.ErrorIsNil)
}
开发者ID:kat-co,项目名称:juju,代码行数:31,代码来源:upgrade_mongo_test.go

示例5: TestStateServingInfo

func (*suite) TestStateServingInfo(c *gc.C) {
	servingInfo := params.StateServingInfo{
		Cert:           "old cert",
		PrivateKey:     "old key",
		StatePort:      69,
		APIPort:        47,
		SharedSecret:   "shared",
		SystemIdentity: "identity",
	}
	conf, err := agent.NewStateMachineConfig(attributeParams, servingInfo)
	c.Assert(err, gc.IsNil)
	gotInfo, ok := conf.StateServingInfo()
	c.Assert(ok, jc.IsTrue)
	c.Assert(gotInfo, jc.DeepEquals, servingInfo)
	newInfo := params.StateServingInfo{
		APIPort:        147,
		StatePort:      169,
		Cert:           "new cert",
		PrivateKey:     "new key",
		SharedSecret:   "new shared",
		SystemIdentity: "new identity",
	}
	conf.SetStateServingInfo(newInfo)
	gotInfo, ok = conf.StateServingInfo()
	c.Assert(ok, jc.IsTrue)
	c.Assert(gotInfo, jc.DeepEquals, newInfo)
}
开发者ID:rogpeppe,项目名称:juju,代码行数:27,代码来源:agent_test.go

示例6: TestNewStateMachineConfig

func (*suite) TestNewStateMachineConfig(c *gc.C) {
	type testStruct struct {
		about         string
		params        agent.AgentConfigParams
		servingInfo   params.StateServingInfo
		checkErr      string
		inspectConfig func(*gc.C, agent.Config)
	}
	var tests = []testStruct{{
		about:    "missing state server cert",
		checkErr: "state server cert not found in configuration",
	}, {
		about: "missing state server key",
		servingInfo: params.StateServingInfo{
			Cert: "server cert",
		},
		checkErr: "state server key not found in configuration",
	}, {
		about: "missing state port",
		servingInfo: params.StateServingInfo{
			Cert:       "server cert",
			PrivateKey: "server key",
		},
		checkErr: "state port not found in configuration",
	}, {
		about: "params api port",
		servingInfo: params.StateServingInfo{
			Cert:       "server cert",
			PrivateKey: "server key",
			StatePort:  69,
		},
		checkErr: "api port not found in configuration",
	}}
	for _, test := range agentConfigTests {
		tests = append(tests, testStruct{
			about:  test.about,
			params: test.params,
			servingInfo: params.StateServingInfo{
				Cert:       "server cert",
				PrivateKey: "server key",
				StatePort:  3171,
				APIPort:    300,
			},
			checkErr: test.checkErr,
		})
	}

	for i, test := range tests {
		c.Logf("%v: %s", i, test.about)
		cfg, err := agent.NewStateMachineConfig(test.params, test.servingInfo)
		if test.checkErr == "" {
			c.Assert(err, gc.IsNil)
			if test.inspectConfig != nil {
				test.inspectConfig(c, cfg)
			}
		} else {
			c.Assert(err, gc.ErrorMatches, test.checkErr)
		}
	}
}
开发者ID:rogpeppe,项目名称:juju,代码行数:60,代码来源:agent_test.go

示例7: WriteStateAgentConfig

// WriteStateAgentConfig creates and writes a state agent config.
func (s *AgentSuite) WriteStateAgentConfig(
	c *gc.C,
	tag names.Tag,
	password string,
	vers version.Binary,
	modelTag names.ModelTag,
) agent.ConfigSetterWriter {
	stateInfo := s.State.MongoConnectionInfo()
	apiPort := gitjujutesting.FindTCPPort()
	apiAddr := []string{fmt.Sprintf("localhost:%d", apiPort)}
	conf, err := agent.NewStateMachineConfig(
		agent.AgentConfigParams{
			Paths:             agent.NewPathsWithDefaults(agent.Paths{DataDir: s.DataDir()}),
			Tag:               tag,
			UpgradedToVersion: vers.Number,
			Password:          password,
			Nonce:             agent.BootstrapNonce,
			StateAddresses:    stateInfo.Addrs,
			APIAddresses:      apiAddr,
			CACert:            stateInfo.CACert,
			Model:             modelTag,
		},
		params.StateServingInfo{
			Cert:         coretesting.ServerCert,
			PrivateKey:   coretesting.ServerKey,
			CAPrivateKey: coretesting.CAKey,
			StatePort:    gitjujutesting.MgoServer.Port(),
			APIPort:      apiPort,
		})
	c.Assert(err, jc.ErrorIsNil)
	conf.SetPassword(password)
	c.Assert(conf.Write(), gc.IsNil)
	return conf
}
开发者ID:pmatulis,项目名称:juju,代码行数:35,代码来源:agent.go

示例8: writeStateAgentConfig

// writeStateAgentConfig creates and writes a state agent config.
func writeStateAgentConfig(c *gc.C, stateInfo *state.Info, dataDir, tag, password string, vers version.Binary) agent.ConfigSetterWriter {
	port := gitjujutesting.FindTCPPort()
	apiAddr := []string{fmt.Sprintf("localhost:%d", port)}
	conf, err := agent.NewStateMachineConfig(
		agent.AgentConfigParams{
			DataDir:           dataDir,
			Tag:               tag,
			UpgradedToVersion: vers.Number,
			Password:          password,
			Nonce:             state.BootstrapNonce,
			StateAddresses:    stateInfo.Addrs,
			APIAddresses:      apiAddr,
			CACert:            stateInfo.CACert,
		},
		params.StateServingInfo{
			Cert:       coretesting.ServerCert,
			PrivateKey: coretesting.ServerKey,
			StatePort:  gitjujutesting.MgoServer.Port(),
			APIPort:    port,
		})
	c.Assert(err, gc.IsNil)
	conf.SetPassword(password)
	c.Assert(conf.Write(), gc.IsNil)
	return conf
}
开发者ID:rogpeppe,项目名称:juju,代码行数:26,代码来源:agent_test.go

示例9: TestMongoInfoHonorsPreferIPv6

func (*suite) TestMongoInfoHonorsPreferIPv6(c *gc.C) {
	attrParams := attributeParams
	attrParams.PreferIPv6 = true
	servingInfo := stateServingInfo()
	conf, err := agent.NewStateMachineConfig(attrParams, servingInfo)
	c.Assert(err, jc.ErrorIsNil)
	mongoInfo, ok := conf.MongoInfo()
	c.Assert(ok, jc.IsTrue)
	c.Check(mongoInfo.Info.Addrs, jc.DeepEquals, []string{"[::1]:69"})

	attrParams.PreferIPv6 = false
	conf, err = agent.NewStateMachineConfig(attrParams, servingInfo)
	c.Assert(err, jc.ErrorIsNil)
	mongoInfo, ok = conf.MongoInfo()
	c.Assert(ok, jc.IsTrue)
	c.Check(mongoInfo.Info.Addrs, jc.DeepEquals, []string{"127.0.0.1:69"})
}
开发者ID:exekias,项目名称:juju,代码行数:17,代码来源:agent_test.go

示例10: TestMongoInfoHonorsPreferIPv6

func (*suite) TestMongoInfoHonorsPreferIPv6(c *gc.C) {
	attrParams := attributeParams
	attrParams.PreferIPv6 = true
	servingInfo := params.StateServingInfo{
		Cert:           "old cert",
		PrivateKey:     "old key",
		StatePort:      69,
		APIPort:        1492,
		SharedSecret:   "shared",
		SystemIdentity: "identity",
	}
	conf, err := agent.NewStateMachineConfig(attrParams, servingInfo)
	c.Assert(err, gc.IsNil)
	mongoInfo, ok := conf.MongoInfo()
	c.Assert(ok, jc.IsTrue)
	c.Check(mongoInfo.Info.Addrs, jc.DeepEquals, []string{"[::1]:69"})

	attrParams.PreferIPv6 = false
	conf, err = agent.NewStateMachineConfig(attrParams, servingInfo)
	c.Assert(err, gc.IsNil)
	mongoInfo, ok = conf.MongoInfo()
	c.Assert(ok, jc.IsTrue)
	c.Check(mongoInfo.Info.Addrs, jc.DeepEquals, []string{"127.0.0.1:69"})
}
开发者ID:kapilt,项目名称:juju,代码行数:24,代码来源:agent_test.go

示例11: TestNewDialInfo

func (r *RestoreSuite) TestNewDialInfo(c *gc.C) {
	machineTag, err := names.ParseTag("machine-0")
	c.Assert(err, jc.ErrorIsNil)

	dataDir := path.Join(r.cwd, "dataDir")
	err = os.Mkdir(dataDir, os.FileMode(0755))
	c.Assert(err, jc.ErrorIsNil)

	logDir := path.Join(r.cwd, "logDir")
	err = os.Mkdir(logDir, os.FileMode(0755))
	c.Assert(err, jc.ErrorIsNil)

	configParams := agent.AgentConfigParams{
		Paths: agent.Paths{
			DataDir: dataDir,
			LogDir:  logDir,
		},
		UpgradedToVersion: version.Current.Number,
		Tag:               machineTag,
		Environment:       coretesting.EnvironmentTag,
		Password:          "dummyPassword",
		Nonce:             "dummyNonce",
		StateAddresses:    []string{"fakeStateAddress:1234"},
		APIAddresses:      []string{"fakeAPIAddress:12345"},
		CACert:            caCertPEM,
	}
	statePort := 12345
	privateAddress := "dummyPrivateAddress"
	servingInfo := params.StateServingInfo{
		APIPort:        1234,
		StatePort:      statePort,
		Cert:           caCertPEM,
		CAPrivateKey:   "a ca key",
		PrivateKey:     "a key",
		SharedSecret:   "a secret",
		SystemIdentity: "an identity",
	}

	conf, err := agent.NewStateMachineConfig(configParams, servingInfo)
	c.Assert(err, jc.ErrorIsNil)

	dialInfo, err := newDialInfo(privateAddress, conf)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(dialInfo.Username, gc.Equals, "admin")
	c.Assert(dialInfo.Password, gc.Equals, "dummyPassword")
	c.Assert(dialInfo.Direct, gc.Equals, true)
	c.Assert(dialInfo.Addrs, gc.DeepEquals, []string{fmt.Sprintf("%s:%d", privateAddress, statePort)})
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:48,代码来源:restore_test.go

示例12: initBootstrapCommand

func (s *BootstrapSuite) initBootstrapCommand(c *gc.C, jobs []multiwatcher.MachineJob, args ...string) (machineConf agent.ConfigSetterWriter, cmd *BootstrapCommand, err error) {
	if len(jobs) == 0 {
		// Add default jobs.
		jobs = []multiwatcher.MachineJob{
			multiwatcher.JobManageEnviron,
			multiwatcher.JobHostUnits,
			multiwatcher.JobManageNetworking,
		}
	}
	// NOTE: the old test used an equivalent of the NewAgentConfig, but it
	// really should be using NewStateMachineConfig.
	agentParams := agent.AgentConfigParams{
		Paths: agent.Paths{
			LogDir:  s.logDir,
			DataDir: s.dataDir,
		},
		Jobs:              jobs,
		Tag:               names.NewMachineTag("0"),
		UpgradedToVersion: version.Current.Number,
		Password:          testPasswordHash(),
		Nonce:             agent.BootstrapNonce,
		Environment:       testing.EnvironmentTag,
		StateAddresses:    []string{gitjujutesting.MgoServer.Addr()},
		APIAddresses:      []string{"0.1.2.3:1234"},
		CACert:            testing.CACert,
		Values: map[string]string{
			agent.Namespace:      "foobar",
			agent.MongoOplogSize: s.mongoOplogSize,
		},
	}
	servingInfo := params.StateServingInfo{
		Cert:         "some cert",
		PrivateKey:   "some key",
		CAPrivateKey: "another key",
		APIPort:      3737,
		StatePort:    gitjujutesting.MgoServer.Port(),
	}

	machineConf, err = agent.NewStateMachineConfig(agentParams, servingInfo)
	c.Assert(err, jc.ErrorIsNil)
	err = machineConf.Write()
	c.Assert(err, jc.ErrorIsNil)

	cmd = NewBootstrapCommand()

	err = testing.InitCommand(cmd, append([]string{"--data-dir", s.dataDir}, args...))
	return machineConf, cmd, err
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:48,代码来源:bootstrap_test.go

示例13: TestAPIInfoAddsLocalhostWhenServingInfoPresent

func (*suite) TestAPIInfoAddsLocalhostWhenServingInfoPresent(c *gc.C) {
	attrParams := attributeParams
	servingInfo := stateServingInfo()
	conf, err := agent.NewStateMachineConfig(attrParams, servingInfo)
	c.Assert(err, jc.ErrorIsNil)
	apiinfo := conf.APIInfo()
	c.Check(apiinfo.Addrs, gc.HasLen, len(attrParams.APIAddresses)+1)
	localhostAddressFound := false
	for _, eachApiAddress := range apiinfo.Addrs {
		if eachApiAddress == "localhost:47" {
			localhostAddressFound = true
			break
		}
	}
	c.Assert(localhostAddressFound, jc.IsTrue)
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:16,代码来源:agent_test.go

示例14: TestSetPassword

func (*suite) TestSetPassword(c *gc.C) {
	attrParams := attributeParams
	servingInfo := params.StateServingInfo{
		Cert:           "old cert",
		PrivateKey:     "old key",
		StatePort:      1234,
		APIPort:        1235,
		SharedSecret:   "shared",
		SystemIdentity: "identity",
	}
	conf, err := agent.NewStateMachineConfig(attrParams, servingInfo)
	c.Assert(err, gc.IsNil)

	expectAPIInfo := &api.Info{
		Addrs:    attrParams.APIAddresses,
		CACert:   attrParams.CACert,
		Tag:      attrParams.Tag,
		Password: "",
		Nonce:    attrParams.Nonce,
	}
	c.Assert(conf.APIInfo(), jc.DeepEquals, expectAPIInfo)
	addr := fmt.Sprintf("127.0.0.1:%d", servingInfo.StatePort)
	expectStateInfo := &state.Info{
		Info: mongo.Info{
			Addrs:  []string{addr},
			CACert: attrParams.CACert,
		},
		Tag:      attrParams.Tag,
		Password: "",
	}
	info, ok := conf.StateInfo()
	c.Assert(ok, jc.IsTrue)
	c.Assert(info, jc.DeepEquals, expectStateInfo)

	conf.SetPassword("newpassword")

	expectAPIInfo.Password = "newpassword"
	expectStateInfo.Password = "newpassword"

	c.Assert(conf.APIInfo(), jc.DeepEquals, expectAPIInfo)
	info, ok = conf.StateInfo()
	c.Assert(ok, jc.IsTrue)
	c.Assert(info, jc.DeepEquals, expectStateInfo)
}
开发者ID:rogpeppe,项目名称:juju,代码行数:44,代码来源:agent_test.go

示例15: TestSetPassword

func (*suite) TestSetPassword(c *gc.C) {
	attrParams := attributeParams
	servingInfo := stateServingInfo()
	servingInfo.APIPort = 1235
	conf, err := agent.NewStateMachineConfig(attrParams, servingInfo)
	c.Assert(err, jc.ErrorIsNil)

	expectAPIInfo := &api.Info{
		Addrs:    attrParams.APIAddresses,
		CACert:   attrParams.CACert,
		Tag:      attrParams.Tag,
		Password: "",
		Nonce:    attrParams.Nonce,
		ModelTag: attrParams.Model,
	}
	apiInfo, ok := conf.APIInfo()
	c.Assert(ok, jc.IsTrue)
	c.Assert(apiInfo, jc.DeepEquals, expectAPIInfo)
	addr := fmt.Sprintf("127.0.0.1:%d", servingInfo.StatePort)
	expectStateInfo := &mongo.MongoInfo{
		Info: mongo.Info{
			Addrs:  []string{addr},
			CACert: attrParams.CACert,
		},
		Tag:      attrParams.Tag,
		Password: "",
	}
	info, ok := conf.MongoInfo()
	c.Assert(ok, jc.IsTrue)
	c.Assert(info, jc.DeepEquals, expectStateInfo)

	conf.SetPassword("newpassword")

	expectAPIInfo.Password = "newpassword"
	expectStateInfo.Password = "newpassword"

	apiInfo, ok = conf.APIInfo()
	c.Assert(ok, jc.IsTrue)
	c.Assert(apiInfo, jc.DeepEquals, expectAPIInfo)
	info, ok = conf.MongoInfo()
	c.Assert(ok, jc.IsTrue)
	c.Assert(info, jc.DeepEquals, expectStateInfo)
}
开发者ID:exekias,项目名称:juju,代码行数:43,代码来源:agent_test.go


注:本文中的github.com/juju/juju/agent.NewStateMachineConfig函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。