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


Golang State.SetEnvironConstraints方法代碼示例

本文整理匯總了Golang中launchpad/net/juju-core/state.State.SetEnvironConstraints方法的典型用法代碼示例。如果您正苦於以下問題:Golang State.SetEnvironConstraints方法的具體用法?Golang State.SetEnvironConstraints怎麽用?Golang State.SetEnvironConstraints使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在launchpad/net/juju-core/state.State的用法示例。


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

示例1: ConfigureBootstrapMachine

// ConfigureBootstrapMachine adds the initial machine into state.  As a part
// of this process the environmental constraints are saved as constraints used
// when bootstrapping are considered constraints for the entire environment.
func ConfigureBootstrapMachine(
	st *state.State,
	cons constraints.Value,
	datadir string,
	jobs []state.MachineJob,
	instId instance.Id,
	characteristics instance.HardwareCharacteristics,
) error {
	logger.Debugf("setting environment constraints")
	if err := st.SetEnvironConstraints(cons); err != nil {
		return err
	}

	logger.Debugf("create bootstrap machine in state")
	m, err := st.InjectMachine(version.Current.Series, cons, instId, characteristics, jobs...)
	if err != nil {
		return err
	}
	// Read the machine agent's password and change it to
	// a new password (other agents will change their password
	// via the API connection).
	logger.Debugf("create new random password for machine %v", m.Id())
	mconf, err := agent.ReadConf(datadir, m.Tag())
	if err != nil {
		return err
	}
	newPassword, err := utils.RandomPassword()
	if err != nil {
		return err
	}
	mconf.StateInfo.Password = newPassword
	mconf.APIInfo.Password = newPassword
	mconf.OldPassword = ""

	if err := mconf.Write(); err != nil {
		return err
	}
	if err := m.SetMongoPassword(newPassword); err != nil {
		return err
	}
	if err := m.SetPassword(newPassword); err != nil {
		return err
	}
	return nil
}
開發者ID:rif,項目名稱:golang-stuff,代碼行數:48,代碼來源:bootstrap.go


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