Update generator interface and plugins

This commit is contained in:
David Allen 2024-06-26 13:41:14 -06:00
parent 30c8336ca6
commit e92a883c89
No known key found for this signature in database
GPG key ID: 717C593FF60A2ACC
9 changed files with 85 additions and 5 deletions

View file

@ -19,6 +19,8 @@ type Mappings = map[string]any
type Files = map[string][]byte
type Generator interface {
GetName() string
GetVersion() string
GetDescription() string
Generate(config *configurator.Config, opts ...util.Option) (Files, error)
}

View file

@ -14,6 +14,14 @@ func (g *Conman) GetName() string {
return "conman"
}
func (g *Conman) GetVersion() string {
return util.GitCommit()
}
func (g *Conman) GetDescription() string {
return fmt.Sprintf("Configurator generator plugin for '%s'.", g.GetName())
}
func (g *Conman) GetGroups() []string {
return []string{""}
}

View file

@ -13,6 +13,14 @@ func (g *CoreDhcp) GetName() string {
return "coredhcp"
}
func (g *CoreDhcp) GetVersion() string {
return util.GitCommit()
}
func (g *CoreDhcp) GetDescription() string {
return fmt.Sprintf("Configurator generator plugin for '%s' to generate config files. This plugin is not complete and still a WIP.", g.GetName())
}
func (g *CoreDhcp) Generate(config *configurator.Config, opts ...util.Option) (map[string][]byte, error) {
return nil, fmt.Errorf("plugin does not implement generation function")
}

View file

@ -14,6 +14,14 @@ func (g *Dhcpd) GetName() string {
return "dhcpd"
}
func (g *Dhcpd) GetVersion() string {
return util.GitCommit()
}
func (g *Dhcpd) GetDescription() string {
return fmt.Sprintf("Configurator generator plugin for '%s'.", g.GetName())
}
func (g *Dhcpd) Generate(config *configurator.Config, opts ...util.Option) (generator.Files, error) {
var (
params = generator.GetParams(opts...)

View file

@ -15,6 +15,14 @@ func (g *DnsMasq) GetName() string {
return "dnsmasq"
}
func (g *DnsMasq) GetVersion() string {
return util.GitCommit()
}
func (g *DnsMasq) GetDescription() string {
return fmt.Sprintf("Configurator generator plugin for '%s'.", g.GetName())
}
func (g *DnsMasq) Generate(config *configurator.Config, opts ...util.Option) (map[string][]byte, error) {
// make sure we have a valid config first
if config == nil {
@ -50,7 +58,7 @@ func (g *DnsMasq) Generate(config *configurator.Config, opts ...util.Option) (ma
// print message if verbose param found
if verbose, ok := params["verbose"].(bool); ok {
if verbose {
fmt.Printf("template: \n%s\n ethernet interfaces found: %v\n", strings.Join(target.Templates, "\n\t"), len(eths))
fmt.Printf("template: \n%s\nethernet interfaces found: %v\n", strings.Join(target.Templates, "\n\t"), len(eths))
}
}

View file

@ -13,6 +13,14 @@ func (g *Hostfile) GetName() string {
return "hostfile"
}
func (g *Hostfile) GetVersion() string {
return util.GitCommit()
}
func (g *Hostfile) GetDescription() string {
return fmt.Sprintf("Configurator generator plugin for '%s'.", g.GetName())
}
func (g *Hostfile) Generate(config *configurator.Config, opts ...util.Option) (map[string][]byte, error) {
return nil, fmt.Errorf("plugin does not implement generation function")
}

View file

@ -13,8 +13,12 @@ func (g *Powerman) GetName() string {
return "powerman"
}
func (g *Powerman) GetGroups() []string {
return []string{"powerman"}
func (g *Powerman) GetVersion() string {
return util.GitCommit()
}
func (g *Powerman) GetDescription() string {
return fmt.Sprintf("Configurator generator plugin for '%s'.", g.GetName())
}
func (g *Powerman) Generate(config *configurator.Config, opts ...util.Option) (map[string][]byte, error) {

View file

@ -13,6 +13,14 @@ func (g *Syslog) GetName() string {
return "syslog"
}
func (g *Syslog) GetVersion() string {
return util.GitCommit()
}
func (g *Syslog) GetDescription() string {
return fmt.Sprintf("Configurator generator plugin for '%s'.", g.GetName())
}
func (g *Syslog) Generate(config *configurator.Config, opts ...util.Option) (map[string][]byte, error) {
return nil, fmt.Errorf("plugin does not implement generation function")
}

View file

@ -3,6 +3,7 @@ package main
import (
"fmt"
"maps"
"strings"
configurator "github.com/OpenCHAMI/configurator/internal"
"github.com/OpenCHAMI/configurator/internal/generator"
@ -15,8 +16,12 @@ func (g *Warewulf) GetName() string {
return "warewulf"
}
func (g *Warewulf) GetGroups() []string {
return []string{"warewulf"}
func (g *Warewulf) GetVersion() string {
return util.GitCommit()
}
func (g *Warewulf) GetDescription() string {
return "Configurator generator plugin for 'warewulf' config files."
}
func (g *Warewulf) Generate(config *configurator.Config, opts ...util.Option) (generator.Files, error) {
@ -33,6 +38,27 @@ func (g *Warewulf) Generate(config *configurator.Config, opts ...util.Option) (g
return nil, fmt.Errorf("invalid client (client is nil)")
}
// if we have a client, try making the request for the ethernet interfaces
eths, err := client.FetchEthernetInterfaces(opts...)
if err != nil {
return nil, fmt.Errorf("failed to fetch ethernet interfaces with client: %v", err)
}
// check if we have the required params first
if eths == nil {
return nil, fmt.Errorf("invalid ethernet interfaces (variable is nil)")
}
if len(eths) <= 0 {
return nil, fmt.Errorf("no ethernet interfaces found")
}
// print message if verbose param found
if verbose, ok := params["verbose"].(bool); ok {
if verbose {
fmt.Printf("template: \n%s\n ethernet interfaces found: %v\n", strings.Join(target.Templates, "\n\t"), len(eths))
}
}
// fetch redfish endpoints and handle errors
eps, err := client.FetchRedfishEndpoints(opts...)
if err != nil {