本文整理汇总了Golang中github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/errors.Errorf函数的典型用法代码示例。如果您正苦于以下问题:Golang Errorf函数的具体用法?Golang Errorf怎么用?Golang Errorf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Errorf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DiskPool
func (d Manifest) DiskPool(jobName string) (DiskPool, error) {
job, found := d.FindJobByName(jobName)
if !found {
return DiskPool{}, bosherr.Errorf("Could not find job with name: %s", jobName)
}
if job.PersistentDiskPool != "" {
for _, diskPool := range d.DiskPools {
if diskPool.Name == job.PersistentDiskPool {
return diskPool, nil
}
}
err := bosherr.Errorf("Could not find persistent disk pool '%s' for job '%s'", job.PersistentDiskPool, jobName)
return DiskPool{}, err
}
if job.PersistentDisk > 0 {
diskPool := DiskPool{
DiskSize: job.PersistentDisk,
CloudProperties: biproperty.Map{},
}
return diskPool, nil
}
return DiskPool{}, nil
}
示例2: createAllInstances
func (d *deployer) createAllInstances(
deploymentManifest bideplmanifest.Manifest,
instanceManager biinstance.Manager,
cloudStemcell bistemcell.CloudStemcell,
registryConfig biinstallmanifest.Registry,
deployStage biui.Stage,
) ([]biinstance.Instance, []bidisk.Disk, error) {
instances := []biinstance.Instance{}
disks := []bidisk.Disk{}
if len(deploymentManifest.Jobs) != 1 {
return instances, disks, bosherr.Errorf("There must only be one job, found %d", len(deploymentManifest.Jobs))
}
for _, jobSpec := range deploymentManifest.Jobs {
if jobSpec.Instances != 1 {
return instances, disks, bosherr.Errorf("Job '%s' must have only one instance, found %d", jobSpec.Name, jobSpec.Instances)
}
for instanceID := 0; instanceID < jobSpec.Instances; instanceID++ {
instance, instanceDisks, err := instanceManager.Create(jobSpec.Name, instanceID, deploymentManifest, cloudStemcell, registryConfig, deployStage)
if err != nil {
return instances, disks, bosherr.WrapErrorf(err, "Creating instance '%s/%d'", jobSpec.Name, instanceID)
}
instances = append(instances, instance)
disks = append(disks, instanceDisks...)
err = instance.UpdateJobs(deploymentManifest, deployStage)
if err != nil {
return instances, disks, err
}
}
}
return instances, disks, nil
}
示例3: Build
// Build creates a generic property that may be a Map, List or primitive.
// If it is a Map or List it will be built using the appropriate builder and constraints.
func Build(val interface{}) (Property, error) {
if val == nil {
return nil, nil
}
switch reflect.TypeOf(val).Kind() {
case reflect.Map:
valMap, ok := val.(map[interface{}]interface{})
if !ok {
return nil, bosherr.Errorf("Converting map %#v", val)
}
return BuildMap(valMap)
case reflect.Slice:
valSlice, ok := val.([]interface{})
if !ok {
return nil, bosherr.Errorf("Converting slice %#v", val)
}
return BuildList(valSlice)
default:
return val, nil
}
}
示例4: validateGateway
func (v *validator) validateGateway(idx int, gateway string, ipNet maybeIPNet) []error {
if v.isBlank(gateway) {
return []error{bosherr.Errorf("networks[%d].subnets[0].gateway must be provided", idx)}
} else {
errors := []error{}
ipNet.Try(func(ipNet *net.IPNet) error {
gatewayIp := net.ParseIP(gateway)
if gatewayIp == nil {
errors = append(errors, bosherr.Errorf("networks[%d].subnets[0].gateway must be an ip", idx))
}
if !ipNet.Contains(gatewayIp) {
errors = append(errors, bosherr.Errorf("subnet gateway '%s' must be within the specified range '%s'", gateway, ipNet))
}
if ipNet.IP.Equal(gatewayIp) {
errors = append(errors, bosherr.Errorf("subnet gateway can't be the network address '%s'", gatewayIp))
}
if binet.LastAddress(ipNet).Equal(gatewayIp) {
errors = append(errors, bosherr.Errorf("subnet gateway can't be the broadcast address '%s'", gatewayIp))
}
return nil
})
return errors
}
}
示例5: validateNetwork
func (v *validator) validateNetwork(network Network, networkIdx int) []error {
errs := []error{}
if v.isBlank(network.Name) {
errs = append(errs, bosherr.Errorf("networks[%d].name must be provided", networkIdx))
}
if network.Type != Dynamic && network.Type != Manual && network.Type != VIP {
errs = append(errs, bosherr.Errorf("networks[%d].type must be 'manual', 'dynamic', or 'vip'", networkIdx))
}
if network.Type == Manual {
if len(network.Subnets) != 1 {
errs = append(errs, bosherr.Errorf("networks[%d].subnets must be of size 1", networkIdx))
} else {
ipRange := network.Subnets[0].Range
rangeErrors, maybeIpNet := v.validateRange(networkIdx, ipRange)
errs = append(errs, rangeErrors...)
gateway := network.Subnets[0].Gateway
gatewayErrors := v.validateGateway(networkIdx, gateway, maybeIpNet)
errs = append(errs, gatewayErrors...)
}
}
return errs
}
示例6: GetPrimaryIPv4
func (r ipResolver) GetPrimaryIPv4(interfaceName string) (*gonet.IPNet, error) {
addrs, err := r.ifaceToAddrsFunc(interfaceName)
if err != nil {
return nil, bosherr.WrapErrorf(err, "Looking up addresses for interface '%s'", interfaceName)
}
if len(addrs) == 0 {
return nil, bosherr.Errorf("No addresses found for interface '%s'", interfaceName)
}
for _, addr := range addrs {
ip, ok := addr.(*gonet.IPNet)
if !ok {
continue
}
// ignore ipv6
if ip.IP.To4() == nil {
continue
}
return ip, nil
}
return nil, bosherr.Errorf("Failed to find primary IPv4 address for interface '%s'", interfaceName)
}
示例7: Partition
func (p rootDevicePartitioner) Partition(devicePath string, partitions []Partition) error {
existingPartitions, deviceFullSizeInBytes, err := p.getPartitions(devicePath)
if err != nil {
return bosherr.WrapErrorf(err, "Getting existing partitions of `%s'", devicePath)
}
p.logger.Debug(p.logTag, "Current partitions: %#v", existingPartitions)
if len(existingPartitions) == 0 {
return bosherr.Errorf("Missing first partition on `%s'", devicePath)
}
if p.partitionsMatch(existingPartitions[1:], partitions) {
p.logger.Info(p.logTag, "Partitions already match, skipping partitioning")
return nil
}
if len(existingPartitions) > 1 {
p.logger.Error(p.logTag,
"Failed to create ephemeral partitions on root device `%s'. Expected 1 partition, found %d: %s",
devicePath,
len(existingPartitions),
existingPartitions,
)
return bosherr.Errorf("Found %d unexpected partitions on `%s'", len(existingPartitions)-1, devicePath)
}
// To support optimal reads on HDDs and optimal erasure on SSD: use 1MiB partition alignments.
alignmentInBytes := uint64(1048576)
partitionStart := p.roundUp(existingPartitions[0].EndInBytes+1, alignmentInBytes)
for index, partition := range partitions {
partitionEnd := partitionStart + partition.SizeInBytes - 1
if partitionEnd >= deviceFullSizeInBytes {
partitionEnd = deviceFullSizeInBytes - 1
p.logger.Info(p.logTag, "Partition %d would be larger than remaining space. Reducing size to %dB", index, partitionEnd-partitionStart)
}
p.logger.Info(p.logTag, "Creating partition %d with start %dB and end %dB", index, partitionStart, partitionEnd)
_, _, _, err := p.cmdRunner.RunCommand(
"parted",
"-s",
devicePath,
"unit",
"B",
"mkpart",
"primary",
fmt.Sprintf("%d", partitionStart),
fmt.Sprintf("%d", partitionEnd),
)
if err != nil {
return bosherr.WrapErrorf(err, "Partitioning disk `%s'", devicePath)
}
partitionStart = p.roundUp(partitionEnd+1, alignmentInBytes)
}
return nil
}
示例8: NewWatchTime
func NewWatchTime(timeRange string) (WatchTime, error) {
parts := strings.Split(timeRange, "-")
if len(parts) != 2 {
return WatchTime{}, bosherr.Errorf("Invalid watch time range '%s'", timeRange)
}
start, err := strconv.Atoi(strings.Trim(parts[0], " "))
if err != nil {
return WatchTime{}, bosherr.WrapErrorf(
err, "Non-positive number as watch time minimum %s", parts[0])
}
end, err := strconv.Atoi(strings.Trim(parts[1], " "))
if err != nil {
return WatchTime{}, bosherr.WrapErrorf(
err, "Non-positive number as watch time maximum %s", parts[1])
}
if end < start {
return WatchTime{}, bosherr.Errorf(
"Watch time must have maximum greater than or equal minimum %s", timeRange)
}
return WatchTime{
Start: start,
End: end,
}, nil
}
示例9: validateJobNetworks
func (v *validator) validateJobNetworks(jobNetworks []JobNetwork, networks []Network, jobIdx int) []error {
errs := []error{}
defaultCounts := make(map[NetworkDefault]int)
for networkIdx, jobNetwork := range jobNetworks {
if v.isBlank(jobNetwork.Name) {
errs = append(errs, bosherr.Errorf("jobs[%d].networks[%d].name must be provided", jobIdx, networkIdx))
}
var matchingNetwork Network
found := false
for _, network := range networks {
if network.Name == jobNetwork.Name {
found = true
matchingNetwork = network
}
}
if !found {
errs = append(errs, bosherr.Errorf("jobs[%d].networks[%d] not found in networks", jobIdx, networkIdx))
}
for ipIdx, ip := range jobNetwork.StaticIPs {
staticIPErrors := v.validateStaticIP(ip, jobNetwork, matchingNetwork, jobIdx, networkIdx, ipIdx)
errs = append(errs, staticIPErrors...)
}
for defaultIdx, value := range jobNetwork.Defaults {
if value != NetworkDefaultDNS && value != NetworkDefaultGateway {
errs = append(errs, bosherr.Errorf("jobs[%d].networks[%d].default[%d] must be 'dns' or 'gateway'", jobIdx, networkIdx, defaultIdx))
}
}
for _, dflt := range jobNetwork.Defaults {
count, present := defaultCounts[dflt]
if present {
defaultCounts[dflt] = count + 1
} else {
defaultCounts[dflt] = 1
}
}
}
for _, dflt := range []NetworkDefault{"dns", "gateway"} {
count, found := defaultCounts[dflt]
if len(jobNetworks) > 1 && !found {
errs = append(errs, bosherr.Errorf("with multiple networks, a default for '%s' must be specified", dflt))
} else if count > 1 {
errs = append(errs, bosherr.Errorf("only one network can be the default for '%s'", dflt))
}
}
return errs
}
示例10: validateRange
func (v *validator) validateRange(idx int, ipRange string) ([]error, maybeIPNet) {
if v.isBlank(ipRange) {
return []error{bosherr.Errorf("networks[%d].subnets[0].range must be provided", idx)}, ¬hingIpNet{}
} else {
_, ipNet, err := net.ParseCIDR(ipRange)
if err != nil {
return []error{bosherr.Errorf("networks[%d].subnets[0].range must be an ip range", idx)}, ¬hingIpNet{}
}
return []error{}, &somethingIpNet{ipNet: ipNet}
}
}
示例11: Validate
func (v Validator) Validate(release birel.Release, cpiReleaseJobName string) error {
job, ok := release.FindJobByName(cpiReleaseJobName)
if !ok {
return bosherr.Errorf("CPI release must contain specified job '%s'", cpiReleaseJobName)
}
_, ok = job.FindTemplateByValue(ReleaseBinaryName)
if !ok {
return bosherr.Errorf("Specified CPI release job '%s' must contain a template that renders to target '%s'", cpiReleaseJobName, ReleaseBinaryName)
}
return nil
}
示例12: TaskID
func (r *TaskResponse) TaskID() (string, error) {
complexResponse, ok := r.Value.(map[string]interface{})
if !ok {
return "", bosherr.Errorf("Failed to convert agent response to map %#v\n%s", r.Value, debug.Stack())
}
agentTaskID, ok := complexResponse["agent_task_id"]
if !ok {
return "", bosherr.Errorf("Failed to parse task id from agent response %#v", r.Value)
}
return agentTaskID.(string), nil
}
示例13: Resolve
func (r *resolver) Resolve(jobName, releaseName string) (bireljob.Job, error) {
release, found := r.releaseManager.Find(releaseName)
if !found {
return bireljob.Job{}, bosherr.Errorf("Finding release '%s'", releaseName)
}
releaseJob, found := release.FindJobByName(jobName)
if !found {
return bireljob.Job{}, bosherr.Errorf("Finding job '%s' in release '%s'", jobName, releaseName)
}
return releaseJob, nil
}
示例14: ResourcePool
func (d Manifest) ResourcePool(jobName string) (ResourcePool, error) {
job, found := d.FindJobByName(jobName)
if !found {
return ResourcePool{}, bosherr.Errorf("Could not find job with name: %s", jobName)
}
for _, resourcePool := range d.ResourcePools {
if resourcePool.Name == job.ResourcePool {
return resourcePool, nil
}
}
err := bosherr.Errorf("Could not find resource pool '%s' for job '%s'", job.ResourcePool, jobName)
return ResourcePool{}, err
}
示例15: CompilePackage
func (c *agentClient) CompilePackage(packageSource agentclient.BlobRef, compiledPackageDependencies []agentclient.BlobRef) (compiledPackageRef agentclient.BlobRef, err error) {
dependencies := make(map[string]BlobRef, len(compiledPackageDependencies))
for _, dependency := range compiledPackageDependencies {
dependencies[dependency.Name] = BlobRef{
Name: dependency.Name,
Version: dependency.Version,
SHA1: dependency.SHA1,
BlobstoreID: dependency.BlobstoreID,
}
}
args := []interface{}{
packageSource.BlobstoreID,
packageSource.SHA1,
packageSource.Name,
packageSource.Version,
dependencies,
}
responseValue, err := c.sendAsyncTaskMessage("compile_package", args)
if err != nil {
return agentclient.BlobRef{}, bosherr.WrapError(err, "Sending 'compile_package' to the agent")
}
result, ok := responseValue["result"].(map[string]interface{})
if !ok {
return agentclient.BlobRef{}, bosherr.Errorf("Unable to parse 'compile_package' response from the agent: %#v", responseValue)
}
sha1, ok := result["sha1"].(string)
if !ok {
return agentclient.BlobRef{}, bosherr.Errorf("Unable to parse 'compile_package' response from the agent: %#v", responseValue)
}
blobstoreID, ok := result["blobstore_id"].(string)
if !ok {
return agentclient.BlobRef{}, bosherr.Errorf("Unable to parse 'compile_package' response from the agent: %#v", responseValue)
}
compiledPackageRef = agentclient.BlobRef{
Name: packageSource.Name,
Version: packageSource.Version,
SHA1: sha1,
BlobstoreID: blobstoreID,
}
return compiledPackageRef, nil
}