Files
warewulf/internal/app/wwctl/node/add/main.go
Christian Goll d3af143a5b main_tests are not working as expected
The global values which store the flags are not regenerated during test

Signed-off-by: Christian Goll <cgoll@suse.de>
2023-03-07 17:01:57 +01:00

38 lines
915 B
Go

package add
import (
"os"
"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"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
// remove the default network as all network values are assigned
// to this network
if _, ok := NodeConf.NetDevs["default"]; ok && NetName != "" {
netDev := *NodeConf.NetDevs["default"]
NodeConf.NetDevs[NetName] = &netDev
delete(NodeConf.NetDevs, "default")
} else {
if NodeConf.NetDevs["default"].Empty() {
delete(NodeConf.NetDevs, "default")
}
}
buffer, err := yaml.Marshal(NodeConf)
if err != nil {
wwlog.Error("Cant marshall nodeInfo", err)
os.Exit(1)
}
set := wwapiv1.NodeAddParameter{
NodeConfYaml: string(buffer[:]),
NodeNames: args,
}
return apinode.NodeAdd(&set)
}