Files
warewulf/internal/app/wwctl/node/add/main.go
Jonathon Anderson 2319906d97 Fix writing of nodes.conf
The caching functionality of nodes.conf, and the optional persistence
functionality that came with it, appears to have been preventing
actually writing the configuration to disk in all cases. This change
fixes the ability to write to nodes.conf.

Somewhat opinionatedly, this change removes the caching functionality of
nodes.conf. The tests have also been updated to use real files for i/o
rather than tying into the caching system, making them more accurately
test the ability of Warewulf to actually read and write its
configuration.

Fixes #779

Signed-off-by: Jonathon Anderson <janderson@ciq.co>
2023-04-14 10:53:31 -06:00

49 lines
1.4 KiB
Go

package add
import (
"gopkg.in/yaml.v2"
apinode "github.com/hpcng/warewulf/internal/pkg/api/node"
"github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
)
/*
RunE needs a function of type func(*cobraCommand,[]string) err, but
in order to avoid global variables which mess up testing a function of
the required type is returned
*/
func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
// run converters for different types
for _, c := range vars.converters {
if err := c(); err != nil {
return err
}
}
// remove the default network as all network values are assigned
// to this network
if _, ok := vars.nodeConf.NetDevs["default"]; ok && vars.netName != "" {
netDev := *vars.nodeConf.NetDevs["default"]
vars.nodeConf.NetDevs[vars.netName] = &netDev
delete(vars.nodeConf.NetDevs, "default")
} else {
if vars.nodeConf.NetDevs["default"].Empty() {
delete(vars.nodeConf.NetDevs, "default")
}
}
buffer, err := yaml.Marshal(vars.nodeConf)
if err != nil {
wwlog.Error("Can't marshall nodeInfo", err)
return err
}
set := wwapiv1.NodeAddParameter{
NodeConfYaml: string(buffer[:]),
NodeNames: args,
Force: true,
}
return apinode.NodeAdd(&set)
}
}