56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
package generator
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
configurator "git.towk2.me/towk/configurator/pkg"
|
|
"git.towk2.me/towk/configurator/pkg/client"
|
|
"git.towk2.me/towk/configurator/pkg/config"
|
|
"git.towk2.me/towk/configurator/pkg/util"
|
|
)
|
|
|
|
type Conman struct{}
|
|
|
|
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) Generate(config *config.Config, params Params) (FileMap, error) {
|
|
var (
|
|
smdClient = client.NewSmdClient(params.ClientOpts...)
|
|
eps = []configurator.RedfishEndpoint{}
|
|
err error = nil
|
|
consoles = ""
|
|
)
|
|
|
|
// fetch required data from SMD to create config
|
|
eps, err = smdClient.FetchRedfishEndpoints(params.Verbose)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to fetch redfish endpoints with client: %v", err)
|
|
}
|
|
|
|
// 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 ApplyTemplates(Mappings{
|
|
"plugin_name": g.GetName(),
|
|
"plugin_version": g.GetVersion(),
|
|
"plugin_description": g.GetDescription(),
|
|
"server_opts": "",
|
|
"global_opts": "",
|
|
"consoles": consoles,
|
|
}, params.Templates)
|
|
}
|