mirror of
https://github.com/davidallendj/configurator.git
synced 2025-12-20 03:27:02 -07:00
Updated generator plugin implementations
This commit is contained in:
parent
22195fa00a
commit
121c7b9f9c
5 changed files with 47 additions and 24 deletions
|
|
@ -1,14 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
configurator "github.com/OpenCHAMI/configurator/internal"
|
||||
"github.com/OpenCHAMI/configurator/internal/generator"
|
||||
"github.com/OpenCHAMI/configurator/internal/util"
|
||||
"github.com/nikolalohinski/gonja/v2"
|
||||
"github.com/nikolalohinski/gonja/v2/exec"
|
||||
)
|
||||
|
||||
type Conman struct{}
|
||||
|
|
@ -22,25 +19,43 @@ func (g *Conman) GetGroups() []string {
|
|||
}
|
||||
|
||||
func (g *Conman) Generate(config *configurator.Config, opts ...util.Option) ([]byte, error) {
|
||||
params := generator.GetParams(opts...)
|
||||
var (
|
||||
template = params["template"].(string)
|
||||
path = config.TemplatePaths[template]
|
||||
params = generator.GetParams(opts...)
|
||||
client = generator.GetClient(params)
|
||||
template = params["template"].(string) // required param
|
||||
path = config.TemplatePaths[template]
|
||||
eps []configurator.RedfishEndpoint = nil
|
||||
err error = nil
|
||||
// serverOpts = ""
|
||||
// globalOpts = ""
|
||||
consoles = ""
|
||||
)
|
||||
data := exec.NewContext(map[string]any{})
|
||||
|
||||
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 += "# ======================================================"
|
||||
b := bytes.Buffer{}
|
||||
if err = t.Execute(&b, data); err != nil {
|
||||
return nil, fmt.Errorf("failed to execute: %v", err)
|
||||
// fetch required data from SMD to create config
|
||||
if client != nil {
|
||||
eps, err = client.FetchRedfishEndpoints(opts...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to fetch redfish endpoints with client: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return b.Bytes(), nil
|
||||
// add any additional conman or server opts
|
||||
// if extraOpts, ok := params["opts"].(map[string]any); ok {
|
||||
|
||||
// }
|
||||
|
||||
// format output to write to config file
|
||||
consoles = "# ========== DYNAMICALLY GENERATED BY OPENCHAMI CONFIGURATOR ==========\n"
|
||||
for _, ep := range eps {
|
||||
consoles += fmt.Sprintf("CONSOLE name=%s dev=ipmi:%s-bmc ipmiopts=U:%s,P:%s,W:solpayloadsize\n", ep.Name, ep.Name, ep.User, ep.Password)
|
||||
}
|
||||
consoles += "# ====================================================================="
|
||||
|
||||
// apply template substitutions and return output as byte array
|
||||
return generator.ApplyTemplate(path, generator.Mappings{
|
||||
"server_opts": "",
|
||||
"global_opts": "",
|
||||
})
|
||||
}
|
||||
|
||||
var Generator Conman
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
configurator "github.com/OpenCHAMI/configurator/internal"
|
||||
"github.com/OpenCHAMI/configurator/internal/util"
|
||||
)
|
||||
|
|
@ -16,7 +18,7 @@ func (g *CoreDhcp) GetGroups() []string {
|
|||
}
|
||||
|
||||
func (g *CoreDhcp) Generate(config *configurator.Config, opts ...util.Option) ([]byte, error) {
|
||||
return nil, nil
|
||||
return nil, fmt.Errorf("plugin does not implement generation function")
|
||||
}
|
||||
|
||||
var Generator CoreDhcp
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ func (g *DnsMasq) Generate(config *configurator.Config, opts ...util.Option) ([]
|
|||
// set all the defaults for variables
|
||||
var (
|
||||
params = generator.GetParams(opts...)
|
||||
client = generator.GetClient(params)
|
||||
template = params["template"].(string) // required param
|
||||
path = config.TemplatePaths[template]
|
||||
eths []configurator.EthernetInterface = nil
|
||||
|
|
@ -47,7 +48,7 @@ func (g *DnsMasq) Generate(config *configurator.Config, opts ...util.Option) ([]
|
|||
)
|
||||
|
||||
// if we have a client, try making the request for the ethernet interfaces
|
||||
if client, ok := params["client"].(configurator.SmdClient); ok {
|
||||
if client != nil {
|
||||
eths, err = client.FetchEthernetInterfaces(opts...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to fetch ethernet interfaces with client: %v", err)
|
||||
|
|
@ -70,7 +71,7 @@ func (g *DnsMasq) Generate(config *configurator.Config, opts ...util.Option) ([]
|
|||
}
|
||||
|
||||
// format output to write to config file
|
||||
output := "# ========== GENERATED BY OCHAMI CONFIGURATOR ==========\n"
|
||||
output := "# ========== DYNAMICALLY GENERATED BY OPENCHAMI CONFIGURATOR ==========\n"
|
||||
for _, eth := range eths {
|
||||
if eth.Type == "NodeBMC" {
|
||||
output += "dhcp-host=" + eth.MacAddress + "," + eth.ComponentId + "," + eth.IpAddresses[0].IpAddress + "\n"
|
||||
|
|
@ -78,11 +79,12 @@ func (g *DnsMasq) Generate(config *configurator.Config, opts ...util.Option) ([]
|
|||
output += "dhcp-host=" + eth.MacAddress + "," + eth.ComponentId + "," + eth.IpAddresses[0].IpAddress + "\n"
|
||||
}
|
||||
}
|
||||
output += "# ======================================================"
|
||||
output += "# ====================================================================="
|
||||
|
||||
// apply template substitutions and return output as byte array
|
||||
return generator.ApplyTemplate(path, generator.Mappings{
|
||||
"hosts": output,
|
||||
"name": g.GetName(),
|
||||
"output": output,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
configurator "github.com/OpenCHAMI/configurator/internal"
|
||||
"github.com/OpenCHAMI/configurator/internal/util"
|
||||
)
|
||||
|
|
@ -16,7 +18,7 @@ func (g *Powerman) GetGroups() []string {
|
|||
}
|
||||
|
||||
func (g *Powerman) Generate(config *configurator.Config, opts ...util.Option) ([]byte, error) {
|
||||
return nil, nil
|
||||
return nil, fmt.Errorf("plugin does not implement generation function")
|
||||
}
|
||||
|
||||
var Generator Powerman
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
configurator "github.com/OpenCHAMI/configurator/internal"
|
||||
"github.com/OpenCHAMI/configurator/internal/util"
|
||||
)
|
||||
|
|
@ -16,7 +18,7 @@ func (g *Syslog) GetGroups() []string {
|
|||
}
|
||||
|
||||
func (g *Syslog) Generate(config *configurator.Config, opts ...util.Option) ([]byte, error) {
|
||||
return nil, nil
|
||||
return nil, fmt.Errorf("plugin does not implement generation function")
|
||||
}
|
||||
|
||||
var Generator Syslog
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue