refactor: more code cleanup and simplification
This commit is contained in:
parent
32065dc163
commit
a7b8fb0de5
11 changed files with 268 additions and 398 deletions
|
|
@ -4,6 +4,8 @@ import (
|
|||
"fmt"
|
||||
|
||||
configurator "github.com/OpenCHAMI/configurator/pkg"
|
||||
"github.com/OpenCHAMI/configurator/pkg/client"
|
||||
"github.com/OpenCHAMI/configurator/pkg/config"
|
||||
"github.com/OpenCHAMI/configurator/pkg/util"
|
||||
)
|
||||
|
||||
|
|
@ -21,32 +23,20 @@ func (g *Conman) GetDescription() string {
|
|||
return fmt.Sprintf("Configurator generator plugin for '%s'.", g.GetName())
|
||||
}
|
||||
|
||||
func (g *Conman) Generate(config *configurator.Config, opts ...util.Option) (FileMap, error) {
|
||||
func (g *Conman) Generate(config *config.Config, params Params) (FileMap, error) {
|
||||
var (
|
||||
params = GetParams(opts...)
|
||||
client = GetClient(params)
|
||||
targetKey = params["target"].(string) // required param
|
||||
target = config.Targets[targetKey]
|
||||
eps []configurator.RedfishEndpoint = nil
|
||||
err error = nil
|
||||
// serverOpts = ""
|
||||
// globalOpts = ""
|
||||
consoles = ""
|
||||
smdClient = client.NewSmdClient(params.ClientOpts...)
|
||||
eps = []configurator.RedfishEndpoint{}
|
||||
err error = nil
|
||||
consoles = ""
|
||||
)
|
||||
|
||||
// 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)
|
||||
}
|
||||
eps, err = smdClient.FetchRedfishEndpoints(params.Verbose)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to fetch redfish endpoints with client: %v", err)
|
||||
}
|
||||
|
||||
// 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 {
|
||||
|
|
@ -55,12 +45,12 @@ func (g *Conman) Generate(config *configurator.Config, opts ...util.Option) (Fil
|
|||
consoles += "# ====================================================================="
|
||||
|
||||
// apply template substitutions and return output as byte array
|
||||
return ApplyTemplateFromFiles(Mappings{
|
||||
return ApplyTemplates(Mappings{
|
||||
"plugin_name": g.GetName(),
|
||||
"plugin_version": g.GetVersion(),
|
||||
"plugin_description": g.GetDescription(),
|
||||
"server_opts": "",
|
||||
"global_opts": "",
|
||||
"consoles": consoles,
|
||||
}, target.TemplatePaths...)
|
||||
}, params.Templates)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue