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


Golang Conf.APIInfo方法代码示例

本文整理汇总了Golang中launchpad/net/juju-core/agent.Conf.APIInfo方法的典型用法代码示例。如果您正苦于以下问题:Golang Conf.APIInfo方法的具体用法?Golang Conf.APIInfo怎么用?Golang Conf.APIInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在launchpad/net/juju-core/agent.Conf的用法示例。


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

示例1: EnsureAPIInfo

// EnsureAPIInfo makes sure we can connect as an agent to the API server 1.10
// did not set an API password for machine agents, 1.11 sets it the same as the
// mongo password.  1.10 also does not set any API Info at all for Unit agents.
// conf is the agent.conf for this machine/unit agent.  agentConn is the direct
// connection to the State database
func EnsureAPIInfo(conf *agent.Conf, stConn *state.State, agentConn AgentState) error {
	// In 1.10 Machine Agents will have an API Info section, but will not
	// have properly configured the Password field, so when upgrading to
	// 1.11 we must set that field
	// In 1.10 Unit Agents will not have an API Info section at all, so we
	// must set everything from the StateInfo (correcting the Addrs for API
	// port vs Mongo port)
	// A new 1.11 Unit Agent will have an OldPassword but no Password set
	// (in StateInfo or APIInfo). Because we only change the password on
	// API connect, not on DB connect. We don't want to make extra
	// SetPassword calls when we already have a valid password set
	if conf.APIInfo != nil && (conf.APIInfo.Password != "" || conf.StateInfo.Password == "") {
		// We must have set it earlier
		return nil
	}
	setter, ok := agentConn.(passwordSetter)
	if !ok {
		panic("AgentState is missing a SetPassword method?")
	}
	if conf.APIInfo == nil {
		// Unit agents didn't get any APIInfo in 1.10
		conf.APIInfo = apiInfoFromStateInfo(conf.StateInfo, stConn)
		validationLogger.Infof(
			"agent.conf APIInfo is not set. Setting to {Addrs: %s, Tag: %s}",
			conf.APIInfo.Addrs,
			conf.APIInfo.Tag,
		)
	} else {
		validationLogger.Infof("agent.conf APIInfo password is not set. Setting to state password")
		conf.APIInfo.Password = conf.StateInfo.Password
	}
	password := conf.StateInfo.Password
	if password == "" {
		// In 1.11 we don't set a new password on connect (because it is
		// done in the API code, and we don't have any API workers).
		// We want to make sure the API user has the correct password
		// (OldPassword). We *don't* want to set APIInfo.Password
		// because then when we do connect via the API we wouldn't
		// change the password. So this is only used for SetPassword
		validationLogger.Infof(
			"agent.conf StateInfo password is \"\". Setting Agent password for %s to OldPassword",
			conf.APIInfo.Tag)
		password = conf.OldPassword
	}
	// We set the actual password before writing it to disk, because
	// otherwise we would not set it correctly in the future
	if err := setter.SetPassword(password); err != nil {
		return err
	}
	if err := conf.Write(); err != nil {
		return err
	}
	return nil
}
开发者ID:rif,项目名称:golang-stuff,代码行数:59,代码来源:upgradevalidation.go


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