本文整理汇总了Golang中github.com/juju/juju/api/provisioner.Machine.SetInstanceInfo方法的典型用法代码示例。如果您正苦于以下问题:Golang Machine.SetInstanceInfo方法的具体用法?Golang Machine.SetInstanceInfo怎么用?Golang Machine.SetInstanceInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/api/provisioner.Machine
的用法示例。
在下文中一共展示了Machine.SetInstanceInfo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: startMachine
func (task *provisionerTask) startMachine(
machine *apiprovisioner.Machine,
provisioningInfo *params.ProvisioningInfo,
startInstanceParams environs.StartInstanceParams,
) error {
inst, metadata, networkInfo, err := task.broker.StartInstance(startInstanceParams)
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.
return task.setErrorStatus("cannot start instance for machine %q: %v", machine, err)
}
nonce := startInstanceParams.MachineConfig.MachineNonce
networks, ifaces := task.prepareNetworkAndInterfaces(networkInfo)
err = machine.SetInstanceInfo(inst.Id(), nonce, metadata, networks, ifaces)
if err != nil && params.IsCodeNotImplemented(err) {
return fmt.Errorf("cannot provision instance %v for machine %q with networks: not implemented", inst.Id(), machine)
} else if err == nil {
logger.Infof("started machine %s as instance %s with hardware %q, networks %v, interfaces %v", machine, inst.Id(), metadata, networks, ifaces)
return nil
}
// We need to stop the instance right away here, set error status and go on.
task.setErrorStatus("cannot register instance for machine %v: %v", machine, err)
if err := task.broker.StopInstances(inst.Id()); err != nil {
// We cannot even stop the instance, log the error and quit.
return errors.Annotatef(err, "cannot stop instance %q for machine %v", inst.Id(), machine)
}
return nil
}
示例2: startMachine
func (task *provisionerTask) startMachine(
machine *apiprovisioner.Machine,
provisioningInfo *params.ProvisioningInfo,
startInstanceParams environs.StartInstanceParams,
) error {
result, err := task.broker.StartInstance(startInstanceParams)
if err != nil {
// If this is a retryable error, we retry once
if instance.IsRetryableCreationError(errors.Cause(err)) {
logger.Infof("retryable error received on start instance - retrying instance creation")
result, err = task.broker.StartInstance(startInstanceParams)
if err != nil {
return task.setErrorStatus("cannot start instance for machine after a retry %q: %v", machine, err)
}
} else {
// 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.
return task.setErrorStatus("cannot start instance for machine %q: %v", machine, err)
}
}
inst := result.Instance
hardware := result.Hardware
nonce := startInstanceParams.InstanceConfig.MachineNonce
networks, ifaces, err := task.prepareNetworkAndInterfaces(result.NetworkInfo)
if err != nil {
return task.setErrorStatus("cannot prepare network for machine %q: %v", machine, err)
}
volumes := volumesToApiserver(result.Volumes)
volumeAttachments := volumeAttachmentsToApiserver(result.VolumeAttachments)
// TODO(dimitern) In a newer Provisioner API version, change
// SetInstanceInfo or add a new method that takes and saves in
// state all the information available on a network.InterfaceInfo
// for each interface, so we can later manage interfaces
// dynamically at run-time.
err = machine.SetInstanceInfo(inst.Id(), nonce, hardware, networks, ifaces, volumes, volumeAttachments)
if err != nil && params.IsCodeNotImplemented(err) {
return fmt.Errorf("cannot provision instance %v for machine %q with networks: not implemented", inst.Id(), machine)
} else if err == nil {
logger.Infof(
"started machine %s as instance %s with hardware %q, networks %v, interfaces %v, volumes %v, volume attachments %v, subnets to zones %v",
machine, inst.Id(), hardware,
networks, ifaces,
volumes, volumeAttachments,
startInstanceParams.SubnetsToZones,
)
return nil
}
// We need to stop the instance right away here, set error status and go on.
task.setErrorStatus("cannot register instance for machine %v: %v", machine, err)
if err := task.broker.StopInstances(inst.Id()); err != nil {
// We cannot even stop the instance, log the error and quit.
return errors.Annotatef(err, "cannot stop instance %q for machine %v", inst.Id(), machine)
}
return nil
}
示例3: startMachine
func (task *provisionerTask) startMachine(
machine *apiprovisioner.Machine,
provisioningInfo *params.ProvisioningInfo,
startInstanceParams environs.StartInstanceParams,
) error {
var result *environs.StartInstanceResult
for attemptsLeft := task.retryStartInstanceStrategy.retryCount; attemptsLeft >= 0; attemptsLeft-- {
attemptResult, err := task.broker.StartInstance(startInstanceParams)
if err == nil {
result = attemptResult
break
} else if attemptsLeft <= 0 {
// 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.
return task.setErrorStatus("cannot start instance for machine %q: %v", machine, err)
}
logger.Warningf("%v", errors.Annotate(err, "starting instance"))
retryMsg := fmt.Sprintf("will retry to start instance in %v", task.retryStartInstanceStrategy.retryDelay)
if err2 := machine.SetStatus(status.Pending, retryMsg, nil); err2 != nil {
logger.Errorf("%v", err2)
}
logger.Infof(retryMsg)
select {
case <-task.catacomb.Dying():
return task.catacomb.ErrDying()
case <-time.After(task.retryStartInstanceStrategy.retryDelay):
}
}
networkConfig := networkingcommon.NetworkConfigFromInterfaceInfo(result.NetworkInfo)
volumes := volumesToAPIserver(result.Volumes)
volumeNameToAttachmentInfo := volumeAttachmentsToAPIserver(result.VolumeAttachments)
if err := machine.SetInstanceInfo(
result.Instance.Id(),
startInstanceParams.InstanceConfig.MachineNonce,
result.Hardware,
networkConfig,
volumes,
volumeNameToAttachmentInfo,
); err != nil {
// We need to stop the instance right away here, set error status and go on.
if err2 := task.setErrorStatus("cannot register instance for machine %v: %v", machine, err); err2 != nil {
logger.Errorf("%v", errors.Annotate(err2, "cannot set machine's status"))
}
if err2 := task.broker.StopInstances(result.Instance.Id()); err2 != nil {
logger.Errorf("%v", errors.Annotate(err2, "after failing to set instance info"))
}
return errors.Annotate(err, "cannot set instance info")
}
logger.Infof(
"started machine %s as instance %s with hardware %q, network config %+v, volumes %v, volume attachments %v, subnets to zones %v",
machine,
result.Instance.Id(),
result.Hardware,
networkConfig,
volumes,
volumeNameToAttachmentInfo,
startInstanceParams.SubnetsToZones,
)
return nil
}
示例4: startMachine
func (task *provisionerTask) startMachine(
machine *apiprovisioner.Machine,
provisioningInfo *params.ProvisioningInfo,
startInstanceParams environs.StartInstanceParams,
) error {
result, err := task.broker.StartInstance(startInstanceParams)
if err != nil {
if !instance.IsRetryableCreationError(errors.Cause(err)) {
// 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.
return task.setErrorStatus("cannot start instance for machine %q: %v", machine, err)
}
logger.Infof("retryable error received on start instance: %v", err)
for count := task.retryStartInstanceStrategy.retryCount; count > 0; count-- {
if task.retryStartInstanceStrategy.retryDelay > 0 {
select {
case <-task.catacomb.Dying():
return task.catacomb.ErrDying()
case <-time.After(task.retryStartInstanceStrategy.retryDelay):
}
}
result, err = task.broker.StartInstance(startInstanceParams)
if err == nil {
break
}
// If this was the last attempt and an error was received, set the error
// status on the machine.
if count == 1 {
return task.setErrorStatus("cannot start instance for machine %q: %v", machine, err)
}
}
}
inst := result.Instance
hardware := result.Hardware
nonce := startInstanceParams.InstanceConfig.MachineNonce
networks, ifaces, err := task.prepareNetworkAndInterfaces(result.NetworkInfo)
if err != nil {
return task.setErrorStatus("cannot prepare network for machine %q: %v", machine, err)
}
volumes := volumesToApiserver(result.Volumes)
volumeAttachments := volumeAttachmentsToApiserver(result.VolumeAttachments)
// TODO(dimitern) In a newer Provisioner API version, change
// SetInstanceInfo or add a new method that takes and saves in
// state all the information available on a network.InterfaceInfo
// for each interface, so we can later manage interfaces
// dynamically at run-time.
err = machine.SetInstanceInfo(inst.Id(), nonce, hardware, networks, ifaces, volumes, volumeAttachments)
if err == nil {
logger.Infof(
"started machine %s as instance %s with hardware %q, networks %v, interfaces %v, volumes %v, volume attachments %v, subnets to zones %v",
machine, inst.Id(), hardware,
networks, ifaces,
volumes, volumeAttachments,
startInstanceParams.SubnetsToZones,
)
return nil
}
// We need to stop the instance right away here, set error status and go on.
task.setErrorStatus("cannot register instance for machine %v: %v", machine, err)
if err := task.broker.StopInstances(inst.Id()); err != nil {
// We cannot even stop the instance, log the error and quit.
return errors.Annotatef(err, "cannot stop instance %q for machine %v", inst.Id(), machine)
}
return nil
}