当前位置: 首页>>代码示例>>Golang>>正文


Golang utils.FormatError函数代码示例

本文整理汇总了Golang中github.com/dorzheh/deployer/utils.FormatError函数的典型用法代码示例。如果您正苦于以下问题:Golang FormatError函数的具体用法?Golang FormatError怎么用?Golang FormatError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了FormatError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ProcessHooks

// ProcessHooks is intended for executing appropriate hooks.
// The hooks must contain the following prefix : [0-9]+_
// If arguments are being passed to the function, they will be
// passed tp the hooks as well
// Example:
// 01_pre_deploy
// 02_deploy
// 03_post_deploy
// 04_clean
func ProcessHooks(pathToHooksDir string, hookArgs ...string) error {
	d, err := os.Stat(pathToHooksDir)
	if err != nil {
		return utils.FormatError(err)
	}
	if !d.IsDir() {
		return utils.FormatError(fmt.Errorf("%s is not directory", d.Name()))
	}

	var scriptsSlice []string
	err = filepath.Walk(pathToHooksDir, func(scriptName string, info os.FileInfo, err error) error {
		if !info.IsDir() {
			if found, _ := regexp.MatchString("[0-9]+_", scriptName); found {
				scriptsSlice = append(scriptsSlice, scriptName)
			}
		}
		return nil
	})
	sort.Strings(scriptsSlice)
	for _, file := range scriptsSlice {
		if err := exec.Command(file, hookArgs[0:]...).Run(); err != nil {
			return utils.FormatError(err)
		}
	}
	return nil
}
开发者ID:weldpua2008,项目名称:deployer,代码行数:35,代码来源:customize.go

示例2: Run

func (b *MetadataBuilder) Run() (deployer.Artifact, error) {
	// in case no source template exists apparently we should use the default metadata
	_, err := os.Stat(b.Source)
	if err != nil {
		b.Source = b.Dest
	}

	f, err := ioutil.ReadFile(b.Source)
	if err != nil {
		return nil, utils.FormatError(err)
	}

	data, err := utils.ProcessTemplate(string(f), b.UserData)
	if err != nil {
		return nil, utils.FormatError(err)
	}

	run := utils.RunFunc(b.SshConfig)
	if _, err := run(fmt.Sprintf("echo \"%s\" > %s", data, b.Dest)); err != nil {
		return nil, utils.FormatError(err)
	}
	return &deployer.CommonArtifact{
		Name: filepath.Base(b.Dest),
		Path: b.Dest,
		Type: deployer.MetadataArtifact,
	}, nil
}
开发者ID:weldpua2008,项目名称:deployer,代码行数:27,代码来源:builders.go

示例3: Customize

// ImageCustomize treating image customization according to XML config files
// Returns error or nil
func Customize(pathToSlash, pathToConfigDir string) error {
	//install/deinstall appropriate packages
	pathToXml := pathToConfigDir + "/packages.xml"
	if _, err := os.Stat(pathToXml); err == nil {
		if err := packageManip(pathToXml, pathToSlash); err != nil {
			return utils.FormatError(err)
		}
	}
	// inject appropriate stuff
	pathToXml = pathToConfigDir + "/inject_items.xml"
	if _, err := os.Stat(pathToXml); err == nil {
		if err := injectManip(pathToXml, pathToSlash); err != nil {
			return utils.FormatError(err)
		}
	}
	// services manipulation
	pathToXml = pathToConfigDir + "/services.xml"
	if _, err := os.Stat(pathToXml); err == nil {
		if err := serviceManip(pathToXml, pathToSlash); err != nil {
			return utils.FormatError(err)
		}
	}
	// file content modification
	pathToXml = pathToConfigDir + "/files_content.xml"
	if _, err := os.Stat(pathToXml); err == nil {
		if err := filesContentManip(pathToXml, pathToSlash); err != nil {
			return utils.FormatError(err)
		}
	}
	return nil
}
开发者ID:weldpua2008,项目名称:deployer,代码行数:33,代码来源:customize.go

示例4: Emulator

// Emulator returns appropriate path to QEMU emulator for a given architecture
func (d *Driver) Emulator(arch string) (string, error) {
	switch arch {
	case "x86_64":
	case "i686":
	default:
		return "", utils.FormatError(fmt.Errorf("Unsupported architecture(%s).Only i686 and x86_64 supported", arch))
	}

	out, err := d.Run("virsh capabilities")
	if err != nil {
		return "", utils.FormatError(err)
	}

	m, err := mxj.NewMapXml([]byte(out))
	if err != nil {
		return "", utils.FormatError(err)
	}

	v, _ := m.ValuesForPath("capabilities.guest.arch", "-name:"+arch)
	// fixing https://github.com/dorzheh/deployer/issues/2
	if len(v) == 0 {
		return "", utils.FormatError(fmt.Errorf("Can't gather a KVM guest information for architecture %s.", arch))
	}
	return v[0].(map[string]interface{})["emulator"].(string), nil

}
开发者ID:weldpua2008,项目名称:deployer,代码行数:27,代码来源:driver.go

示例5: CreateConfig

func CreateConfig(d *deployer.CommonData, i *metadata.InputData) (*metadata.Config, error) {
	if d.DefaultExportDir == "" {
		d.DefaultExportDir = "/var/lib/libvirt/images"
	}

	m, err := metadata.NewMetdataConfig(d, i.StorageConfigFile)
	if err != nil {
		return nil, utils.FormatError(err)
	}

	controller.RegisterSteps(func() func() error {
		return func() error {
			var err error
			m.Hwdriver, err = hwinfodriver.NewHostinfoDriver(m.SshConfig, i.Lshw, filepath.Join(d.RootDir, ".hwinfo.json"))
			if err != nil {
				return utils.FormatError(err)
			}

			m.Metadata = new(metadata.Metadata)
			m.EnvDriver = envdriver.NewDriver(m.SshConfig)
			if m.Metadata.EmulatorPath, err = m.EnvDriver.Emulator(d.Arch); err != nil {
				return utils.FormatError(err)
			}
			return controller.SkipStep
		}
	}())

	if err := metadata.RegisterSteps(d, i, m, &meta{}); err != nil {
		return nil, utils.FormatError(err)
	}
	return m, nil
}
开发者ID:weldpua2008,项目名称:deployer,代码行数:32,代码来源:config.go

示例6: Deploy

// Deploy is implementing entire flow
// The flow consists of the following stages:
// - CreateConfig creates appropriate configuration(user interaction against UI).
// - CreateBuilders creates appropriate builders and passes them to the build process
// - CreatePostProcessors creates appropriate post-processors and passes them for post-processing
func Deploy(c *deployer.CommonData, f deployer.FlowCreator) error {
	if err := f.CreateConfig(c); err != nil {
		return utils.FormatError(err)
	}

	builders, err := f.CreateBuilders(c)
	if err != nil {
		return utils.FormatError(err)
	}

	artifacts, err := deployer.BuildProgress(c, builders)
	if err != nil {
		return utils.FormatError(err)
	}

	post, err := f.CreatePostProcessor(c)
	if err != nil {
		return utils.FormatError(err)
	}
	if post != nil {
		err := deployer.PostProcessProgress(c, post, artifacts)
		if err != nil {
			return utils.FormatError(err)
		}
	}
	return nil
}
开发者ID:weldpua2008,项目名称:deployer,代码行数:32,代码来源:deploy.go

示例7: Build

// Build iterates over a slice of builders and runs
// each builder in a separated goroutine.
// Returns a slice of artifacts.
func Build(builders []Builder) ([]Artifact, error) {
	dur, err := time.ParseDuration("1s")
	if err != nil {
		return nil, utils.FormatError(err)
	}

	runtime.GOMAXPROCS(runtime.NumCPU() - 1)

	var artifacts []Artifact
	ch := make(chan *buildResult, len(builders))

	for _, b := range builders {
		time.Sleep(dur)
		go func(b Builder) {
			artifact, err := b.Run()
			// Forwards created artifact to the channel.
			ch <- &buildResult{artifact, err}
		}(b)
	}
	for i := 0; i < len(builders); i++ {
		select {
		case result := <-ch:
			if result.err != nil {
				//defer close(ch)
				return nil, utils.FormatError(result.err)
			}
			artifacts = append(artifacts, result.artifact)
		}
	}
	return artifacts, nil
}
开发者ID:weldpua2008,项目名称:deployer,代码行数:34,代码来源:build.go

示例8: ProcessNetworkTemplate

func ProcessNetworkTemplate(mode *xmlinput.Mode, defaultTemplate string, tmpltData interface{}, templatesDir string) (string, error) {
	var customTemplate string

	if mode.Tmplt == nil {
		customTemplate = defaultTemplate
	} else {
		var templatePath string
		if templatesDir != "" {
			templatePath = filepath.Join(templatesDir, mode.Tmplt.FileName)
		} else {
			templatePath = filepath.Join(mode.Tmplt.Dir, mode.Tmplt.FileName)
		}

		buf, err := ioutil.ReadFile(templatePath)
		if err != nil {
			return "", utils.FormatError(err)
		}
		customTemplate = string(buf)
	}

	tempData, err := utils.ProcessTemplate(customTemplate, tmpltData)
	if err != nil {
		return "", utils.FormatError(err)
	}
	return string(tempData) + "\n", nil
}
开发者ID:weldpua2008,项目名称:deployer,代码行数:26,代码来源:config.go

示例9: verify

func verify(data *XMLInputData) error {
	if data.Networks.Configure {
		for _, net := range data.Networks.Configs {
			seenDirect := false
			seenPassthrough := false
			for _, mode := range net.Modes {
				switch mode.Type {
				case ConTypeDirect:
					seenDirect = true
				case ConTypePassthrough:
					seenPassthrough = true
				case ConTypeBridged, ConTypeOVS, ConTypeVirtualNetwork, ConTypeSRIOV:
				default:
					return utils.FormatError(errors.New("unexpected mode " + string(mode.Type)))
				}
			}
			if seenDirect && seenPassthrough {
				return utils.FormatError(errors.New("either \"direct\" or\"passthrough\" permitted"))
			}
		}
		for _, nic := range data.HostNics.Allowed {
			if nic.Disjunction && nic.Priority {
				return utils.FormatError(errors.New("either \"priority\" or\"disjunction\" permitted"))
			}
		}
	}
	return nil
}
开发者ID:weldpua2008,项目名称:deployer,代码行数:28,代码来源:xmlinput.go

示例10: getMappers

// getMappers is responsible for finding mappers bound to appropriate loop device
// and providing the stuff as a slice
func (i *image) getMappers(loopDeviceName string) ([]string, error) {
	var mappers []string
	if _, err := i.run(i.utils.Kpartx + " -a " + loopDeviceName); err != nil {
		return mappers, utils.FormatError(err)
	}
	// somehow on RHEL based systems refresh might take some time therefore
	// no mappers are available until then
	duration, err := time.ParseDuration("1s")
	if err != nil {
		return mappers, utils.FormatError(err)
	}
	time.Sleep(duration)

	cmd := fmt.Sprintf("find /dev -name loop%sp[0-9]",
		strings.TrimSpace(strings.SplitAfter(loopDeviceName, "/dev/loop")[1]))
	out, err := i.run(cmd)
	if err != nil {
		return mappers, utils.FormatError(fmt.Errorf("%s [%v]", out, err))
	}
	for _, line := range strings.Split(out, "\n") {
		if line != "" {
			mappers = append(mappers, line)
		}
	}
	if len(mappers) == 0 {
		return mappers, utils.FormatError(errors.New("mappers not found"))
	}
	sort.Strings(mappers)
	return mappers, nil
}
开发者ID:weldpua2008,项目名称:deployer,代码行数:32,代码来源:image.go

示例11: addMapper

// addMapper registers appropriate mapper and it's mount point
func (i *image) addMapper(mapperDeviceName, path string) error {
	mountPoint := filepath.Join(i.slashpath, path)
	if out, err := i.run("mkdir -p " + mountPoint); err != nil {
		return utils.FormatError(fmt.Errorf("%s [%v]", out, err))
	}
	// check if the volume is already mounted
	mounted, err := isMounted(mapperDeviceName)
	if err != nil {
		return utils.FormatError(err)
	}
	if !mounted {
		if out, err := i.run(fmt.Sprintf("mount %s %s", mapperDeviceName, mountPoint)); err != nil {
			return utils.FormatError(fmt.Errorf("%s [%v]", out, err))
		}
	}
	// add mapper
	i.mappers = append(i.mappers,
		&mapperDevice{
			name:       mapperDeviceName,
			mountPoint: mountPoint,
		},
	)
	// advance amount of mappers
	i.loopDevice.amountOfMappers++
	return nil
}
开发者ID:weldpua2008,项目名称:deployer,代码行数:27,代码来源:image.go

示例12: ParseXMLInput

// ParseXMLInputFile is responsible for parsing a given configuration file
// representing appropriate input data to a srtuctured form
func ParseXMLInput(config string) (*XMLInputData, error) {
	d, err := utils.ParseXMLFile(config, new(XMLInputData))
	if err != nil {
		return nil, utils.FormatError(err)
	}
	if err := verify(d.(*XMLInputData)); err != nil {
		return nil, utils.FormatError(err)
	}
	return d.(*XMLInputData), nil
}
开发者ID:weldpua2008,项目名称:deployer,代码行数:12,代码来源:xmlinput.go

示例13: ParseXMLInputBuf

// ParseXMLInputBuf is responsible for parsing a given stream of bytes
// representing appropriate input data to a srtuctured form
func ParseXMLInputBuf(data []byte) (*XMLInputData, error) {
	d, err := utils.ParseXMLBuff(data, new(XMLInputData))
	if err != nil {
		return nil, utils.FormatError(err)
	}
	if err := verify(d.(*XMLInputData)); err != nil {
		return nil, utils.FormatError(err)
	}
	return d.(*XMLInputData), nil
}
开发者ID:weldpua2008,项目名称:deployer,代码行数:12,代码来源:xmlinput.go

示例14: NewParserBuff

func NewParserBuff(bundleConfigStream []byte, s BundleStrategy) (*Parser, error) {
	if s == nil {
		return nil, utils.FormatError(errors.New("bundle strategy is nil"))
	}
	data, err := utils.ParseXMLBuff(bundleConfigStream, s)
	if err != nil {
		return nil, utils.FormatError(err)
	}
	return &Parser{s, data}, nil
}
开发者ID:weldpua2008,项目名称:deployer,代码行数:10,代码来源:parser.go

示例15: NewParser

func NewParser(bundleConfigFile string, s BundleStrategy) (*Parser, error) {
	if s == nil {
		return nil, utils.FormatError(errors.New("bundle strategy is nil"))
	}

	data, err := utils.ParseXMLFile(bundleConfigFile, s)
	if err != nil {
		return nil, utils.FormatError(err)
	}
	return &Parser{s, data}, nil
}
开发者ID:weldpua2008,项目名称:deployer,代码行数:11,代码来源:parser.go


注:本文中的github.com/dorzheh/deployer/utils.FormatError函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。