Exemple #1
0
//ReadMainFile will read the Nulecule file and fill the MainfileData field
func (b *Base) ReadMainFile() error {
	//Check for valid path
	targetFile := filepath.Join(b.Target(), constants.MAIN_FILE)
	if !utils.PathExists(targetFile) {
		logrus.Fatalf("Could not find %s file in %s", constants.MAIN_FILE, b.Target())
		return errors.New("File does not exist")
	}

	//Attempt to parse
	p := parser.NewParser(targetFile)
	err := p.Unmarshal(b.MainfileData)
	if err != nil {
		logrus.Errorf("Error parsing Nulecule file: %v", err)
		return err
	}
	return nil
}
Exemple #2
0
//Undeploy the kubernetes provider and reset replication controllers
func (p *Kubernetes) Undeploy() error {
	for _, artifact := range p.Artifacts() {
		base := filepath.Base(artifact)
		fullPath := filepath.Join(p.WorkDirectory(), base)

		markupParser := parser.NewParser(fullPath)
		result := &kubeConfig{}
		markupParser.Unmarshal(result)
		name := result.Metadata.Name
		kind := result.Kind

		if isReplicationController(kind) {
			p.resetReplica(name)
		}
		p.deletePod(fullPath)
	}
	return nil
}
Exemple #3
0
//LoadAnswers Unmarshals the answers from the answers.conf file into the base AnswersData
func (b *Base) LoadAnswers() error {
	//if a directory was provided...
	fp := b.AnswersDir()
	if utils.PathIsDirectory(fp) {
		//Construct the full path by combining with the ANSWERS_FILE constant
		fp = filepath.Join(fp, constants.ANSWERS_FILE)
		if !utils.PathExists(fp) {
			return errors.New("Failed to read answers from path")
		}
	}
	//..try to parse the file
	if !utils.PathExists(fp) {
		return errors.New("Bad answers filepath")
	}
	p := parser.NewParser(fp)
	err := p.Unmarshal(&b.AnswersData)
	if err != nil {
		return errors.New("Failed to parse file")
	}
	return nil
}