本文整理汇总了Golang中gopkg/in/goose/v1/errors.IsNotFound函数的典型用法代码示例。如果您正苦于以下问题:Golang IsNotFound函数的具体用法?Golang IsNotFound怎么用?Golang IsNotFound使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsNotFound函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Instances
func (e *Environ) Instances(ids []instance.Id) ([]instance.Instance, error) {
if len(ids) == 0 {
return nil, nil
}
// Make a series of requests to cope with eventual consistency.
// Each request will attempt to add more instances to the requested
// set.
var foundServers []nova.ServerDetail
for a := shortAttempt.Start(); a.Next(); {
var err error
foundServers, err = e.listServers(ids)
if err != nil {
logger.Debugf("error listing servers: %v", err)
if !gooseerrors.IsNotFound(err) {
return nil, err
}
}
if len(foundServers) == len(ids) {
break
}
}
logger.Tracef("%d/%d live servers found", len(foundServers), len(ids))
if len(foundServers) == 0 {
return nil, environs.ErrNoInstances
}
instsById := make(map[string]instance.Instance, len(foundServers))
for i, server := range foundServers {
// TODO(wallyworld): lookup the flavor details to fill in the
// instance type data
instsById[server.Id] = &openstackInstance{
e: e,
serverDetail: &foundServers[i],
}
}
// Update the instance structs with any floating IP address that has been assigned to the instance.
if e.ecfg().useFloatingIP() {
if err := e.updateFloatingIPAddresses(instsById); err != nil {
return nil, err
}
}
insts := make([]instance.Instance, len(ids))
var err error
for i, id := range ids {
if inst := instsById[string(id)]; inst != nil {
insts[i] = inst
} else {
err = environs.ErrPartialInstances
}
}
return insts, err
}
示例2: DiscardSecurityGroup
// DiscardSecurityGroup cleans up a security group, it is not an error to
// delete something that doesn't exist.
func DiscardSecurityGroup(e environs.Environ, name string) error {
env := e.(*environ)
novaClient := env.nova()
group, err := novaClient.SecurityGroupByName(name)
if err != nil {
if errors.IsNotFound(err) {
// Group already deleted, done
return nil
}
}
err = novaClient.DeleteSecurityGroup(group.Id)
if err != nil {
return err
}
return nil
}
示例3: terminateInstances
func (e *Environ) terminateInstances(ids []instance.Id) error {
if len(ids) == 0 {
return nil
}
var firstErr error
novaClient := e.nova()
for _, id := range ids {
err := novaClient.DeleteServer(string(id))
if gooseerrors.IsNotFound(err) {
err = nil
}
if err != nil && firstErr == nil {
logger.Debugf("error terminating instance %q: %v", id, err)
firstErr = err
}
}
return firstErr
}
示例4: StartInstance
//.........这里部分代码省略.........
var publicIP *nova.FloatingIP
if withPublicIP {
logger.Debugf("allocating public IP address for openstack node")
if fip, err := e.allocatePublicIP(); err != nil {
return nil, errors.Annotate(err, "cannot allocate a public IP as needed")
} else {
publicIP = fip
logger.Infof("allocated public IP %s", publicIP.IP)
}
}
cfg := e.Config()
var groupNames = make([]nova.SecurityGroupName, 0)
groups, err := e.firewaller.SetUpGroups(args.InstanceConfig.MachineId, cfg.APIPort())
if err != nil {
return nil, errors.Annotate(err, "cannot set up groups")
}
for _, g := range groups {
groupNames = append(groupNames, nova.SecurityGroupName{g.Name})
}
machineName := resourceName(
names.NewMachineTag(args.InstanceConfig.MachineId),
e.Config().UUID(),
)
tryStartNovaInstance := func(
attempts utils.AttemptStrategy,
client *nova.Client,
instanceOpts nova.RunServerOpts,
) (server *nova.Entity, err error) {
for a := attempts.Start(); a.Next(); {
server, err = client.RunServer(instanceOpts)
if err == nil || gooseerrors.IsNotFound(err) == false {
break
}
}
return server, err
}
tryStartNovaInstanceAcrossAvailZones := func(
attempts utils.AttemptStrategy,
client *nova.Client,
instanceOpts nova.RunServerOpts,
availabilityZones []string,
) (server *nova.Entity, err error) {
for _, zone := range availabilityZones {
instanceOpts.AvailabilityZone = zone
e.configurator.ModifyRunServerOptions(&instanceOpts)
server, err = tryStartNovaInstance(attempts, client, instanceOpts)
if err == nil || isNoValidHostsError(err) == false {
break
}
logger.Infof("no valid hosts available in zone %q, trying another availability zone", zone)
}
if err != nil {
err = errors.Annotate(err, "cannot run instance")
}
return server, err
}
var opts = nova.RunServerOpts{
Name: machineName,
示例5: maybeNotFound
// maybeNotFound returns a errors.NotFoundError if the root cause of the specified error is due to a file or
// container not being found.
func maybeNotFound(err error) (error, bool) {
if err != nil && gooseerrors.IsNotFound(err) {
return jujuerrors.NewNotFound(err, ""), true
}
return err, false
}