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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
configurator "github.com/OpenCHAMI/configurator/internal"
|
configurator "github.com/OpenCHAMI/configurator/internal"
|
||||||
"github.com/OpenCHAMI/configurator/internal/generator"
|
"github.com/OpenCHAMI/configurator/internal/generator"
|
||||||
"github.com/OpenCHAMI/configurator/internal/util"
|
"github.com/OpenCHAMI/configurator/internal/util"
|
||||||
"github.com/nikolalohinski/gonja/v2"
|
|
||||||
"github.com/nikolalohinski/gonja/v2/exec"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Conman struct{}
|
type Conman struct{}
|
||||||
|
|
@ -22,25 +19,43 @@ func (g *Conman) GetGroups() []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Conman) Generate(config *configurator.Config, opts ...util.Option) ([]byte, error) {
|
func (g *Conman) Generate(config *configurator.Config, opts ...util.Option) ([]byte, error) {
|
||||||
params := generator.GetParams(opts...)
|
|
||||||
var (
|
var (
|
||||||
template = params["template"].(string)
|
params = generator.GetParams(opts...)
|
||||||
path = config.TemplatePaths[template]
|
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)
|
// fetch required data from SMD to create config
|
||||||
if err != nil {
|
if client != nil {
|
||||||
return nil, fmt.Errorf("failed to read template from file: %v", err)
|
eps, err = client.FetchRedfishEndpoints(opts...)
|
||||||
}
|
if err != nil {
|
||||||
output := "# ========== GENERATED BY OCHAMI CONFIGURATOR ==========\n"
|
return nil, fmt.Errorf("failed to fetch redfish endpoints with client: %v", err)
|
||||||
output += "# ======================================================"
|
}
|
||||||
b := bytes.Buffer{}
|
|
||||||
if err = t.Execute(&b, data); err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to execute: %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
|
var Generator Conman
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
configurator "github.com/OpenCHAMI/configurator/internal"
|
configurator "github.com/OpenCHAMI/configurator/internal"
|
||||||
"github.com/OpenCHAMI/configurator/internal/util"
|
"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) {
|
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
|
var Generator CoreDhcp
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ func (g *DnsMasq) Generate(config *configurator.Config, opts ...util.Option) ([]
|
||||||
// set all the defaults for variables
|
// set all the defaults for variables
|
||||||
var (
|
var (
|
||||||
params = generator.GetParams(opts...)
|
params = generator.GetParams(opts...)
|
||||||
|
client = generator.GetClient(params)
|
||||||
template = params["template"].(string) // required param
|
template = params["template"].(string) // required param
|
||||||
path = config.TemplatePaths[template]
|
path = config.TemplatePaths[template]
|
||||||
eths []configurator.EthernetInterface = nil
|
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 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...)
|
eths, err = client.FetchEthernetInterfaces(opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to fetch ethernet interfaces with client: %v", err)
|
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
|
// format output to write to config file
|
||||||
output := "# ========== GENERATED BY OCHAMI CONFIGURATOR ==========\n"
|
output := "# ========== DYNAMICALLY GENERATED BY OPENCHAMI CONFIGURATOR ==========\n"
|
||||||
for _, eth := range eths {
|
for _, eth := range eths {
|
||||||
if eth.Type == "NodeBMC" {
|
if eth.Type == "NodeBMC" {
|
||||||
output += "dhcp-host=" + eth.MacAddress + "," + eth.ComponentId + "," + eth.IpAddresses[0].IpAddress + "\n"
|
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 += "dhcp-host=" + eth.MacAddress + "," + eth.ComponentId + "," + eth.IpAddresses[0].IpAddress + "\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
output += "# ======================================================"
|
output += "# ====================================================================="
|
||||||
|
|
||||||
// apply template substitutions and return output as byte array
|
// apply template substitutions and return output as byte array
|
||||||
return generator.ApplyTemplate(path, generator.Mappings{
|
return generator.ApplyTemplate(path, generator.Mappings{
|
||||||
"hosts": output,
|
"name": g.GetName(),
|
||||||
|
"output": output,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
configurator "github.com/OpenCHAMI/configurator/internal"
|
configurator "github.com/OpenCHAMI/configurator/internal"
|
||||||
"github.com/OpenCHAMI/configurator/internal/util"
|
"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) {
|
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
|
var Generator Powerman
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
configurator "github.com/OpenCHAMI/configurator/internal"
|
configurator "github.com/OpenCHAMI/configurator/internal"
|
||||||
"github.com/OpenCHAMI/configurator/internal/util"
|
"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) {
|
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
|
var Generator Syslog
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue