本文整理汇总了Golang中github.com/cloudfoundry/bosh-agent/errors.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: GetDefaultNetwork
func (r defaultNetworkResolver) GetDefaultNetwork() (boshsettings.Network, error) {
network := boshsettings.Network{}
routes, err := r.routesSearcher.SearchRoutes()
if err != nil {
return network, bosherr.WrapError(err, "Searching routes")
}
if len(routes) == 0 {
return network, bosherr.New("No routes found")
}
for _, route := range routes {
if !route.IsDefault() {
continue
}
ip, err := r.ipResolver.GetPrimaryIPv4(route.InterfaceName)
if err != nil {
return network, bosherr.WrapError(
err, "Getting primary IPv4 for interface '%s'", route.InterfaceName)
}
return boshsettings.Network{
IP: ip.IP.String(),
Netmask: gonet.IP(ip.Mask).String(),
Gateway: route.Gateway,
}, nil
}
return network, bosherr.New("Failed to find default route")
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:33,代码来源:default_network_resolver.go
示例2: GetPrimaryIPv4
func (r ipResolver) GetPrimaryIPv4(interfaceName string) (*gonet.IPNet, error) {
addrs, err := r.ifaceToAddrsFunc(interfaceName)
if err != nil {
return nil, bosherr.WrapError(err, "Looking up addresses for interface '%s'", interfaceName)
}
if len(addrs) == 0 {
return nil, bosherr.New("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.New("Failed to find primary IPv4 address for interface '%s'", interfaceName)
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:26,代码来源:ip_resolver.go
示例3: validate
func (c Config) validate() error {
if c.AssetsDir == "" {
return bosherr.New("Must provide non-empty assets_dir")
}
if c.ReposDir == "" {
return bosherr.New("Must provide non-empty repos_dir")
}
err := c.EventLog.Validate()
if err != nil {
return bosherr.WrapError(err, "Validating event_log configuration")
}
if c.Blobstore.Type != bpprov.BlobstoreConfigTypeLocal {
return bosherr.New("Blobstore type must be local")
}
err = c.Blobstore.Validate()
if err != nil {
return bosherr.WrapError(err, "Validating blobstore configuration")
}
return nil
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:25,代码来源:config.go
示例4: 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.WrapError(err, "Finding dep-template -> release-job record %s", template.Name)
} else if !found {
return readers, bosherr.New("Expected to find dep-template -> release-job record %s", template.Name)
}
jobRec, found, err := tc.jobsRepo.FindByReleaseJob(rec)
if err != nil {
return readers, bosherr.WrapError(err, "Finding job source blob %s", template.Name)
} else if !found {
return readers, bosherr.New("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:keaty,项目名称:bosh-provisioner,代码行数:30,代码来源:concrete_templates_compiler.go
示例5: validateJob
func (v SyntaxValidator) validateJob(job *Job) error {
if job.Name == "" {
return bosherr.New("Missing job name")
}
if job.Template != nil {
return bosherr.New("'template' is deprecated in favor of 'templates'")
}
err := v.validateUpdate(&job.Update)
if err != nil {
return bosherr.WrapError(err, "Update")
}
props, err := bputil.NewStringKeyed().ConvertMap(job.PropertiesRaw)
if err != nil {
return bosherr.WrapError(err, "Properties")
}
job.Properties = props
for i, na := range job.NetworkAssociations {
err := v.validateNetworkAssociation(&job.NetworkAssociations[i])
if err != nil {
return bosherr.WrapError(err, "Network association %s (%d)", na.NetworkName, i)
}
}
return nil
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:30,代码来源:syntax_validator.go
示例6: NewWatchTimeFromString
func NewWatchTimeFromString(str string) (WatchTime, error) {
var watchTime WatchTime
parts := strings.Split(str, "-")
if len(parts) != 2 {
return watchTime, bosherr.New("Invalid watch time range %s", str)
}
min, err := strconv.Atoi(strings.Trim(parts[0], " "))
if err != nil {
return watchTime, bosherr.WrapError(
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.WrapError(
err, "Non-positive number as watch time maximum %s", parts[1])
}
if max < min {
return watchTime, bosherr.New(
"Watch time must have maximum greater than or equal minimum %s", str)
}
watchTime[0], watchTime[1] = min, max
return watchTime, nil
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:29,代码来源:watch_time.go
示例7: Validate
func (v SyntaxValidator) Validate() error {
if v.release.Name == "" {
return bosherr.New("Missing release name")
}
if v.release.Version == "" {
return bosherr.New("Missing release version")
}
if v.release.CommitHash == "" {
return bosherr.New("Missing release commit_hash")
}
for i, job := range v.release.Jobs {
err := v.validateJob(&v.release.Jobs[i])
if err != nil {
return bosherr.WrapError(err, "Job %s (%d)", job.Name, i)
}
}
for i, pkg := range v.release.Packages {
err := v.validatePkg(&v.release.Packages[i])
if err != nil {
return bosherr.WrapError(err, "Package %s (%d)", pkg.Name, i)
}
}
return nil
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:29,代码来源:syntax_validator.go
示例8: validateNetworkAssociation
func (v SemanticValidator) validateNetworkAssociation(na NetworkAssociation) error {
if na.Network == nil {
return bosherr.New("Missing associated network")
}
if na.MustHaveStaticIP && na.StaticIP == nil {
return bosherr.New("Missing static IP assignment")
}
return nil
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:11,代码来源:semantic_validator.go
示例9: Get
func (bc FileBundleCollection) Get(definition BundleDefinition) (Bundle, error) {
if len(definition.BundleName()) == 0 {
return nil, bosherr.New("Missing bundle name")
}
if len(definition.BundleVersion()) == 0 {
return nil, bosherr.New("Missing bundle version")
}
installPath := filepath.Join(bc.installPath, bc.name, definition.BundleName(), definition.BundleVersion())
enablePath := filepath.Join(bc.enablePath, bc.name, definition.BundleName())
return NewFileBundle(installPath, enablePath, bc.fs, bc.logger), nil
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:13,代码来源:file_bundle_collection.go
示例10: validateNetworkType
func (v SyntaxValidator) validateNetworkType(networkType string) error {
if networkType == "" {
return bosherr.New("Missing network type")
}
for _, t := range NetworkTypes {
if networkType == t {
return nil
}
}
return bosherr.New("Unknown network type %s", networkType)
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:13,代码来源:syntax_validator.go
示例11: validateRelease
func (v SyntaxValidator) validateRelease(release *Release) error {
if release.Name == "" {
return bosherr.New("Missing release name")
}
if release.Version == "" {
return bosherr.New("Missing release version")
}
if release.URL == "" {
return bosherr.New("Missing release URL")
}
return nil
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:15,代码来源:syntax_validator.go
示例12: Find
func (ri DBIndex) Find(key interface{}, value interface{}) error {
rawKey, err := ri.structToMap(key)
if err != nil {
return err
}
rawKeyBytes, err := json.Marshal(rawKey)
if err != nil {
return err
}
rows, err := ri.adapter.Find(rawKeyBytes)
if err != nil {
return err
}
if rows == nil {
return bosherr.New("Expected to find entries for key '%s'", rawKeyBytes)
}
if !rows.Next() {
return bpindex.ErrNotFound
}
var rawEntryBytes []byte
err = rows.Scan(&rawEntryBytes)
if err != nil {
return err
}
if rows.Next() {
// todo should rows.Err() be called before returning
return bosherr.New("Expected to not find more than 1 entry for key '%s'", rawKeyBytes)
}
err = rows.Err()
if err != nil {
return err
}
err = json.Unmarshal(rawEntryBytes, &value)
if err != nil {
return err
}
return nil
}
开发者ID:pivotalservices,项目名称:bosh-hub,代码行数:48,代码来源:db_index.go
示例13: stopRunsv
func (p RunitProvisioner) stopRunsv(name string, stopTimeout time.Duration) error {
p.logger.Info(runitProvisionerLogTag, "Stopping runsv")
// Potentially tried to deprovision before ever provisioning
if !p.runner.CommandExists("sv") {
return nil
}
downStdout, _, _, err := p.runner.RunCommand("sv", "down", name)
if err != nil {
p.logger.Error(runitProvisionerLogTag, "Ignoring down error %s", err)
}
// If runsv configuration does not exist, service was never started
if strings.Contains(downStdout, "file does not exist") {
return nil
}
var lastStatusStdout string
var passedDuration time.Duration
for ; passedDuration < stopTimeout; passedDuration += runitStopStepDuration {
lastStatusStdout, _, _, _ = p.runner.RunCommand("sv", "status", name)
if runitStatusDownRegex.MatchString(lastStatusStdout) {
return nil
}
time.Sleep(runitStopStepDuration)
}
return bosherr.New("Failed to stop runsv for %s. Output: %s", name, lastStatusStdout)
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:33,代码来源:runit_provisioner.go
示例14: validateTemplate
func (v SemanticValidator) validateTemplate(template Template) error {
if template.Release == nil {
return bosherr.New("Missing associated release")
}
return nil
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:7,代码来源:semantic_validator.go
示例15: 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()
devicePath, found := settings.Disks.Persistent[diskCid]
if !found {
return nil, bosherr.New("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(devicePath, mountPoint)
if err != nil {
return nil, bosherr.WrapError(err, "Mounting persistent disk")
}
return map[string]string{}, nil
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:30,代码来源:mount_disk.go
示例16: Validate
func (r WatcherRec) Validate() error {
if len(r.RelSource) == 0 {
return bosherr.New("Expected release source to be non-empty")
}
if len(r.MinVersionRaw) == 0 {
return bosherr.New("Expected min version to be non-empty")
}
_, err := semiver.NewVersionFromString(r.MinVersionRaw)
if err != nil {
return bosherr.WrapError(err, "Expected min version to be a valid version")
}
return nil
}
开发者ID:pivotalservices,项目名称:bosh-hub,代码行数:16,代码来源:watcher.go
示例17: validateNetwork
func (v SemanticValidator) validateNetwork(network Network) error {
if network.Type == NetworkTypeManual {
return bosherr.New("Manual networking is not supported")
}
return nil
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:7,代码来源:semantic_validator.go
示例18: Save
func (ri DBIndex) Save(key interface{}, value interface{}) error {
rawKey, err := ri.structToMap(key)
if err != nil {
return err
}
rawKeyBytes, err := json.Marshal(rawKey)
if err != nil {
return err
}
valueBytes, err := json.Marshal(value)
if err != nil {
return err
}
res, err := ri.adapter.Save(rawKeyBytes, valueBytes)
if err != nil {
return err
}
numRows, err := res.RowsAffected()
if err != nil {
return err
}
if numRows != 1 {
return bosherr.New("Expected to update 1 entry for key '%s'; updated '%d'", rawKeyBytes, numRows)
}
return nil
}
开发者ID:pivotalservices,项目名称:bosh-hub,代码行数:32,代码来源:db_index.go
示例19: Get
func (p Provider) Get(name string) (supervisor JobSupervisor, err error) {
supervisor, found := p.supervisors[name]
if !found {
err = bosherr.New("JobSupervisor %s could not be found", name)
}
return
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:7,代码来源:provider.go
示例20: Validate
func (b retryableBlobstore) Validate() error {
if b.maxTries < 1 {
return bosherr.New("Max tries must be > 0")
}
return b.blobstore.Validate()
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:7,代码来源:retryable_blobstore.go
注:本文中的github.com/cloudfoundry/bosh-agent/errors.New函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论