本文整理匯總了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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}