mirror of
https://github.com/davidallendj/configurator.git
synced 2025-12-20 11:37:00 -07:00
44 lines
980 B
Go
44 lines
980 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
|
|
configurator "github.com/OpenCHAMI/configurator/internal"
|
|
"github.com/nikolalohinski/gonja/v2"
|
|
"github.com/nikolalohinski/gonja/v2/exec"
|
|
)
|
|
|
|
type Warewulf struct{}
|
|
|
|
func (g *Warewulf) GetName() string {
|
|
return "warewulf"
|
|
}
|
|
|
|
func (g *Warewulf) GetGroups() []string {
|
|
return []string{"warewulf"}
|
|
}
|
|
|
|
func (g *Warewulf) Generate(config *configurator.Config, template string) ([]byte, error) {
|
|
var (
|
|
path = config.TemplatePaths[template]
|
|
)
|
|
|
|
t, err := gonja.FromFile(path)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to read template from file: %v", err)
|
|
}
|
|
output := "# ========== GENERATED BY OCHAMI CONFIGURATOR ==========\n"
|
|
|
|
output += "# ======================================================"
|
|
data := exec.NewContext(map[string]any{
|
|
"hosts": output,
|
|
})
|
|
b := bytes.Buffer{}
|
|
if err = t.Execute(&b, data); err != nil {
|
|
return nil, fmt.Errorf("failed to execute: %v", err)
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
var Generator Warewulf
|