Updated wwctl node export to include node IDs

- Fixed: #1718

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
Jonathon Anderson
2025-02-10 13:41:40 -07:00
parent db30008433
commit 900426ce81
3 changed files with 21 additions and 28 deletions

View File

@@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fixed panics in `wwctl node sensors` and `wwctl node console` when ipmi not configured.
- Fixed completions for `wwctl` commands.
- Return "" when NetDev.IpCIDR is empty.
- Updated `wwctl node export` to include node IDs. #1718
### Removed

View File

@@ -2,18 +2,31 @@ package export
import (
"github.com/spf13/cobra"
apinode "github.com/warewulf/warewulf/internal/pkg/api/node"
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
"github.com/warewulf/warewulf/internal/pkg/hostlist"
"github.com/warewulf/warewulf/internal/pkg/node"
"github.com/warewulf/warewulf/internal/pkg/util"
"github.com/warewulf/warewulf/internal/pkg/wwlog"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
args = hostlist.Expand(args)
filterList := wwapiv1.NodeList{
Output: args,
registry, err := node.New()
if err != nil {
return err
}
nodeListMsg := apinode.FilteredNodes(&filterList)
wwlog.Info(nodeListMsg.NodeConfMapYaml)
nodeMap := make(map[string]*node.Node)
names := hostlist.Expand(args)
if len(names) == 0 {
names = registry.ListAllNodes()
}
for _, name := range hostlist.Expand(names) {
if n, err := registry.GetNode(name); err == nil {
nodeMap[name] = &n
}
}
y, err := util.EncodeYaml(nodeMap)
if err != nil {
return err
}
wwlog.Output("%s", y)
return nil
}

View File

@@ -2,33 +2,12 @@ package apinode
import (
"fmt"
"os"
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
"github.com/warewulf/warewulf/internal/pkg/node"
"github.com/warewulf/warewulf/internal/pkg/wwlog"
"gopkg.in/yaml.v3"
)
/*
Returns filtered list of nodes
*/
func FilteredNodes(nodeList *wwapiv1.NodeList) *wwapiv1.NodeYaml {
nodeDB, err := node.New()
if err != nil {
wwlog.Error("Could not open nodeDB: %s\n", err)
os.Exit(1)
}
nodeMap, _ := nodeDB.FindAllNodes()
nodeMap = node.FilterNodeListByName(nodeMap, nodeList.Output)
buffer, _ := yaml.Marshal(nodeMap)
retVal := wwapiv1.NodeYaml{
NodeConfMapYaml: string(buffer),
Hash: nodeDB.StringHash(),
}
return &retVal
}
/*
Add nodes from yaml
*/