From e92a883c89e9c64e6b1a3354588518a0189ea1bc Mon Sep 17 00:00:00 2001 From: David Allen Date: Wed, 26 Jun 2024 13:41:14 -0600 Subject: [PATCH] Update generator interface and plugins --- internal/generator/generator.go | 2 ++ internal/generator/plugins/conman/conman.go | 8 +++++ .../generator/plugins/coredhcp/coredhcp.go | 8 +++++ internal/generator/plugins/dhcpd/dhcpd.go | 8 +++++ internal/generator/plugins/dnsmasq/dnsmasq.go | 10 ++++++- .../generator/plugins/hostfile/hostfile.go | 8 +++++ .../generator/plugins/powerman/powerman.go | 8 +++-- internal/generator/plugins/syslog/syslog.go | 8 +++++ .../generator/plugins/warewulf/warewulf.go | 30 +++++++++++++++++-- 9 files changed, 85 insertions(+), 5 deletions(-) diff --git a/internal/generator/generator.go b/internal/generator/generator.go index a1840a5..45f1586 100644 --- a/internal/generator/generator.go +++ b/internal/generator/generator.go @@ -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) } diff --git a/internal/generator/plugins/conman/conman.go b/internal/generator/plugins/conman/conman.go index 450f383..4fcef2c 100644 --- a/internal/generator/plugins/conman/conman.go +++ b/internal/generator/plugins/conman/conman.go @@ -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{""} } diff --git a/internal/generator/plugins/coredhcp/coredhcp.go b/internal/generator/plugins/coredhcp/coredhcp.go index ea0f2c1..9b76227 100644 --- a/internal/generator/plugins/coredhcp/coredhcp.go +++ b/internal/generator/plugins/coredhcp/coredhcp.go @@ -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") } diff --git a/internal/generator/plugins/dhcpd/dhcpd.go b/internal/generator/plugins/dhcpd/dhcpd.go index edd09bb..a56732e 100644 --- a/internal/generator/plugins/dhcpd/dhcpd.go +++ b/internal/generator/plugins/dhcpd/dhcpd.go @@ -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...) diff --git a/internal/generator/plugins/dnsmasq/dnsmasq.go b/internal/generator/plugins/dnsmasq/dnsmasq.go index 2795623..b1b71a7 100644 --- a/internal/generator/plugins/dnsmasq/dnsmasq.go +++ b/internal/generator/plugins/dnsmasq/dnsmasq.go @@ -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)) } } diff --git a/internal/generator/plugins/hostfile/hostfile.go b/internal/generator/plugins/hostfile/hostfile.go index ae3fba3..9c66f3a 100644 --- a/internal/generator/plugins/hostfile/hostfile.go +++ b/internal/generator/plugins/hostfile/hostfile.go @@ -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") } diff --git a/internal/generator/plugins/powerman/powerman.go b/internal/generator/plugins/powerman/powerman.go index 37263e5..9f68dd7 100644 --- a/internal/generator/plugins/powerman/powerman.go +++ b/internal/generator/plugins/powerman/powerman.go @@ -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) { diff --git a/internal/generator/plugins/syslog/syslog.go b/internal/generator/plugins/syslog/syslog.go index a50fba3..f9caf40 100644 --- a/internal/generator/plugins/syslog/syslog.go +++ b/internal/generator/plugins/syslog/syslog.go @@ -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") } diff --git a/internal/generator/plugins/warewulf/warewulf.go b/internal/generator/plugins/warewulf/warewulf.go index 477815f..7999afa 100644 --- a/internal/generator/plugins/warewulf/warewulf.go +++ b/internal/generator/plugins/warewulf/warewulf.go @@ -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 {