本文整理汇总了Golang中github.com/cloudfoundry/bosh-utils/errors.Errorf函数的典型用法代码示例。如果您正苦于以下问题:Golang Errorf函数的具体用法?Golang Errorf怎么用?Golang Errorf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Errorf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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
}
开发者ID:mattcui,项目名称:bosh-init,代码行数:25,代码来源:validator.go
示例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
}
开发者ID:mattcui,项目名称:bosh-init,代码行数:35,代码来源:deployer.go
示例3: validate_arguments
func (c BaremetalCreator) validate_arguments(memory int, processor int, disksize int, host string, domain string, ostype string, datacenter string) error {
if memory <= 0 {
return bosherr.Errorf("memory can not be negative: %d", memory)
}
if processor <= 0 {
return bosherr.Errorf("processor can not be negative: %d", processor)
}
if disksize <= 0 {
return bosherr.Errorf("disk size can not be negative: %d", disksize)
}
if host == "" {
return bosherr.Error("host can not be empty.")
}
if domain == "" {
return bosherr.Error("domain can not be empty.")
}
if ostype == "" {
return bosherr.Error("os type can not be empty.")
}
if datacenter == "" {
return bosherr.Error("data center can not be empty.")
}
return nil
}
开发者ID:digideskweb,项目名称:bosh-softlayer-cpi,代码行数:32,代码来源:baremetal_creator.go
示例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
}
}
开发者ID:mattcui,项目名称:bosh-init,代码行数:29,代码来源:validator.go
示例5: Run
func (a AttachDisk) Run(vmCID VMCID, diskCID DiskCID) (interface{}, error) {
vm, found, err := a.vmFinder.Find(vmCID.Int())
if err != nil {
return nil, bosherr.WrapErrorf(err, "Finding VM '%s'", vmCID)
}
if !found {
return nil, bosherr.Errorf("Expected to find VM '%s'", vmCID)
}
disk, found, err := a.diskFinder.Find(diskCID.Int())
if err != nil {
return nil, bosherr.WrapErrorf(err, "Finding disk '%s'", diskCID)
}
if !found {
return nil, bosherr.Errorf("Expected to find disk '%s'", diskCID)
}
err = vm.AttachDisk(disk)
if err != nil {
return nil, bosherr.WrapErrorf(err, "Attaching disk '%s' to VM '%s'", diskCID, vmCID)
}
return nil, nil
}
开发者ID:jianqiu,项目名称:bosh-softlayer-cpi,代码行数:26,代码来源:attach_disk.go
示例6: 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
}
开发者ID:mattcui,项目名称:bosh-init,代码行数:28,代码来源:watch_time.go
示例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
}
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:60,代码来源:root_device_partitioner.go
示例8: 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
}
开发者ID:mattcui,项目名称:bosh-init,代码行数:26,代码来源:manifest.go
示例9: 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
}
}
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:28,代码来源:builders.go
示例10: WaitForVirtualGuestIsPingable
func WaitForVirtualGuestIsPingable(softLayerClient sl.Client, virtualGuestId int, logger boshlog.Logger) error {
virtualGuestService, err := softLayerClient.GetSoftLayer_Virtual_Guest_Service()
if err != nil {
return bosherr.WrapError(err, "Creating VirtualGuestService from SoftLayer client")
}
checkPingableRetryable := boshretry.NewRetryable(
func() (bool, error) {
state, err := virtualGuestService.IsPingable(virtualGuestId)
if err != nil {
return false, bosherr.WrapErrorf(err, "Checking pingable against vitrual guest %d", virtualGuestId)
} else {
if state {
return false, nil
} else {
return true, bosherr.Errorf("vitrual guest %d is not pingable", virtualGuestId)
}
}
})
timeService := clock.NewClock()
timeoutRetryStrategy := boshretry.NewTimeoutRetryStrategy(TIMEOUT, POLLING_INTERVAL, checkPingableRetryable, timeService, logger)
err = timeoutRetryStrategy.Try()
if err != nil {
return bosherr.Errorf("Waiting for virtual guest with ID '%d' is not pingable", virtualGuestId)
}
return nil
}
开发者ID:jianqiu,项目名称:bosh-softlayer-cpi,代码行数:28,代码来源:softlayer_helper.go
示例11: WaitForVirtualGuestToTargetState
func WaitForVirtualGuestToTargetState(softLayerClient sl.Client, virtualGuestId int, targetState string, logger boshlog.Logger) error {
virtualGuestService, err := softLayerClient.GetSoftLayer_Virtual_Guest_Service()
if err != nil {
return bosherr.WrapError(err, "Creating VirtualGuestService from SoftLayer client")
}
getTargetStateRetryable := boshretry.NewRetryable(
func() (bool, error) {
vgPowerState, err := virtualGuestService.GetPowerState(virtualGuestId)
if err != nil {
return false, bosherr.WrapErrorf(err, "Getting PowerState from vitrual guest %d", virtualGuestId)
} else {
if strings.Contains(vgPowerState.KeyName, targetState) {
return false, nil
}
return true, bosherr.Errorf("The PowerState of vitrual guest %d is not targetState %s", virtualGuestId, targetState)
}
})
timeService := clock.NewClock()
timeoutRetryStrategy := boshretry.NewTimeoutRetryStrategy(TIMEOUT, POLLING_INTERVAL, getTargetStateRetryable, timeService, logger)
err = timeoutRetryStrategy.Try()
if err != nil {
return bosherr.Errorf("Waiting for virtual guest with ID '%d' to have be in state '%s'", virtualGuestId, targetState)
}
return nil
}
开发者ID:jianqiu,项目名称:bosh-softlayer-cpi,代码行数:28,代码来源:softlayer_helper.go
示例12: buildJobReaders
func (tc ConcreteTemplatesCompiler) buildJobReaders(job bpdep.Job) ([]jobReader, error) {
var readers []jobReader
for _, template := range job.Templates {
rec, found, err := tc.tplToJobRepo.FindByTemplate(template)
if err != nil {
return readers, bosherr.WrapErrorf(err, "Finding dep-template -> release-job record %s", template.Name)
} else if !found {
return readers, bosherr.Errorf("Expected to find dep-template -> release-job record %s", template.Name)
}
jobRec, found, err := tc.jobsRepo.FindByReleaseJob(rec)
if err != nil {
return readers, bosherr.WrapErrorf(err, "Finding job source blob %s", template.Name)
} else if !found {
return readers, bosherr.Errorf("Expected to find job source blob %s -- %s", template.Name, rec)
}
jobURL := fmt.Sprintf("blobstore:///%s?fingerprint=%s", jobRec.BlobID, jobRec.SHA1)
reader := jobReader{
rec: rec,
tarReader: tc.jobReaderFactory.NewReader(jobURL),
}
readers = append(readers, reader)
}
return readers, nil
}
开发者ID:pcfdev-forks,项目名称:bosh-provisioner,代码行数:30,代码来源:concrete_templates_compiler.go
示例13: createMapperPartition
func (p partedPartitioner) createMapperPartition(devicePath string) error {
_, _, _, err := p.cmdRunner.RunCommand("/etc/init.d/open-iscsi", "restart")
if err != nil {
return bosherr.WrapError(err, "Shelling out to restart open-iscsi")
}
detectPartitionRetryable := boshretry.NewRetryable(func() (bool, error) {
output, _, _, err := p.cmdRunner.RunCommand("dmsetup", "ls")
if err != nil {
return true, bosherr.WrapError(err, "Shelling out to dmsetup ls")
}
if strings.Contains(output, "No devices found") {
return true, bosherr.Errorf("No devices found")
}
device := strings.TrimPrefix(devicePath, "/dev/mapper/")
lines := strings.Split(strings.Trim(output, "\n"), "\n")
for i := 0; i < len(lines); i++ {
if match, _ := regexp.MatchString("-part1", lines[i]); match {
if strings.Contains(lines[i], device) {
p.logger.Info(p.logTag, "Succeeded in detecting partition %s", devicePath+"-part1")
return false, nil
}
}
}
return true, bosherr.Errorf("Partition %s does not show up", devicePath+"-part1")
})
detectPartitionRetryStrategy := NewPartitionStrategy(detectPartitionRetryable, p.timeService, p.logger)
return detectPartitionRetryStrategy.Try()
}
开发者ID:jianqiu,项目名称:bosh-agent,代码行数:33,代码来源:parted_partitioner.go
示例14: 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)
}
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:26,代码来源:ip_resolver.go
示例15: createMultipleInterfaceConfigurations
func (creator interfaceConfigurationCreator) createMultipleInterfaceConfigurations(networks boshsettings.Networks, interfacesByMAC map[string]string) ([]StaticInterfaceConfiguration, []DHCPInterfaceConfiguration, error) {
if len(interfacesByMAC) < len(networks) {
return nil, nil, bosherr.Errorf("Number of network settings '%d' is greater than the number of network devices '%d'", len(networks), len(interfacesByMAC))
}
for name := range networks {
if mac := networks[name].Mac; mac != "" {
if _, ok := interfacesByMAC[mac]; !ok {
return nil, nil, bosherr.Errorf("No device found for network '%s' with MAC address '%s'", name, mac)
}
}
}
// Configure interfaces with network settings matching MAC address.
// If we cannot find a network setting with a matching MAC address, configure that interface as DHCP
var networkSettings boshsettings.Network
var err error
staticConfigs := []StaticInterfaceConfiguration{}
dhcpConfigs := []DHCPInterfaceConfiguration{}
for mac, ifaceName := range interfacesByMAC {
networkSettings, _ = networks.NetworkForMac(mac)
staticConfigs, dhcpConfigs, err = creator.createInterfaceConfiguration(staticConfigs, dhcpConfigs, ifaceName, networkSettings)
if err != nil {
return nil, nil, bosherr.WrapError(err, "Creating interface configuration")
}
}
return staticConfigs, dhcpConfigs, nil
}
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:30,代码来源:interface_configuration_creator.go
示例16: NewWatchTimeFromString
func NewWatchTimeFromString(str string) (WatchTime, error) {
var watchTime WatchTime
parts := strings.Split(str, "-")
if len(parts) != 2 {
return watchTime, bosherr.Errorf("Invalid watch time range %s", str)
}
min, 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])
}
max, 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 max < min {
return watchTime, bosherr.Errorf(
"Watch time must have maximum greater than or equal minimum %s", str)
}
watchTime[0], watchTime[1] = min, max
return watchTime, nil
}
开发者ID:pcfdev-forks,项目名称:bosh-provisioner,代码行数:29,代码来源:watch_time.go
示例17: GetRealDevicePath
func (idpr idDevicePathResolver) GetRealDevicePath(diskSettings boshsettings.DiskSettings) (string, bool, error) {
if diskSettings.ID == "" {
return "", false, bosherr.Errorf("Disk ID is not set")
}
if len(diskSettings.ID) < 20 {
return "", false, bosherr.Errorf("Disk ID is not the correct format")
}
err := idpr.udev.Trigger()
if err != nil {
return "", false, bosherr.WrapError(err, "Running udevadm trigger")
}
err = idpr.udev.Settle()
if err != nil {
return "", false, bosherr.WrapError(err, "Running udevadm settle")
}
stopAfter := time.Now().Add(idpr.diskWaitTimeout)
found := false
var realPath string
diskID := diskSettings.ID[0:20]
deviceGlobPattern := fmt.Sprintf("*%s", diskID)
deviceIDPathGlobPattern := path.Join("/", "dev", "disk", "by-id", deviceGlobPattern)
for !found {
if time.Now().After(stopAfter) {
return "", true, bosherr.Errorf("Timed out getting real device path for '%s'", diskID)
}
time.Sleep(100 * time.Millisecond)
pathMatches, err := idpr.fs.Glob(deviceIDPathGlobPattern)
if err != nil {
continue
}
switch len(pathMatches) {
case 0:
continue
case 1:
realPath, err = idpr.fs.ReadAndFollowLink(pathMatches[0])
if err != nil {
continue
}
if idpr.fs.FileExists(realPath) {
found = true
}
default:
return "", true, bosherr.Errorf("More than one disk matched glob %q while getting real device path for %q", deviceIDPathGlobPattern, diskID)
}
}
return realPath, false, nil
}
开发者ID:mattcui,项目名称:bosh-agent,代码行数:58,代码来源:id_device_path_resolver.go
示例18: GetRealDevicePath
func (idpr SCSIIDDevicePathResolver) GetRealDevicePath(diskSettings boshsettings.DiskSettings) (string, bool, error) {
if diskSettings.DeviceID == "" {
return "", false, bosherr.Errorf("Disk device ID is not set")
}
hostPaths, err := idpr.fs.Glob("/sys/class/scsi_host/host*/scan")
if err != nil {
return "", false, bosherr.WrapError(err, "Could not list SCSI hosts")
}
for _, hostPath := range hostPaths {
idpr.logger.Info(idpr.logTag, "Performing SCSI rescan of "+hostPath)
err = idpr.fs.WriteFileString(hostPath, "- - -")
if err != nil {
return "", false, bosherr.WrapError(err, "Starting SCSI rescan")
}
}
stopAfter := time.Now().Add(idpr.diskWaitTimeout)
found := false
var realPath string
for !found {
idpr.logger.Debug(idpr.logTag, "Waiting for device to appear")
if time.Now().After(stopAfter) {
return "", true, bosherr.Errorf("Timed out getting real device path for '%s'", diskSettings.DeviceID)
}
time.Sleep(100 * time.Millisecond)
uuid := strings.Replace(diskSettings.DeviceID, "-", "", -1)
disks, err := idpr.fs.Glob("/dev/disk/by-id/*" + uuid)
if err != nil {
return "", false, bosherr.WrapError(err, "Could not list disks by id")
}
for _, path := range disks {
idpr.logger.Debug(idpr.logTag, "Reading link "+path)
realPath, err = idpr.fs.ReadAndFollowLink(path)
if err != nil {
continue
}
if idpr.fs.FileExists(realPath) {
idpr.logger.Debug(idpr.logTag, "Found real path "+realPath)
found = true
break
}
}
}
return realPath, false, nil
}
开发者ID:mattcui,项目名称:bosh-agent,代码行数:54,代码来源:scsi_id_device_path_resolver.go
示例19: 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
}
开发者ID:mattcui,项目名称:bosh-init,代码行数:54,代码来源:validator.go
示例20: 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}
}
}
开发者ID:mattcui,项目名称:bosh-init,代码行数:12,代码来源:validator.go
注:本文中的github.com/cloudfoundry/bosh-utils/errors.Errorf函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论