本文整理汇总了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
}