Merge pull request #1685 from anderbubble/node-list-maps
wwctl node list <--yaml|--json> outputs a map keyed by node name
This commit is contained in:
@@ -10,6 +10,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||
|
||||
- Document defining kernel args that include commas. #1679
|
||||
- Recommend installing ipmitool with Warewulf package. #970
|
||||
### Changed
|
||||
|
||||
- `wwctl node list <--yaml|--json>` outputs a map keyed by node name. #1667
|
||||
|
||||
### Fixed
|
||||
|
||||
|
||||
@@ -428,8 +428,9 @@ func TestListMultipleFormats(t *testing.T) {
|
||||
name: "single node list yaml output",
|
||||
args: []string{"-y"},
|
||||
stdout: `
|
||||
- profiles:
|
||||
- default
|
||||
n01:
|
||||
profiles:
|
||||
- default
|
||||
`,
|
||||
inDb: `
|
||||
nodeprofiles:
|
||||
@@ -444,8 +445,8 @@ nodes:
|
||||
name: "single node list json output",
|
||||
args: []string{"-j"},
|
||||
stdout: `
|
||||
[
|
||||
{
|
||||
{
|
||||
"n01": {
|
||||
"Discoverable": "",
|
||||
"AssetKey": "",
|
||||
"Profiles": [
|
||||
@@ -468,7 +469,7 @@ nodes:
|
||||
"FileSystems": null,
|
||||
"Resources": null
|
||||
}
|
||||
]
|
||||
}
|
||||
`,
|
||||
inDb: `
|
||||
nodeprofiles:
|
||||
@@ -483,8 +484,8 @@ nodes:
|
||||
name: "multiple nodes list json output",
|
||||
args: []string{"-j"},
|
||||
stdout: `
|
||||
[
|
||||
{
|
||||
{
|
||||
"n01": {
|
||||
"Discoverable": "",
|
||||
"AssetKey": "",
|
||||
"Profiles": [
|
||||
@@ -507,7 +508,7 @@ nodes:
|
||||
"FileSystems": null,
|
||||
"Resources": null
|
||||
},
|
||||
{
|
||||
"n02": {
|
||||
"Discoverable": "",
|
||||
"AssetKey": "",
|
||||
"Profiles": [
|
||||
@@ -530,7 +531,7 @@ nodes:
|
||||
"FileSystems": null,
|
||||
"Resources": null
|
||||
}
|
||||
]
|
||||
}
|
||||
`,
|
||||
inDb: `
|
||||
nodeprofiles:
|
||||
@@ -548,10 +549,12 @@ nodes:
|
||||
name: "multiple nodes list yaml output",
|
||||
args: []string{"-y"},
|
||||
stdout: `
|
||||
- profiles:
|
||||
- default
|
||||
- profiles:
|
||||
- default
|
||||
n01:
|
||||
profiles:
|
||||
- default
|
||||
n02:
|
||||
profiles:
|
||||
- default
|
||||
`,
|
||||
inDb: `
|
||||
nodeprofiles:
|
||||
|
||||
@@ -101,13 +101,16 @@ func NodeList(nodeGet *wwapiv1.GetNodeList) (nodeList wwapiv1.NodeList, err erro
|
||||
}
|
||||
}
|
||||
} else if nodeGet.Type == wwapiv1.GetNodeList_YAML || nodeGet.Type == wwapiv1.GetNodeList_JSON {
|
||||
filterNodes := node.FilterNodeListByName(nodes, nodeGet.Nodes)
|
||||
nodeMap := make(map[string]node.Node)
|
||||
for _, n := range node.FilterNodeListByName(nodes, nodeGet.Nodes) {
|
||||
nodeMap[n.Id()] = n
|
||||
}
|
||||
var buf []byte
|
||||
if nodeGet.Type == wwapiv1.GetNodeList_JSON {
|
||||
buf, _ = json.MarshalIndent(filterNodes, "", " ")
|
||||
buf, _ = json.MarshalIndent(nodeMap, "", " ")
|
||||
}
|
||||
if nodeGet.Type == wwapiv1.GetNodeList_YAML {
|
||||
buf, _ = yaml.Marshal(filterNodes)
|
||||
buf, _ = yaml.Marshal(nodeMap)
|
||||
}
|
||||
nodeList.Output = append(nodeList.Output, string(buf))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user