Beispiel #1
0
// GetDeploySpecs searches the working directory of wd to find otpl-deploy
// config files in their standard locations (config/{cluster-name}), and
// converts them to sous.DeploySpecs.
func (dsp *DeploySpecParser) GetDeploySpecs(wd shell.Shell) sous.DeploySpecs {
	wd = wd.Clone()
	if err := wd.CD("config"); err != nil {
		return nil
	}
	l, err := wd.List()
	if err != nil {
		dsp.debug(err)
		return nil
	}
	c := make(chan namedDeploySpec)
	wg := sync.WaitGroup{}
	wg.Add(len(l))
	go func() { wg.Wait(); close(c) }()
	for _, f := range l {
		f := f
		go func() {
			defer wg.Done()
			if !f.IsDir() {
				return
			}
			wd := wd.Clone()
			if err := wd.CD(f.Name()); err != nil {
				dsp.debug(err)
				return
			}
			if otplConfig := dsp.GetSingleDeploySpec(wd); otplConfig != nil {
				name := path.Base(wd.Dir())
				c <- namedDeploySpec{name, otplConfig}
			}
		}()
	}
	deployConfigs := sous.DeploySpecs{}
	for s := range c {
		deployConfigs[s.Name] = *s.Spec
	}
	return deployConfigs
}