Every struct in a NodeConf with `lopt:"foo" set is now added as a command-line flag with the RecursiveCreateFlags call. For maps a struct with the key UNDEF is added so that it can be parsed out. As the flags for the command-line need variables which hold the values, for every map an element map[UNDEF] is added. When now calling the internal add, these map element can be filtered out and replace by the given name. (e.g., --netname) * rewrote node/profile add for recursive functions * rewrote node/profile set for recursive functions * rewrote node/profile list for recursive functions Signed-off-by: Christian Goll <cgoll@suse.com>
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package list
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/hpcng/warewulf/internal/app/wwctl/helper"
|
|
apinode "github.com/hpcng/warewulf/internal/pkg/api/node"
|
|
"github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) (err error) {
|
|
return func(cmd *cobra.Command, args []string) (err error) {
|
|
if len(args) > 0 && strings.Contains(args[0], ",") {
|
|
args = strings.FieldsFunc(args[0], func(r rune) bool { return r == ',' })
|
|
}
|
|
req := wwapiv1.GetNodeList{
|
|
Nodes: args,
|
|
Type: wwapiv1.GetNodeList_Simple,
|
|
}
|
|
if vars.showAll {
|
|
req.Type = wwapiv1.GetNodeList_All
|
|
} else if vars.showIpmi {
|
|
req.Type = wwapiv1.GetNodeList_Ipmi
|
|
} else if vars.showNet {
|
|
req.Type = wwapiv1.GetNodeList_Network
|
|
} else if vars.showLong {
|
|
req.Type = wwapiv1.GetNodeList_Long
|
|
} else if vars.showFullAll {
|
|
req.Type = wwapiv1.GetNodeList_FullAll
|
|
}
|
|
nodeInfo, err := apinode.NodeList(&req)
|
|
if len(nodeInfo.Output) > 0 {
|
|
ph := helper.NewPrintHelper(strings.Split(nodeInfo.Output[0], ":=:"))
|
|
for _, val := range nodeInfo.Output[1:] {
|
|
ph.Append(strings.Split(val, ":=:"))
|
|
}
|
|
ph.Render()
|
|
}
|
|
return
|
|
}
|
|
}
|