本文整理匯總了Golang中github.com/cloudfoundry/bosh-utils/errors.WrapErrorf函數的典型用法代碼示例。如果您正苦於以下問題:Golang WrapErrorf函數的具體用法?Golang WrapErrorf怎麽用?Golang WrapErrorf使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了WrapErrorf函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Upload
// Upload stemcell to an IAAS. It does the following steps:
// 1) uploads the stemcell to the cloud (if needed),
// 2) saves a record of the uploaded stemcell in the repo
func (m *manager) Upload(extractedStemcell ExtractedStemcell, uploadStage biui.Stage) (cloudStemcell CloudStemcell, err error) {
manifest := extractedStemcell.Manifest()
stageName := fmt.Sprintf("Uploading stemcell '%s/%s'", manifest.Name, manifest.Version)
err = uploadStage.Perform(stageName, func() error {
foundStemcellRecord, found, err := m.repo.Find(manifest.Name, manifest.Version)
if err != nil {
return bosherr.WrapError(err, "Finding existing stemcell record in repo")
}
if found {
cloudStemcell = NewCloudStemcell(foundStemcellRecord, m.repo, m.cloud)
return biui.NewSkipStageError(bosherr.Errorf("Found stemcell: %#v", foundStemcellRecord), "Stemcell already uploaded")
}
cid, err := m.cloud.CreateStemcell(manifest.ImagePath, manifest.CloudProperties)
if err != nil {
return bosherr.WrapErrorf(err, "creating stemcell (%s %s)", manifest.Name, manifest.Version)
}
stemcellRecord, err := m.repo.Save(manifest.Name, manifest.Version, cid)
if err != nil {
//TODO: delete stemcell from cloud when saving fails
return bosherr.WrapErrorf(err, "saving stemcell record in repo (cid=%s, stemcell=%s)", cid, extractedStemcell)
}
cloudStemcell = NewCloudStemcell(stemcellRecord, m.repo, m.cloud)
return nil
})
if err != nil {
return cloudStemcell, err
}
return cloudStemcell, nil
}
示例2: getAllowedHostCredential
func (vm SoftLayerVM) getAllowedHostCredential(virtualGuest datatypes.SoftLayer_Virtual_Guest) (AllowedHostCredential, error) {
virtualGuestService, err := vm.softLayerClient.GetSoftLayer_Virtual_Guest_Service()
if err != nil {
return AllowedHostCredential{}, bosherr.WrapError(err, "Cannot get softlayer virtual guest service.")
}
allowedHost, err := virtualGuestService.GetAllowedHost(virtualGuest.Id)
if err != nil {
return AllowedHostCredential{}, bosherr.WrapErrorf(err, "Cannot get allowed host with instance id: %d", virtualGuest.Id)
}
if allowedHost.Id == 0 {
return AllowedHostCredential{}, bosherr.Errorf("Cannot get allowed host with instance id: %d", virtualGuest.Id)
}
allowedHostService, err := vm.softLayerClient.GetSoftLayer_Network_Storage_Allowed_Host_Service()
if err != nil {
return AllowedHostCredential{}, bosherr.WrapError(err, "Cannot get network storage allowed host service.")
}
credential, err := allowedHostService.GetCredential(allowedHost.Id)
if err != nil {
return AllowedHostCredential{}, bosherr.WrapErrorf(err, "Cannot get credential with allowed host id: %d", allowedHost.Id)
}
return AllowedHostCredential{
Iqn: allowedHost.Name,
Username: credential.Username,
Password: credential.Password,
}, nil
}
示例3: GetDeviceSizeInBytes
func (p partedPartitioner) 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
}
示例4: Get
func (s *systemInterfaceAddrs) Get() ([]InterfaceAddress, error) {
ifaces, err := net.Interfaces()
if err != nil {
return []InterfaceAddress{}, bosherr.WrapError(err, "Getting network interfaces")
}
interfaceAddrs := []InterfaceAddress{}
for _, iface := range ifaces {
addrs, err := iface.Addrs()
if err != nil {
return []InterfaceAddress{}, bosherr.WrapErrorf(err, "Getting addresses of interface '%s'", iface.Name)
}
for _, addr := range addrs {
ip, _, err := net.ParseCIDR(addr.String())
if err != nil {
return []InterfaceAddress{}, bosherr.WrapErrorf(err, "Parsing addresses of interface '%s'", iface.Name)
}
if ipv4 := ip.To4(); ipv4 != nil {
interfaceAddrs = append(interfaceAddrs, NewSimpleInterfaceAddress(iface.Name, ipv4.String()))
}
}
}
return interfaceAddrs, nil
}
示例5: Symlink
func (fs *osFileSystem) Symlink(oldPath, newPath string) error {
fs.logger.Debug(fs.logTag, "Symlinking oldPath %s with newPath %s", oldPath, newPath)
if fi, err := os.Lstat(newPath); err == nil {
if fi.Mode()&os.ModeSymlink != 0 {
// Symlink
new, err := os.Readlink(newPath)
if err != nil {
return bosherr.WrapErrorf(err, "Reading link for %s", newPath)
}
if filepath.Clean(oldPath) == filepath.Clean(new) {
return nil
}
}
if err := os.Remove(newPath); err != nil {
return bosherr.WrapErrorf(err, "Removing new path at %s", newPath)
}
}
containingDir := filepath.Dir(newPath)
if !fs.FileExists(containingDir) {
fs.MkdirAll(containingDir, os.FileMode(0700))
}
return symlink(oldPath, newPath)
}
示例6: 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
}
示例7: setupRunDir
func (p linux) setupRunDir(sysDir string) error {
runDir := path.Join(sysDir, "run")
_, runDirIsMounted, err := p.IsMountPoint(runDir)
if err != nil {
return bosherr.WrapErrorf(err, "Checking for mount point %s", runDir)
}
if !runDirIsMounted {
err = p.fs.MkdirAll(runDir, runDirPermissions)
if err != nil {
return bosherr.WrapErrorf(err, "Making %s dir", runDir)
}
err = p.diskManager.GetMounter().Mount("tmpfs", runDir, "-t", "tmpfs", "-o", "size=1m")
if err != nil {
return bosherr.WrapErrorf(err, "Mounting tmpfs to %s", runDir)
}
_, _, _, err = p.cmdRunner.RunCommand("chown", "root:vcap", runDir)
if err != nil {
return bosherr.WrapErrorf(err, "chown %s", runDir)
}
}
return nil
}
示例8: Parse
func (p *parser) Parse(path string) (Manifest, error) {
contents, err := p.fs.ReadFile(path)
if err != nil {
return Manifest{}, bosherr.WrapErrorf(err, "Reading file %s", path)
}
comboManifest := manifest{}
err = yaml.Unmarshal(contents, &comboManifest)
if err != nil {
return Manifest{}, bosherr.WrapError(err, "Unmarshalling release set manifest")
}
p.logger.Debug(p.logTag, "Parsed release set manifest: %#v", comboManifest)
for i, releaseRef := range comboManifest.Releases {
comboManifest.Releases[i].URL, err = biutil.AbsolutifyPath(path, releaseRef.URL, p.fs)
if err != nil {
return Manifest{}, bosherr.WrapErrorf(err, "Resolving release path '%s", releaseRef.URL)
}
}
releaseSetManifest := Manifest{
Releases: comboManifest.Releases,
}
err = p.validator.Validate(releaseSetManifest)
if err != nil {
return Manifest{}, bosherr.WrapError(err, "Validating release set manifest")
}
return releaseSetManifest, nil
}
示例9: Update
func (s registryAgentEnvService) Update(agentEnv AgentEnv) error {
settingsJSON, err := json.Marshal(agentEnv)
if err != nil {
return bosherr.WrapError(err, "Marshalling agent env")
}
s.logger.Debug(s.logTag, "Updating registry endpoint '%s' with agent env: '%s'", s.endpoint, settingsJSON)
putPayload := bytes.NewReader(settingsJSON)
request, err := http.NewRequest("PUT", s.endpoint, putPayload)
if err != nil {
return bosherr.WrapErrorf(err, "Creating PUT request to update registry at '%s' with settings '%s'", s.endpoint, settingsJSON)
}
httpClient := http.Client{}
httpResponse, err := httpClient.Do(request)
if err != nil {
return bosherr.WrapErrorf(err, "Updating registry endpoint '%s' with settings: '%s'", s.endpoint, settingsJSON)
}
defer httpResponse.Body.Close()
if httpResponse.StatusCode != http.StatusOK && httpResponse.StatusCode != http.StatusCreated {
return bosherr.Errorf("Received non-2xx status code when contacting registry: '%d'", httpResponse.StatusCode)
}
return nil
}
示例10: Run
func (a SyncDNS) Run(blobID, sha1 string) (string, error) {
fileName, err := a.blobstore.Get(blobID, sha1)
if err != nil {
return "", bosherr.WrapErrorf(err, "Getting %s from blobstore", blobID)
}
fs := a.platform.GetFs()
contents, err := fs.ReadFile(fileName)
if err != nil {
return "", bosherr.WrapErrorf(err, "Reading fileName %s from blobstore", fileName)
}
err = fs.RemoveAll(fileName)
if err != nil {
a.logger.Info(a.logTag, fmt.Sprintf("Failed to remove dns blob file at path '%s'", fileName))
}
dnsRecords := boshsettings.DNSRecords{}
err = json.Unmarshal(contents, &dnsRecords)
if err != nil {
return "", bosherr.WrapError(err, "Unmarshalling DNS records")
}
err = a.platform.SaveDNSRecords(dnsRecords, a.settingsService.GetSettings().AgentID)
if err != nil {
return "", bosherr.WrapError(err, "Saving DNS records in platform")
}
return "synced", nil
}
示例11: Load
func (s *fileSystemDeploymentStateService) Load() (DeploymentState, error) {
if s.configPath == "" {
panic("configPath not yet set!")
}
s.logger.Debug(s.logTag, "Loading deployment state: %s", s.configPath)
deploymentState := &DeploymentState{}
if s.fs.FileExists(s.configPath) {
deploymentStateFileContents, err := s.fs.ReadFile(s.configPath)
if err != nil {
return DeploymentState{}, bosherr.WrapErrorf(err, "Reading deployment state file '%s'", s.configPath)
}
s.logger.Debug(s.logTag, "Deployment File Contents %#s", deploymentStateFileContents)
err = json.Unmarshal(deploymentStateFileContents, deploymentState)
if err != nil {
return DeploymentState{}, bosherr.WrapErrorf(err, "Unmarshalling deployment state file '%s'", s.configPath)
}
}
err := s.initDefaults(deploymentState)
if err != nil {
return DeploymentState{}, bosherr.WrapErrorf(err, "Initializing deployment state defaults")
}
return *deploymentState, nil
}
示例12: Symlink
func (fs *osFileSystem) Symlink(oldPath, newPath string) error {
fs.logger.Debug(fs.logTag, "Symlinking oldPath %s with newPath %s", oldPath, newPath)
actualOldPath, err := filepath.EvalSymlinks(oldPath)
if err != nil {
return bosherr.WrapErrorf(err, "Evaluating symlinks for %s", oldPath)
}
existingTargetedPath, err := filepath.EvalSymlinks(newPath)
if err == nil {
if existingTargetedPath == actualOldPath {
return nil
}
err = os.Remove(newPath)
if err != nil {
return bosherr.WrapErrorf(err, "Failed to delete symlimk at %s", newPath)
}
}
containingDir := filepath.Dir(newPath)
if !fs.FileExists(containingDir) {
fs.MkdirAll(containingDir, os.FileMode(0700))
}
return os.Symlink(oldPath, newPath)
}
示例13: Extract
func (e *extractor) Extract(blobID string, blobSHA1 string, targetDir string) error {
// Retrieve a temp copy of blob
filePath, err := e.blobstore.Get(blobID, blobSHA1)
if err != nil {
return bosherr.WrapErrorf(err, "Getting object from blobstore: %s", blobID)
}
// Clean up temp copy of blob
defer e.cleanUpBlob(filePath)
existed := e.fs.FileExists(targetDir)
if !existed {
err = e.fs.MkdirAll(targetDir, os.ModePerm)
if err != nil {
return bosherr.WrapErrorf(err, "Creating target dir: %s", targetDir)
}
}
err = e.compressor.DecompressFileToDir(filePath, targetDir, boshcmd.CompressorOptions{})
if err != nil {
if !existed {
// Clean up extracted contents of blob
e.cleanUpFile(targetDir)
}
return bosherr.WrapErrorf(err, "Decompressing compiled package: BlobID: '%s', BlobSHA1: '%s'", blobID, blobSHA1)
}
return nil
}
示例14: 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
}
示例15: diskMatchesPartitions
func (p sfdiskPartitioner) diskMatchesPartitions(devicePath string, partitionsToMatch []Partition) (result bool) {
existingPartitions, err := p.getPartitions(devicePath)
if err != nil {
err = bosherr.WrapErrorf(err, "Getting partitions for %s", devicePath)
return
}
if len(existingPartitions) < len(partitionsToMatch) {
return
}
remainingDiskSpace, err := p.GetDeviceSizeInBytes(devicePath)
if err != nil {
err = bosherr.WrapErrorf(err, "Getting device size for %s", devicePath)
return
}
for index, partitionToMatch := range partitionsToMatch {
if index == len(partitionsToMatch)-1 {
partitionToMatch.SizeInBytes = remainingDiskSpace
}
existingPartition := existingPartitions[index]
switch {
case existingPartition.Type != partitionToMatch.Type:
return
case !withinDelta(existingPartition.SizeInBytes, partitionToMatch.SizeInBytes, p.convertFromMbToBytes(20)):
return
}
remainingDiskSpace = remainingDiskSpace - partitionToMatch.SizeInBytes
}
return true
}