Update generator interface and plugins
This commit is contained in:
parent
30c8336ca6
commit
e92a883c89
9 changed files with 85 additions and 5 deletions
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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{""}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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...)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue