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