Files
warewulf/internal/app/wwctl/node/set/main.go
Christian Goll b0602133ec use netParseIP and ParseMAC
check also MAC addresses and common formating

Signed-off-by: Christian Goll <cgoll@suse.de>

reformat ipaddr for test coverage

fixed processing of default values

updated transformer tests

correct behavior for tags

add tests for tags

new tests for primary network

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

57 lines
1.4 KiB
Go

package set
import (
"fmt"
"os"
apinode "github.com/hpcng/warewulf/internal/pkg/api/node"
"github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1"
"github.com/hpcng/warewulf/internal/pkg/api/util"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
)
func CobraRunE(cmd *cobra.Command, args []string) (err error) {
// run converters for different types
for _, c := range Converters {
if err := c(); err != nil {
return err
}
}
// remove the default network as the all network values are assigned
// to this network
if NetName != "default" {
NodeConf.NetDevs[NetName] = NodeConf.NetDevs["default"]
delete(NodeConf.NetDevs, "default")
}
buffer, err := yaml.Marshal(NodeConf)
if err != nil {
wwlog.Error("Can't marshall nodeInfo", err)
os.Exit(1)
}
set := wwapiv1.NodeSetParameter{
NodeConfYaml: string(buffer[:]),
NetdevDelete: SetNetDevDel,
AllNodes: SetNodeAll,
Force: SetForce,
NodeNames: args,
}
if !SetYes {
var nodeCount uint
// The checks run twice in the prompt case.
// Avoiding putting in a blocking prompt in an API.
_, nodeCount, err = apinode.NodeSetParameterCheck(&set, false)
if err != nil {
return
}
yes := util.ConfirmationPrompt(fmt.Sprintf("Are you sure you want to modify %d nodes(s)", nodeCount))
if !yes {
return
}
}
return apinode.NodeSet(&set)
}