本文整理汇总了Golang中launchpad/net/juju-core/state.Machine.SetProvisioned方法的典型用法代码示例。如果您正苦于以下问题:Golang Machine.SetProvisioned方法的具体用法?Golang Machine.SetProvisioned怎么用?Golang Machine.SetProvisioned使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类launchpad/net/juju-core/state.Machine
的用法示例。
在下文中一共展示了Machine.SetProvisioned方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: startMachine
func (p *Provisioner) startMachine(m *state.Machine) error {
// TODO(dfc) the state.Info passed to environ.StartInstance remains contentious
// however as the PA only knows one state.Info, and that info is used by MAs and
// UAs to locate the state for this environment, it is logical to use the same
// state.Info as the PA.
stateInfo, apiInfo, err := p.setupAuthentication(m)
if err != nil {
return err
}
cons, err := m.Constraints()
if err != nil {
return err
}
// Generate a unique nonce for the new instance.
uuid, err := utils.NewUUID()
if err != nil {
return err
}
// Generated nonce has the format: "machine-#:UUID". The first
// part is a badge, specifying the tag of the machine the provisioner
// is running on, while the second part is a random UUID.
nonce := fmt.Sprintf("%s:%s", state.MachineTag(p.machineId), uuid.String())
inst, err := p.environ.StartInstance(m.Id(), nonce, m.Series(), cons, stateInfo, apiInfo)
if err != nil {
// Set the state to error, so the machine will be skipped next
// time until the error is resolved, but don't return an
// error; just keep going with the other machines.
log.Errorf("worker/provisioner: cannot start instance for machine %q: %v", m, err)
if err1 := m.SetStatus(params.StatusError, err.Error()); err1 != nil {
// Something is wrong with this machine, better report it back.
log.Errorf("worker/provisioner: cannot set error status for machine %q: %v", m, err1)
return err1
}
return nil
}
if err := m.SetProvisioned(inst.Id(), nonce); err != nil {
// The machine is started, but we can't record the mapping in
// state. It'll keep running while we fail out and restart,
// but will then be detected by findUnknownInstances and
// killed again.
//
// TODO(dimitern) Stop the instance right away here.
//
// Multiple instantiations of a given machine (with the same
// machine ID) cannot coexist, because findUnknownInstances is
// called before startMachines. However, if the first machine
// had started to do work before being replaced, we may
// encounter surprising problems.
return err
}
// populate the local cache
p.instances[m.Id()] = inst
p.machines[inst.Id()] = m.Id()
log.Noticef("worker/provisioner: started machine %s as instance %s", m, inst.Id())
return nil
}
示例2: startMachine
func (task *provisionerTask) startMachine(machine *state.Machine) error {
stateInfo, apiInfo, err := task.auth.SetupAuthentication(machine)
if err != nil {
logger.Errorf("failed to setup authentication: %v", err)
return err
}
cons, err := machine.Constraints()
if err != nil {
return err
}
// Generate a unique nonce for the new instance.
uuid, err := utils.NewUUID()
if err != nil {
return err
}
// Generated nonce has the format: "machine-#:UUID". The first
// part is a badge, specifying the tag of the machine the provisioner
// is running on, while the second part is a random UUID.
nonce := fmt.Sprintf("%s:%s", names.MachineTag(task.machineId), uuid.String())
inst, metadata, err := task.broker.StartInstance(machine.Id(), nonce, machine.Series(), cons, stateInfo, apiInfo)
if err != nil {
// Set the state to error, so the machine will be skipped next
// time until the error is resolved, but don't return an
// error; just keep going with the other machines.
logger.Errorf("cannot start instance for machine %q: %v", machine, err)
if err1 := machine.SetStatus(params.StatusError, err.Error()); err1 != nil {
// Something is wrong with this machine, better report it back.
logger.Errorf("cannot set error status for machine %q: %v", machine, err1)
return err1
}
return nil
}
if err := machine.SetProvisioned(inst.Id(), nonce, metadata); err != nil {
logger.Errorf("cannot register instance for machine %v: %v", machine, err)
// The machine is started, but we can't record the mapping in
// state. It'll keep running while we fail out and restart,
// but will then be detected by findUnknownInstances and
// killed again.
//
// TODO(dimitern) Stop the instance right away here.
//
// Multiple instantiations of a given machine (with the same
// machine ID) cannot coexist, because findUnknownInstances is
// called before startMachines. However, if the first machine
// had started to do work before being replaced, we may
// encounter surprising problems.
return err
}
logger.Infof("started machine %s as instance %s with hardware %q", machine, inst.Id(), metadata)
return nil
}
示例3: startInstance
// startInstance starts a new instance for the given machine.
func (s *FirewallerSuite) startInstance(c *C, m *state.Machine) instance.Instance {
inst, hc := testing.StartInstance(c, s.Conn.Environ, m.Id())
err := m.SetProvisioned(inst.Id(), "fake_nonce", hc)
c.Assert(err, IsNil)
return inst
}