本文整理汇总了Golang中github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/errors.Errorf函数的典型用法代码示例。如果您正苦于以下问题:Golang Errorf函数的具体用法?Golang Errorf怎么用?Golang Errorf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Errorf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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:viovanov,项目名称:bosh-agent,代码行数:28,代码来源:builders.go
示例2: 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:viovanov,项目名称:bosh-agent,代码行数:60,代码来源:root_device_partitioner.go
示例3: 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:viovanov,项目名称:bosh-agent,代码行数:30,代码来源:interface_configuration_creator.go
示例4: 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:viovanov,项目名称:bosh-agent,代码行数:26,代码来源:ip_resolver.go
示例5: 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
}
开发者ID:tacgomes,项目名称:bosh-agent,代码行数:48,代码来源:agent_client.go
示例6: Get
func (p HandlerProvider) Get(
platform boshplatform.Platform,
dirProvider boshdir.Provider,
) (handler boshhandler.Handler, err error) {
if p.handler != nil {
handler = p.handler
return
}
mbusURL, err := url.Parse(p.settingsService.GetSettings().Mbus)
if err != nil {
err = bosherr.WrapError(err, "Parsing handler URL")
return
}
switch mbusURL.Scheme {
case "nats":
handler = NewNatsHandler(p.settingsService, yagnats.NewClient(), p.logger)
case "https":
handler = boshmicro.NewHTTPSHandler(mbusURL, p.logger, platform.GetFs(), dirProvider)
default:
err = bosherr.Errorf("Message Bus Handler with scheme %s could not be found", mbusURL.Scheme)
}
p.handler = handler
return
}
开发者ID:viovanov,项目名称:bosh-agent,代码行数:28,代码来源:handler_provider.go
示例7: Run
func (a MountDiskAction) Run(diskCid string) (interface{}, error) {
err := a.settingsService.LoadSettings()
if err != nil {
return nil, bosherr.WrapError(err, "Refreshing the settings")
}
settings := a.settingsService.GetSettings()
diskSettings, found := settings.PersistentDiskSettings(diskCid)
if !found {
return nil, bosherr.Errorf("Persistent disk with volume id '%s' could not be found", diskCid)
}
mountPoint := a.dirProvider.StoreDir()
isMountPoint, err := a.mountPoints.IsMountPoint(mountPoint)
if err != nil {
return nil, bosherr.WrapError(err, "Checking mount point")
}
if isMountPoint {
mountPoint = a.dirProvider.StoreMigrationDir()
}
err = a.diskMounter.MountPersistentDisk(diskSettings, mountPoint)
if err != nil {
return nil, bosherr.WrapError(err, "Mounting persistent disk")
}
return map[string]string{}, nil
}
开发者ID:viovanov,项目名称:bosh-agent,代码行数:30,代码来源:mount_disk.go
示例8: Get
func (p provider) Get(name string) (Platform, error) {
plat, found := p.platforms[name]
if !found {
return nil, bosherror.Errorf("Platform %s could not be found", name)
}
return plat, nil
}
开发者ID:tacgomes,项目名称:bosh-agent,代码行数:7,代码来源:provider.go
示例9: Validate
func (b externalBlobstore) Validate() error {
if !b.runner.CommandExists(b.executable()) {
return bosherr.Errorf("executable %s not found in PATH", b.executable())
}
return b.writeConfigFile()
}
开发者ID:viovanov,项目名称:bosh-agent,代码行数:7,代码来源:external_blobstore.go
示例10: PopulateDHCPNetworks
func (s concreteV1Service) PopulateDHCPNetworks(spec V1ApplySpec, settings boshsettings.Settings) (V1ApplySpec, error) {
for networkName, networkSpec := range spec.NetworkSpecs {
// Skip 'local' network since for vsphere/vcloud networks
// are generated incorrectly by the bosh_cli_plugin_micro/bosh-release;
// can be removed with new bosh micro CLI
if networkName == "local" && networkSpec.Fields["ip"] == "127.0.0.1" {
continue
}
network, ok := settings.Networks[networkName]
if !ok {
return V1ApplySpec{}, bosherr.Errorf("Network '%s' is not found in settings", networkName)
}
if !network.IsDHCP() {
continue
}
spec.NetworkSpecs[networkName] = networkSpec.PopulateIPInfo(
network.IP,
network.Netmask,
network.Gateway,
)
}
return spec, nil
}
开发者ID:viovanov,项目名称:bosh-agent,代码行数:27,代码来源:concrete_v1_service.go
示例11: GetDeviceSizeInBytes
func (p rootDevicePartitioner) GetDeviceSizeInBytes(devicePath string) (uint64, error) {
p.logger.Debug(p.logTag, "Getting size of disk remaining after first partition")
stdout, _, _, err := p.cmdRunner.RunCommand("parted", "-m", devicePath, "unit", "B", "print")
if err != nil {
return 0, bosherr.WrapErrorf(err, "Getting remaining size of `%s'", devicePath)
}
allLines := strings.Split(stdout, "\n")
if len(allLines) < 3 {
return 0, bosherr.Errorf("Getting remaining size of `%s'", devicePath)
}
partitionInfoLines := allLines[1:3]
deviceInfo := strings.Split(partitionInfoLines[0], ":")
deviceFullSizeInBytes, err := strconv.ParseUint(strings.TrimRight(deviceInfo[1], "B"), 10, 64)
if err != nil {
return 0, bosherr.WrapErrorf(err, "Getting remaining size of `%s'", devicePath)
}
firstPartitionInfo := strings.Split(partitionInfoLines[1], ":")
firstPartitionEndInBytes, err := strconv.ParseUint(strings.TrimRight(firstPartitionInfo[2], "B"), 10, 64)
if err != nil {
return 0, bosherr.WrapErrorf(err, "Getting remaining size of `%s'", devicePath)
}
remainingSizeInBytes := deviceFullSizeInBytes - firstPartitionEndInBytes - 1
return remainingSizeInBytes, nil
}
开发者ID:viovanov,项目名称:bosh-agent,代码行数:30,代码来源:root_device_partitioner.go
示例12: Get
func (p Provider) Get(name string) (supervisor JobSupervisor, err error) {
supervisor, found := p.supervisors[name]
if !found {
err = bosherr.Errorf("JobSupervisor %s could not be found", name)
}
return
}
开发者ID:viovanov,项目名称:bosh-agent,代码行数:7,代码来源:provider.go
示例13: Run
func (a UnmountDiskAction) Run(diskID string) (value interface{}, err error) {
settings := a.settingsService.GetSettings()
diskSettings, found := settings.PersistentDiskSettings(diskID)
if !found {
err = bosherr.Errorf("Persistent disk with volume id '%s' could not be found", diskID)
return
}
didUnmount, err := a.platform.UnmountPersistentDisk(diskSettings)
if err != nil {
err = bosherr.WrapError(err, "Unmounting persistent disk")
return
}
msg := fmt.Sprintf("Partition of %s is not mounted", diskSettings.Path)
if didUnmount {
msg = fmt.Sprintf("Unmounted partition of %s", diskSettings.Path)
}
type valueType struct {
Message string `json:"message"`
}
value = valueType{Message: msg}
return
}
开发者ID:viovanov,项目名称:bosh-agent,代码行数:28,代码来源:unmount_disk.go
示例14: 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]
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)
deviceIDPath := filepath.Join(string(os.PathSeparator), "dev", "disk", "by-id", fmt.Sprintf("virtio-%s", diskID))
realPath, err = idpr.fs.ReadLink(deviceIDPath)
if err != nil {
continue
}
if idpr.fs.FileExists(realPath) {
found = true
}
}
return realPath, false, nil
}
开发者ID:viovanov,项目名称:bosh-agent,代码行数:47,代码来源:id_device_path_resolver.go
示例15: Run
func (a CancelTaskAction) Run(taskID string) (string, error) {
task, found := a.taskService.FindTaskWithID(taskID)
if !found {
return "", bosherr.Errorf("Task with id %s could not be found", taskID)
}
return "canceled", task.Cancel()
}
开发者ID:tacgomes,项目名称:bosh-agent,代码行数:8,代码来源:cancel_task.go
示例16: Create
func (f concreteFactory) Create(method string) (Action, error) {
action, found := f.availableActions[method]
if !found {
return nil, bosherr.Errorf("Could not create action with method %s", method)
}
return action, nil
}
开发者ID:zhang-hua,项目名称:bosh-agent,代码行数:8,代码来源:concrete_factory.go
示例17: Attempt
func (r *getStateRetryable) Attempt() (bool, error) {
stateResponse, err := r.agentClient.GetState()
if err != nil {
return false, err
}
if stateResponse.JobState == "running" {
return true, nil
}
return true, bosherr.Errorf("Received non-running job state: '%s'", stateResponse.JobState)
}
开发者ID:tacgomes,项目名称:bosh-agent,代码行数:12,代码来源:get_state_retryable.go
示例18: shouldMount
func (m linuxMounter) shouldMount(partitionPath, mountPoint string) (bool, error) {
mounts, err := m.mountsSearcher.SearchMounts()
if err != nil {
return false, bosherr.WrapError(err, "Searching mounts")
}
for _, mount := range mounts {
switch {
case mount.PartitionPath == partitionPath && mount.MountPoint == mountPoint:
return false, nil
case mount.PartitionPath == partitionPath && mount.MountPoint != mountPoint && partitionPath != "tmpfs":
return false, bosherr.Errorf("Device %s is already mounted to %s, can't mount to %s",
mount.PartitionPath, mount.MountPoint, mountPoint)
case mount.MountPoint == mountPoint:
return false, bosherr.Errorf("Device %s is already mounted to %s, can't mount %s",
mount.PartitionPath, mount.MountPoint, partitionPath)
}
}
return true, nil
}
开发者ID:viovanov,项目名称:bosh-agent,代码行数:21,代码来源:linux_mounter.go
示例19: Run
func (a RunScriptAction) Run(scriptName string, options map[string]interface{}) (map[string]string, error) {
result := map[string]string{}
currentSpec, err := a.specService.Get()
if err != nil {
return result, bosherr.WrapError(err, "Getting current spec")
}
a.logger.Info("run-script-action", "Attempting to run '%s' scripts in %d jobs", scriptName, len(currentSpec.JobSpec.JobTemplateSpecs))
scriptCount := 0
resultChannel := make(chan scriptrunner.RunScriptResult)
for _, jobTemplate := range currentSpec.JobSpec.JobTemplateSpecs {
script := a.scriptProvider.Get(jobTemplate.Name, scriptName)
if script.Exists() {
scriptCount++
go func() {
resultChannel <- script.Run()
}()
}
}
var failedScripts []string
var passedScripts []string
for i := 0; i < scriptCount; i++ {
select {
case resultScript := <-resultChannel:
jobName := resultScript.Tag
if resultScript.Error == nil {
passedScripts = append(passedScripts, jobName)
result[jobName] = "executed"
a.logger.Info("run-script-action", "'%s' script has successfully executed", resultScript.ScriptPath)
} else {
failedScripts = append(failedScripts, jobName)
result[jobName] = "failed"
a.logger.Error("run-script-action", "'%s' script has failed with error %s", resultScript.ScriptPath, resultScript.Error)
}
}
}
if len(failedScripts) > 0 {
msg := "Failed Jobs: " + strings.Join(failedScripts, ", ")
if len(passedScripts) > 0 {
msg += ". Successful Jobs: " + strings.Join(passedScripts, ", ")
}
return result, bosherr.Errorf("%d of %d %s scripts failed. %s.", len(failedScripts), scriptCount, scriptName, msg)
}
return result, nil
}
开发者ID:gu-bin,项目名称:bosh-agent,代码行数:52,代码来源:run_script.go
示例20: Start
func (c *agentClient) Start() error {
var response SimpleTaskResponse
err := c.agentRequest.Send("start", []interface{}{}, &response)
if err != nil {
return bosherr.WrapError(err, "Starting agent services")
}
if response.Value != "started" {
return bosherr.Errorf("Failed to start agent services with response: '%s'", response)
}
return nil
}
开发者ID:tacgomes,项目名称:bosh-agent,代码行数:13,代码来源:agent_client.go
注:本文中的github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/errors.Errorf函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论