本文整理汇总了Golang中github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/errors.WrapErrorf函数的典型用法代码示例。如果您正苦于以下问题:Golang WrapErrorf函数的具体用法?Golang WrapErrorf怎么用?Golang WrapErrorf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WrapErrorf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: setupRunDir
func (p linux) setupRunDir(sysDir string) error {
runDir := filepath.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
}
开发者ID:vestel,项目名称:bosh-init,代码行数:27,代码来源:linux_platform.go
示例2: 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
}
开发者ID:vestel,项目名称:bosh-init,代码行数:31,代码来源:parser.go
示例3: parseResourcePoolManifests
func (p *parser) parseResourcePoolManifests(rawResourcePools []resourcePool, path string) ([]ResourcePool, error) {
resourcePools := make([]ResourcePool, len(rawResourcePools), len(rawResourcePools))
for i, rawResourcePool := range rawResourcePools {
resourcePool := ResourcePool{
Name: rawResourcePool.Name,
Network: rawResourcePool.Network,
Stemcell: StemcellRef(rawResourcePool.Stemcell),
}
cloudProperties, err := biproperty.BuildMap(rawResourcePool.CloudProperties)
if err != nil {
return resourcePools, bosherr.WrapErrorf(err, "Parsing resource_pool '%s' cloud_properties: %#v", rawResourcePool.Name, rawResourcePool.CloudProperties)
}
resourcePool.CloudProperties = cloudProperties
env, err := biproperty.BuildMap(rawResourcePool.Env)
if err != nil {
return resourcePools, bosherr.WrapErrorf(err, "Parsing resource_pool '%s' env: %#v", rawResourcePool.Name, rawResourcePool.Env)
}
resourcePool.Env = env
resourcePool.Stemcell.URL, err = biutil.AbsolutifyPath(path, resourcePool.Stemcell.URL, p.fs)
if err != nil {
return resourcePools, bosherr.WrapErrorf(err, "Resolving stemcell path '%s", resourcePool.Stemcell.URL)
}
resourcePools[i] = resourcePool
}
return resourcePools, nil
}
开发者ID:jmaryland,项目名称:bosh-init,代码行数:31,代码来源:parser.go
示例4: parseNetworkManifests
func (p *parser) parseNetworkManifests(rawNetworks []network) ([]Network, error) {
networks := make([]Network, len(rawNetworks), len(rawNetworks))
for i, rawNetwork := range rawNetworks {
network := Network{
Name: rawNetwork.Name,
Type: NetworkType(rawNetwork.Type),
DNS: rawNetwork.DNS,
}
cloudProperties, err := biproperty.BuildMap(rawNetwork.CloudProperties)
if err != nil {
return networks, bosherr.WrapErrorf(err, "Parsing network '%s' cloud_properties: %#v", rawNetwork.Name, rawNetwork.CloudProperties)
}
network.CloudProperties = cloudProperties
for _, subnet := range rawNetwork.Subnets {
cloudProperties, err := biproperty.BuildMap(subnet.CloudProperties)
if err != nil {
return networks, bosherr.WrapErrorf(err, "Parsing network subnet '%s' cloud_properties: %#v", rawNetwork.Name, subnet.CloudProperties)
}
network.Subnets = append(network.Subnets, Subnet{
Range: subnet.Range,
Gateway: subnet.Gateway,
DNS: subnet.DNS,
CloudProperties: cloudProperties,
})
}
networks[i] = network
}
return networks, nil
}
开发者ID:jmaryland,项目名称:bosh-init,代码行数:34,代码来源:parser.go
示例5: Chown
func (fs *osFileSystem) Chown(path, username string) error {
fs.logger.Debug(fs.logTag, "Chown %s to user %s", path, username)
uid, err := fs.runCommand(fmt.Sprintf("id -u %s", username))
if err != nil {
return bosherr.WrapErrorf(err, "Getting user id for '%s'", username)
}
uidAsInt, err := strconv.Atoi(uid)
if err != nil {
return bosherr.WrapError(err, "Converting UID to integer")
}
gid, err := fs.runCommand(fmt.Sprintf("id -g %s", username))
if err != nil {
return bosherr.WrapErrorf(err, "Getting group id for '%s'", username)
}
gidAsInt, err := strconv.Atoi(gid)
if err != nil {
return bosherr.WrapError(err, "Converting GID to integer")
}
err = os.Chown(path, uidAsInt, gidAsInt)
if err != nil {
return bosherr.WrapError(err, "Doing Chown")
}
return nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:30,代码来源:os_file_system.go
示例6: 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)
}
开发者ID:vestel,项目名称:bosh-init,代码行数:27,代码来源:os_file_system.go
示例7: Add
func (b *blobstore) Add(sourcePath string) (string, error) {
blobID, err := b.uuidGenerator.Generate()
if err != nil {
return "", bosherr.WrapError(err, "Generating Blob ID")
}
b.logger.Debug(b.logTag, "Uploading blob %s from %s", blobID, sourcePath)
file, err := b.fs.OpenFile(sourcePath, os.O_RDONLY, 0)
if err != nil {
return "", bosherr.WrapErrorf(err, "Opening file for reading %s", sourcePath)
}
defer func() {
if err := file.Close(); err != nil {
b.logger.Warn(b.logTag, "Couldn't close source file: %s", err.Error())
}
}()
fileInfo, err := file.Stat()
if err != nil {
return "", bosherr.WrapErrorf(err, "Getting fileInfo from %s", sourcePath)
}
err = b.davClient.Put(blobID, file, fileInfo.Size())
if err != nil {
return "", bosherr.WrapErrorf(err, "Putting file '%s' into blobstore (via DAVClient) as blobID '%s'", sourcePath, blobID)
}
return blobID, nil
}
开发者ID:jmaryland,项目名称:bosh-init,代码行数:30,代码来源:blobstore.go
示例8: 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
}
开发者ID:vestel,项目名称:bosh-init,代码行数:35,代码来源:sfdisk_partitioner.go
示例9: 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
}
开发者ID:vestel,项目名称:bosh-init,代码行数:29,代码来源:file_system_deployment_state_service.go
示例10: 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:vestel,项目名称:bosh-init,代码行数:28,代码来源:watch_time.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:vestel,项目名称:bosh-init,代码行数:30,代码来源:root_device_partitioner.go
示例12: 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
}
开发者ID:vestel,项目名称:bosh-init,代码行数:37,代码来源:manager.go
示例13: Extract
// Extract decompresses a release tarball into a temp directory (release.extractedPath),
// parses the release manifest, decompresses the packages and jobs, and validates the release.
// Use release.Delete() to clean up the temp directory.
func (e *extractor) Extract(releaseTarballPath string) (Release, error) {
extractedReleasePath, err := e.fs.TempDir("bosh-init-release")
if err != nil {
return nil, bosherr.WrapErrorf(err, "Creating temp directory to extract release '%s'", releaseTarballPath)
}
e.logger.Info(e.logTag, "Extracting release tarball '%s' to '%s'", releaseTarballPath, extractedReleasePath)
releaseReader := NewReader(releaseTarballPath, extractedReleasePath, e.fs, e.compressor)
release, err := releaseReader.Read()
if err != nil {
if removeErr := e.fs.RemoveAll(extractedReleasePath); removeErr != nil {
e.logger.Warn(e.logTag, "Failed to remove extracted release: %s", removeErr.Error())
}
return nil, bosherr.WrapErrorf(err, "Reading release from '%s'", releaseTarballPath)
}
err = e.validator.Validate(release)
if err != nil {
if removeErr := e.fs.RemoveAll(extractedReleasePath); removeErr != nil {
e.logger.Warn(e.logTag, "Failed to remove extracted release: %s", removeErr.Error())
}
return nil, bosherr.WrapErrorf(err, "Validating release '%s-%s'", release.Name(), release.Version())
}
e.logger.Info(e.logTag, "Extracted release %s version %s", release.Name(), release.Version())
return release, nil
}
开发者ID:jmaryland,项目名称:bosh-init,代码行数:32,代码来源:extractor.go
示例14: 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:vestel,项目名称:bosh-init,代码行数:60,代码来源:root_device_partitioner.go
示例15: SetupDataDir
func (p linux) SetupDataDir() error {
dataDir := p.dirProvider.DataDir()
sysDataDir := filepath.Join(dataDir, "sys")
logDir := filepath.Join(sysDataDir, "log")
err := p.fs.MkdirAll(logDir, logDirPermissions)
if err != nil {
return bosherr.WrapErrorf(err, "Making %s dir", logDir)
}
_, _, _, err = p.cmdRunner.RunCommand("chown", "root:vcap", sysDataDir)
if err != nil {
return bosherr.WrapErrorf(err, "chown %s", sysDataDir)
}
_, _, _, err = p.cmdRunner.RunCommand("chown", "root:vcap", logDir)
if err != nil {
return bosherr.WrapErrorf(err, "chown %s", logDir)
}
err = p.setupRunDir(sysDataDir)
if err != nil {
return err
}
sysDir := filepath.Join(filepath.Dir(dataDir), "sys")
err = p.fs.Symlink(sysDataDir, sysDir)
if err != nil {
return bosherr.WrapErrorf(err, "Symlinking '%s' to '%s'", sysDir, sysDataDir)
}
return nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:34,代码来源:linux_platform.go
示例16: ConvergeFileContents
func (fs *osFileSystem) ConvergeFileContents(path string, content []byte) (bool, error) {
if fs.filesAreIdentical(content, path) {
fs.logger.Debug(fs.logTag, "Skipping writing %s because contents are identical", path)
return false, nil
}
fs.logger.Debug(fs.logTag, "File %s will be overwritten", path)
err := fs.MkdirAll(filepath.Dir(path), os.ModePerm)
if err != nil {
return true, bosherr.WrapErrorf(err, "Making dir for file %s", path)
}
file, err := os.Create(path)
if err != nil {
return true, bosherr.WrapErrorf(err, "Creating file %s", path)
}
defer file.Close()
_, err = file.Write(content)
if err != nil {
return true, bosherr.WrapErrorf(err, "Writing content to file %s", path)
}
return true, nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:27,代码来源:os_file_system.go
示例17: 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
}
开发者ID:vestel,项目名称:bosh-init,代码行数:27,代码来源:extractor.go
示例18: Calculate
func (c sha1Calculator) Calculate(filePath string) (string, error) {
file, err := c.fs.OpenFile(filePath, os.O_RDONLY, 0)
if err != nil {
return "", bosherr.WrapErrorf(err, "Calculating sha1 of '%s'", filePath)
}
defer file.Close()
fileInfo, err := file.Stat()
if err != nil {
return "", bosherr.WrapErrorf(err, "Opening file '%s' for sha1 calculation", filePath)
}
h := sha1.New()
if fileInfo.IsDir() {
c.fs.Walk(filePath+"/", func(path string, info os.FileInfo, err error) error {
if !info.IsDir() {
err := c.populateSha1(path, h)
if err != nil {
return bosherr.WrapErrorf(err, "Calculating directory SHA1 for %s", path)
}
}
return nil
})
} else {
err = c.populateSha1(filePath, h)
if err != nil {
return "", bosherr.WrapErrorf(err, "Calculating file SHA1 for %s", filePath)
}
}
return fmt.Sprintf("%x", h.Sum(nil)), nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:33,代码来源:sha1_calculator.go
示例19: Get
func (b *blobstore) Get(blobID string) (LocalBlob, error) {
file, err := b.fs.TempFile("bosh-init-local-blob")
destinationPath := file.Name()
err = file.Close()
if err != nil {
return nil, bosherr.WrapErrorf(err, "Closing new temp file '%s'", destinationPath)
}
b.logger.Debug(b.logTag, "Downloading blob %s to %s", blobID, destinationPath)
readCloser, err := b.davClient.Get(blobID)
if err != nil {
return nil, bosherr.WrapErrorf(err, "Getting blob %s from blobstore", blobID)
}
defer func() {
if err = readCloser.Close(); err != nil {
b.logger.Warn(b.logTag, "Couldn't close davClient.Get reader: %s", err.Error())
}
}()
targetFile, err := b.fs.OpenFile(destinationPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
return nil, bosherr.WrapErrorf(err, "Opening file for blob at %s", destinationPath)
}
_, err = io.Copy(targetFile, readCloser)
if err != nil {
return nil, bosherr.WrapErrorf(err, "Saving blob to %s", destinationPath)
}
return NewLocalBlob(destinationPath, b.fs, b.logger), nil
}
开发者ID:jmaryland,项目名称:bosh-init,代码行数:32,代码来源:blobstore.go
示例20: writeDHCPConfiguration
func (net centosNetManager) writeDHCPConfiguration(dnsServers []string, dhcpInterfaceConfigurations []DHCPInterfaceConfiguration) (bool, error) {
buffer := bytes.NewBuffer([]byte{})
t := template.Must(template.New("dhcp-config").Parse(centosDHCPConfigTemplate))
// Keep DNS servers in the order specified by the network
// because they are added by a *single* DHCP's prepend command
dnsServersList := strings.Join(dnsServers, ", ")
err := t.Execute(buffer, dnsServersList)
if err != nil {
return false, bosherr.WrapError(err, "Generating config from template")
}
dhclientConfigFile := "/etc/dhcp/dhclient.conf"
changed, err := net.fs.ConvergeFileContents(dhclientConfigFile, buffer.Bytes())
if err != nil {
return changed, bosherr.WrapErrorf(err, "Writing to %s", dhclientConfigFile)
}
for i := range dhcpInterfaceConfigurations {
name := dhcpInterfaceConfigurations[i].Name
interfaceDhclientConfigFile := filepath.Join("/etc/dhcp/", "dhclient-"+name+".conf")
err = net.fs.Symlink(dhclientConfigFile, interfaceDhclientConfigFile)
if err != nil {
return changed, bosherr.WrapErrorf(err, "Symlinking '%s' to '%s'", interfaceDhclientConfigFile, dhclientConfigFile)
}
}
return changed, nil
}
开发者ID:vestel,项目名称:bosh-init,代码行数:29,代码来源:centos_net_manager.go
注:本文中的github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/errors.WrapErrorf函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论