本文整理汇总了Golang中github.com/juju/errors.IsNotProvisioned函数的典型用法代码示例。如果您正苦于以下问题:Golang IsNotProvisioned函数的具体用法?Golang IsNotProvisioned怎么用?Golang IsNotProvisioned使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsNotProvisioned函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: createParamsStorageAttachment
func (api *API) createParamsStorageAttachment(si params.StorageDetails, sa state.StorageAttachment) (params.StorageDetails, error) {
result := params.StorageDetails{Status: "pending"}
result.StorageTag = sa.StorageInstance().String()
if result.StorageTag != si.StorageTag {
panic("attachment does not belong to storage instance")
}
result.UnitTag = sa.Unit().String()
result.OwnerTag = si.OwnerTag
result.Kind = si.Kind
result.Persistent = si.Persistent
// TODO(axw) set status according to whether storage has been provisioned.
// This is only for provisioned attachments
machineTag, err := api.storage.UnitAssignedMachine(sa.Unit())
if err != nil {
return params.StorageDetails{}, errors.Annotate(err, "getting unit for storage attachment")
}
info, err := common.StorageAttachmentInfo(api.storage, sa, machineTag)
if err != nil {
if errors.IsNotProvisioned(err) {
// If Info returns an error, then the storage has not yet been provisioned.
return result, nil
}
return params.StorageDetails{}, errors.Annotate(err, "getting storage attachment info")
}
result.Location = info.Location
if result.Location != "" {
result.Status = "attached"
}
return result, nil
}
开发者ID:mhilton,项目名称:juju,代码行数:31,代码来源:storage.go
示例2: ServiceInstances
// ServiceInstances returns the instance IDs of provisioned
// machines that are assigned units of the specified service.
func ServiceInstances(st *State, service string) ([]instance.Id, error) {
units, err := allUnits(st, service)
if err != nil {
return nil, err
}
instanceIds := make([]instance.Id, 0, len(units))
for _, unit := range units {
machineId, err := unit.AssignedMachineId()
if errors.IsNotAssigned(err) {
continue
} else if err != nil {
return nil, err
}
machine, err := st.Machine(machineId)
if err != nil {
return nil, err
}
instanceId, err := machine.InstanceId()
if err == nil {
instanceIds = append(instanceIds, instanceId)
} else if errors.IsNotProvisioned(err) {
continue
} else {
return nil, err
}
}
return instanceIds, nil
}
开发者ID:pmatulis,项目名称:juju,代码行数:30,代码来源:distribution.go
示例3: isVolumeInherentlyMachineBound
// isVolumeInherentlyMachineBound reports whether or not the volume with the
// specified tag is inherently bound to the lifetime of the machine, and will
// be removed along with it, leaving no resources dangling.
func isVolumeInherentlyMachineBound(st *State, tag names.VolumeTag) (bool, error) {
volume, err := st.Volume(tag)
if err != nil {
return false, errors.Trace(err)
}
volumeInfo, err := volume.Info()
if errors.IsNotProvisioned(err) {
params, _ := volume.Params()
_, provider, err := poolStorageProvider(st, params.Pool)
if err != nil {
return false, errors.Trace(err)
}
if provider.Scope() == storage.ScopeMachine {
// Any storage created by a machine must be destroyed
// along with the machine.
return true, nil
}
if provider.Dynamic() {
// We don't know ahead of time whether the storage
// will be Persistent, so we assume it will be, and
// rely on the environment-level storage provisioner
// to clean up.
return false, nil
}
// Volume is static, so even if it is provisioned, it will
// be tied to the machine.
return true, nil
} else if err != nil {
return false, errors.Trace(err)
}
// If volume does not outlive machine it can be removed.
return !volumeInfo.Persistent, nil
}
开发者ID:bac,项目名称:juju,代码行数:36,代码来源:volume.go
示例4: SetFilesystemStatus
// SetFilesystemStatus sets the status of the specified filesystem.
func (st *State) SetFilesystemStatus(tag names.FilesystemTag, status Status, info string, data map[string]interface{}) error {
switch status {
case StatusAttaching, StatusAttached, StatusDetaching, StatusDetached, StatusDestroying:
case StatusError:
if info == "" {
return errors.Errorf("cannot set status %q without info", status)
}
case StatusPending:
// If a filesystem is not yet provisioned, we allow its status
// to be set back to pending (when a retry is to occur).
v, err := st.Filesystem(tag)
if err != nil {
return errors.Trace(err)
}
_, err = v.Info()
if errors.IsNotProvisioned(err) {
break
}
return errors.Errorf("cannot set status %q", status)
default:
return errors.Errorf("cannot set invalid status %q", status)
}
return setStatus(st, setStatusParams{
badge: "filesystem",
globalKey: filesystemGlobalKey(tag.Id()),
status: status,
message: info,
rawData: data,
})
}
开发者ID:pmatulis,项目名称:juju,代码行数:31,代码来源:filesystem.go
示例5: upgradingFilesystemStatus
// If the filesystem has not been provisioned, then it should be Pending;
// if it has been provisioned, but there is an unprovisioned attachment, then
// it should be Attaching; otherwise it is Attached.
func upgradingFilesystemStatus(st *State, filesystem Filesystem) (status.Status, error) {
if _, err := filesystem.Info(); errors.IsNotProvisioned(err) {
return status.StatusPending, nil
}
attachments, err := st.FilesystemAttachments(filesystem.FilesystemTag())
if err != nil {
return "", errors.Trace(err)
}
for _, attachment := range attachments {
_, err := attachment.Info()
if errors.IsNotProvisioned(err) {
return status.StatusAttaching, nil
}
}
return status.StatusAttached, nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:19,代码来源:upgrades.go
示例6: SetStatus
// SetStatus sets the status of the machine.
func (m *Machine) SetStatus(status Status, info string, data map[string]interface{}) error {
switch status {
case StatusStarted, StatusStopped:
case StatusError:
if info == "" {
return errors.Errorf("cannot set status %q without info", status)
}
case StatusPending:
// If a machine is not yet provisioned, we allow its status
// to be set back to pending (when a retry is to occur).
_, err := m.InstanceId()
allowPending := errors.IsNotProvisioned(err)
if allowPending {
break
}
fallthrough
case StatusDown:
return errors.Errorf("cannot set status %q", status)
default:
return errors.Errorf("cannot set invalid status %q", status)
}
return setStatus(m.st, setStatusParams{
badge: "machine",
globalKey: m.globalKey(),
status: status,
message: info,
rawData: data,
})
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:30,代码来源:machine.go
示例7: SetObservedNetworkConfig
func (api *MachinerAPI) SetObservedNetworkConfig(args params.SetMachineNetworkConfig) error {
m, err := api.getMachineForSettingNetworkConfig(args.Tag)
if err != nil {
return errors.Trace(err)
}
if m.IsContainer() {
return nil
}
observedConfig := args.Config
logger.Tracef("observed network config of machine %q: %+v", m.Id(), observedConfig)
if len(observedConfig) == 0 {
logger.Infof("not updating machine network config: no observed network config found")
return nil
}
providerConfig, err := api.getOneMachineProviderNetworkConfig(m)
if errors.IsNotProvisioned(err) {
logger.Infof("not updating provider network config: %v", err)
return nil
}
if err != nil {
return errors.Trace(err)
}
if len(providerConfig) == 0 {
logger.Infof("not updating machine network config: no provider network config found")
return nil
}
mergedConfig := networkingcommon.MergeProviderAndObservedNetworkConfigs(providerConfig, observedConfig)
logger.Tracef("merged observed and provider network config: %+v", mergedConfig)
return api.setOneMachineNetworkConfig(m, mergedConfig)
}
开发者ID:bac,项目名称:juju,代码行数:33,代码来源:machiner.go
示例8: isVolumeInherentlyMachineBound
// isVolumeInherentlyMachineBound reports whether or not the volume with the
// specified tag is inherently bound to the lifetime of the machine, and will
// be removed along with it, leaving no resources dangling.
func isVolumeInherentlyMachineBound(st *State, tag names.VolumeTag) (bool, error) {
volume, err := st.Volume(tag)
if err != nil {
return false, errors.Trace(err)
}
volumeInfo, err := volume.Info()
if errors.IsNotProvisioned(err) {
params, _ := volume.Params()
_, provider, err := poolStorageProvider(st, params.Pool)
if err != nil {
return false, errors.Trace(err)
}
if provider.Dynamic() {
// Even machine-scoped storage could be provisioned
// while the machine is Dying, and we don't know at
// this layer whether or not it will be Persistent.
//
// TODO(axw) extend storage provider interface to
// determine up-front whether or not a volume will
// be persistent. This will have to depend on the
// machine type, since, e.g., loop devices will
// outlive LXC containers.
return false, nil
}
// Volume is static, so even if it is provisioned, it will
// be tied to the machine.
return true, nil
} else if err != nil {
return false, errors.Trace(err)
}
// If volume does not outlive machine it can be removed.
return !volumeInfo.Persistent, nil
}
开发者ID:chrisjohnston,项目名称:juju,代码行数:36,代码来源:volume.go
示例9: ServerError
// ServerError returns an error suitable for returning to an API
// client, with an error code suitable for various kinds of errors
// generated in packages outside the API.
func ServerError(err error) *params.Error {
if err == nil {
return nil
}
logger.Tracef("server RPC error %v", errors.Details(err))
msg := err.Error()
// Skip past annotations when looking for the code.
err = errors.Cause(err)
code, ok := singletonCode(err)
var info *params.ErrorInfo
switch {
case ok:
case errors.IsUnauthorized(err):
code = params.CodeUnauthorized
case errors.IsNotFound(err):
code = params.CodeNotFound
case errors.IsUserNotFound(err):
code = params.CodeUserNotFound
case errors.IsAlreadyExists(err):
code = params.CodeAlreadyExists
case errors.IsNotAssigned(err):
code = params.CodeNotAssigned
case state.IsHasAssignedUnitsError(err):
code = params.CodeHasAssignedUnits
case state.IsHasHostedModelsError(err):
code = params.CodeHasHostedModels
case isNoAddressSetError(err):
code = params.CodeNoAddressSet
case errors.IsNotProvisioned(err):
code = params.CodeNotProvisioned
case IsUpgradeInProgressError(err):
code = params.CodeUpgradeInProgress
case state.IsHasAttachmentsError(err):
code = params.CodeMachineHasAttachedStorage
case isUnknownModelError(err):
code = params.CodeModelNotFound
case errors.IsNotSupported(err):
code = params.CodeNotSupported
case errors.IsBadRequest(err):
code = params.CodeBadRequest
case errors.IsMethodNotAllowed(err):
code = params.CodeMethodNotAllowed
default:
if err, ok := err.(*DischargeRequiredError); ok {
code = params.CodeDischargeRequired
info = ¶ms.ErrorInfo{
Macaroon: err.Macaroon,
// One macaroon fits all.
MacaroonPath: "/",
}
break
}
code = params.ErrCode(err)
}
return ¶ms.Error{
Message: msg,
Code: code,
Info: info,
}
}
开发者ID:bac,项目名称:juju,代码行数:63,代码来源:errors.go
示例10: SetVolumeStatus
// SetVolumeStatus sets the status of the specified volume.
func (st *State) SetVolumeStatus(tag names.VolumeTag, volumeStatus status.Status, info string, data map[string]interface{}, updated *time.Time) error {
switch volumeStatus {
case status.Attaching, status.Attached, status.Detaching, status.Detached, status.Destroying:
case status.Error:
if info == "" {
return errors.Errorf("cannot set status %q without info", volumeStatus)
}
case status.Pending:
// If a volume is not yet provisioned, we allow its status
// to be set back to pending (when a retry is to occur).
v, err := st.Volume(tag)
if err != nil {
return errors.Trace(err)
}
_, err = v.Info()
if errors.IsNotProvisioned(err) {
break
}
return errors.Errorf("cannot set status %q", volumeStatus)
default:
return errors.Errorf("cannot set invalid status %q", volumeStatus)
}
return setStatus(st, setStatusParams{
badge: "volume",
globalKey: volumeGlobalKey(tag.Id()),
status: volumeStatus,
message: info,
rawData: data,
updated: updated,
})
}
开发者ID:bac,项目名称:juju,代码行数:32,代码来源:volume.go
示例11: reconcileInstances
// reconcileInstances compares the initially started watcher for machines,
// units and services with the opened and closed ports of the instances and
// opens and closes the appropriate ports for each instance.
func (fw *Firewaller) reconcileInstances() error {
for _, machined := range fw.machineds {
m, err := machined.machine()
if params.IsCodeNotFound(err) {
if err := fw.forgetMachine(machined); err != nil {
return err
}
continue
}
if err != nil {
return err
}
instanceId, err := m.InstanceId()
if errors.IsNotProvisioned(err) {
logger.Errorf("Machine not yet provisioned: %v", err)
continue
}
if err != nil {
return err
}
instances, err := fw.environ.Instances([]instance.Id{instanceId})
if err == environs.ErrNoInstances {
return nil
}
if err != nil {
return err
}
machineId := machined.tag.Id()
initialPortRanges, err := instances[0].Ports(machineId)
if err != nil {
return err
}
// Check which ports to open or to close.
toOpen := diffRanges(machined.openedPorts, initialPortRanges)
toClose := diffRanges(initialPortRanges, machined.openedPorts)
if len(toOpen) > 0 {
logger.Infof("opening instance port ranges %v for %q",
toOpen, machined.tag)
if err := instances[0].OpenPorts(machineId, toOpen); err != nil {
// TODO(mue) Add local retry logic.
return err
}
network.SortPortRanges(toOpen)
}
if len(toClose) > 0 {
logger.Infof("closing instance port ranges %v for %q",
toClose, machined.tag)
if err := instances[0].ClosePorts(machineId, toClose); err != nil {
// TODO(mue) Add local retry logic.
return err
}
network.SortPortRanges(toClose)
}
}
return nil
}
开发者ID:bac,项目名称:juju,代码行数:60,代码来源:firewaller.go
示例12: makeMachineStatus
func makeMachineStatus(machine *state.Machine) (status params.MachineStatus) {
var err error
status.Id = machine.Id()
agentStatus := processMachine(machine)
status.AgentStatus = agentStatus
status.Series = machine.Series()
status.Jobs = paramsJobsFromJobs(machine.Jobs())
status.WantsVote = machine.WantsVote()
status.HasVote = machine.HasVote()
sInfo, err := machine.InstanceStatus()
populateStatusFromStatusInfoAndErr(&status.InstanceStatus, sInfo, err)
instid, err := machine.InstanceId()
if err == nil {
status.InstanceId = instid
addr, err := machine.PublicAddress()
if err != nil {
// Usually this indicates that no addresses have been set on the
// machine yet.
addr = network.Address{}
logger.Debugf("error fetching public address: %q", err)
}
status.DNSName = addr.Value
mAddrs := machine.Addresses()
if len(mAddrs) == 0 {
logger.Debugf("no IP addresses fetched for machine %q", instid)
// At least give it the newly created DNSName address, if it exists.
if addr.Value != "" {
mAddrs = append(mAddrs, addr)
}
}
for _, mAddr := range mAddrs {
switch mAddr.Scope {
case network.ScopeMachineLocal, network.ScopeLinkLocal:
continue
}
status.IPAddresses = append(status.IPAddresses, mAddr.Value)
}
} else {
if errors.IsNotProvisioned(err) {
status.InstanceId = "pending"
} else {
status.InstanceId = "error"
}
}
hc, err := machine.HardwareCharacteristics()
if err != nil {
if !errors.IsNotFound(err) {
status.Hardware = "error"
}
} else {
status.Hardware = hc.String()
}
status.Containers = make(map[string]params.MachineStatus)
return
}
开发者ID:bac,项目名称:juju,代码行数:57,代码来源:status.go
示例13: ModelMachineInfo
// ModelMachineInfo returns information about machine hardware for
// alive top level machines (not containers).
func ModelMachineInfo(st ModelManagerBackend) (machineInfo []params.ModelMachineInfo, _ error) {
machines, err := st.AllMachines()
if err != nil {
return nil, errors.Trace(err)
}
for _, m := range machines {
if m.Life() != state.Alive {
continue
}
var status string
statusInfo, err := MachineStatus(m)
if err == nil {
status = string(statusInfo.Status)
} else {
status = err.Error()
}
mInfo := params.ModelMachineInfo{
Id: m.Id(),
HasVote: m.HasVote(),
WantsVote: m.WantsVote(),
Status: status,
}
instId, err := m.InstanceId()
switch {
case err == nil:
mInfo.InstanceId = string(instId)
case errors.IsNotProvisioned(err):
// ok, but no instance ID to get.
default:
return nil, errors.Trace(err)
}
if m.ContainerType() != "" && m.ContainerType() != instance.NONE {
machineInfo = append(machineInfo, mInfo)
continue
}
// Only include cores for physical machines.
hw, err := m.HardwareCharacteristics()
if err != nil && !errors.IsNotFound(err) {
return nil, errors.Trace(err)
}
if hw != nil && hw.String() != "" {
hwParams := ¶ms.MachineHardware{
Cores: hw.CpuCores,
Arch: hw.Arch,
Mem: hw.Mem,
RootDisk: hw.RootDisk,
CpuPower: hw.CpuPower,
Tags: hw.Tags,
AvailabilityZone: hw.AvailabilityZone,
}
mInfo.Hardware = hwParams
}
machineInfo = append(machineInfo, mInfo)
}
return machineInfo, nil
}
开发者ID:kat-co,项目名称:juju,代码行数:58,代码来源:machine.go
示例14: AllocateTo
// AllocateTo sets the machine ID, MAC address and interface ID of the IP address.
// It will fail if the state is not AddressStateUnknown. On success,
// the address state will also change to AddressStateAllocated.
func (i *IPAddress) AllocateTo(machineId, interfaceId, macAddress string) (err error) {
defer errors.DeferredAnnotatef(&err, "cannot allocate IP address %q to machine %q, interface %q", i, machineId, interfaceId)
var instId instance.Id
machine, err := i.st.Machine(machineId)
if err != nil {
return errors.Annotatef(err, "cannot get allocated machine %q", machineId)
} else {
instId, err = machine.InstanceId()
if errors.IsNotProvisioned(err) {
// The machine is not yet provisioned. The instance ID will be
// set on provisioning.
instId = instance.UnknownId
} else if err != nil {
return errors.Annotatef(err, "cannot get machine %q instance ID", machineId)
}
}
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
if err := i.Refresh(); errors.IsNotFound(err) {
return nil, err
} else if i.Life() == Dead {
return nil, errors.New("address is dead")
} else if i.State() != AddressStateUnknown {
return nil, errors.Errorf("already allocated or unavailable")
} else if err != nil {
return nil, err
}
}
return []txn.Op{{
C: ipaddressesC,
Id: i.doc.DocID,
Assert: append(isAliveDoc, bson.DocElem{"state", AddressStateUnknown}),
Update: bson.D{{"$set", bson.D{
{"machineid", machineId},
{"interfaceid", interfaceId},
{"instanceid", instId},
{"macaddress", macAddress},
{"state", string(AddressStateAllocated)},
}}},
}}, nil
}
err = i.st.run(buildTxn)
if err != nil {
return err
}
i.doc.MachineId = machineId
i.doc.MACAddress = macAddress
i.doc.InterfaceId = interfaceId
i.doc.State = AddressStateAllocated
i.doc.InstanceId = string(instId)
return nil
}
开发者ID:frankban,项目名称:juju-tmp,代码行数:59,代码来源:ipaddresses.go
示例15: makeMachineStatus
func makeMachineStatus(machine *state.Machine) (status params.MachineStatus) {
status.Id = machine.Id()
agentStatus, compatStatus := processMachine(machine)
status.Agent = agentStatus
// These legacy status values will be deprecated for Juju 2.0.
status.AgentState = compatStatus.Status
status.AgentStateInfo = compatStatus.Info
status.AgentVersion = compatStatus.Version
status.Life = compatStatus.Life
status.Err = compatStatus.Err
status.Series = machine.Series()
status.Jobs = paramsJobsFromJobs(machine.Jobs())
status.WantsVote = machine.WantsVote()
status.HasVote = machine.HasVote()
instid, err := machine.InstanceId()
if err == nil {
status.InstanceId = instid
status.InstanceState, err = machine.InstanceStatus()
if err != nil {
status.InstanceState = "error"
}
addr, err := machine.PublicAddress()
if err != nil {
// Usually this indicates that no addresses have been set on the
// machine yet.
addr = network.Address{}
logger.Warningf("error fetching public address: %q", err)
}
status.DNSName = addr.Value
} else {
if errors.IsNotProvisioned(err) {
status.InstanceId = "pending"
} else {
status.InstanceId = "error"
}
// There's no point in reporting a pending agent state
// if the machine hasn't been provisioned. This
// also makes unprovisioned machines visually distinct
// in the output.
status.AgentState = ""
}
hc, err := machine.HardwareCharacteristics()
if err != nil {
if !errors.IsNotFound(err) {
status.Hardware = "error"
}
} else {
status.Hardware = hc.String()
}
status.Containers = make(map[string]params.MachineStatus)
return
}
开发者ID:kakamessi99,项目名称:juju,代码行数:54,代码来源:status.go
示例16: waitInstanceId
// waitInstanceId waits until the supplied machine has an instance id, then
// asserts it is as expected.
func (s *CommonProvisionerSuite) waitInstanceId(c *gc.C, m *state.Machine, expect instance.Id) {
s.waitHardwareCharacteristics(c, m, func() bool {
if actual, err := m.InstanceId(); err == nil {
c.Assert(actual, gc.Equals, expect)
return true
} else if !errors.IsNotProvisioned(err) {
// We don't expect any errors.
panic(err)
}
c.Logf("machine %v is still unprovisioned", m)
return false
})
}
开发者ID:felicianotech,项目名称:juju,代码行数:15,代码来源:provisioner_test.go
示例17: storageAttachmentInfo
func storageAttachmentInfo(st storageAccess, a state.StorageAttachment) (_ names.MachineTag, location string, _ error) {
machineTag, err := st.UnitAssignedMachine(a.Unit())
if errors.IsNotAssigned(err) {
return names.MachineTag{}, "", nil
} else if err != nil {
return names.MachineTag{}, "", errors.Trace(err)
}
info, err := storagecommon.StorageAttachmentInfo(st, a, machineTag)
if errors.IsNotProvisioned(err) {
return machineTag, "", nil
} else if err != nil {
return names.MachineTag{}, "", errors.Trace(err)
}
return machineTag, info.Location, nil
}
开发者ID:kat-co,项目名称:juju,代码行数:15,代码来源:storage.go
示例18: makeMachineStatus
func makeMachineStatus(machine *state.Machine) (status params.MachineStatus) {
status.Id = machine.Id()
agentStatus := processMachine(machine)
status.Agent = agentStatus
status.Series = machine.Series()
status.Jobs = paramsJobsFromJobs(machine.Jobs())
status.WantsVote = machine.WantsVote()
status.HasVote = machine.HasVote()
instid, err := machine.InstanceId()
if err == nil {
status.InstanceId = instid
status.InstanceState, err = machine.InstanceStatus()
if err != nil {
status.InstanceState = "error"
}
addr, err := machine.PublicAddress()
if err != nil {
// Usually this indicates that no addresses have been set on the
// machine yet.
addr = network.Address{}
logger.Debugf("error fetching public address: %q", err)
}
status.DNSName = addr.Value
} else {
if errors.IsNotProvisioned(err) {
status.InstanceId = "pending"
} else {
status.InstanceId = "error"
}
}
hc, err := machine.HardwareCharacteristics()
if err != nil {
if !errors.IsNotFound(err) {
status.Hardware = "error"
}
} else {
status.Hardware = hc.String()
}
status.Containers = make(map[string]params.MachineStatus)
return
}
开发者ID:imoapps,项目名称:juju,代码行数:42,代码来源:status.go
示例19: environManagerInstances
// environManagerInstances returns all environ manager instances.
func environManagerInstances(st *state.State) ([]instance.Id, error) {
info, err := st.ControllerInfo()
if err != nil {
return nil, err
}
instances := make([]instance.Id, 0, len(info.MachineIds))
for _, id := range info.MachineIds {
machine, err := st.Machine(id)
if err != nil {
return nil, err
}
instanceId, err := machine.InstanceId()
if err == nil {
instances = append(instances, instanceId)
} else if !errors.IsNotProvisioned(err) {
return nil, err
}
}
return instances, nil
}
开发者ID:bac,项目名称:juju,代码行数:21,代码来源:provisioner.go
示例20: SetConstraints
// SetConstraints sets the exact constraints to apply when provisioning an
// instance for the machine. It will fail if the machine is Dead, or if it
// is already provisioned.
func (m *Machine) SetConstraints(cons constraints.Value) (err error) {
defer errors.DeferredAnnotatef(&err, "cannot set constraints")
unsupported, err := m.st.validateConstraints(cons)
if len(unsupported) > 0 {
logger.Warningf(
"setting constraints on machine %q: unsupported constraints: %v", m.Id(), strings.Join(unsupported, ","))
} else if err != nil {
return err
}
notSetYet := bson.D{{"nonce", ""}}
ops := []txn.Op{
{
C: machinesC,
Id: m.doc.DocID,
Assert: append(isAliveDoc, notSetYet...),
},
setConstraintsOp(m.st, m.globalKey(), cons),
}
// make multiple attempts to push the ErrExcessiveContention case out of the
// realm of plausibility: it implies local state indicating unprovisioned,
// and remote state indicating provisioned (reasonable); but which changes
// back to unprovisioned and then to provisioned again with *very* specific
// timing in the course of this loop.
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
if m, err = m.st.Machine(m.doc.Id); err != nil {
return nil, err
}
}
if m.doc.Life != Alive {
return nil, errNotAlive
}
if _, err := m.InstanceId(); err == nil {
return nil, fmt.Errorf("machine is already provisioned")
} else if !errors.IsNotProvisioned(err) {
return nil, err
}
return ops, nil
}
return m.st.run(buildTxn)
}
开发者ID:vonwenm,项目名称:juju,代码行数:44,代码来源:machine.go
注:本文中的github.com/juju/errors.IsNotProvisioned函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论