simplified node list command

This commit is contained in:
Christian Goll
2022-07-18 19:27:57 +02:00
parent 1dd519a7e6
commit e23f794166
8 changed files with 442 additions and 866 deletions

View File

@@ -5,7 +5,6 @@ import (
"fmt"
"net/http"
"os"
"strconv"
"strings"
"github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1"
@@ -183,184 +182,9 @@ func NodeList(nodeNames []string) (nodeInfo []*wwapiv1.NodeInfo, err error) {
// Translate to the protobuf structure so wwapiv1 can use this across the wire.
// This is the same logic as was in wwctl.
for _, node := range node.FilterByName(nodes, nodeNames) {
for _, n := range node.FilterByName(nodes, nodeNames) {
var ni wwapiv1.NodeInfo
ni.Id = &wwapiv1.NodeField{
Source: node.Id.Source(),
Value: node.Id.Get(),
Print: node.Id.Print(),
}
ni.Comment = &wwapiv1.NodeField{
Source: node.Comment.Source(),
Value: node.Comment.Get(),
Print: node.Comment.Print(),
}
ni.Cluster = &wwapiv1.NodeField{
Source: node.ClusterName.Source(),
Value: node.ClusterName.Get(),
Print: node.ClusterName.Print(),
}
ni.Profiles = node.Profiles
ni.Discoverable = &wwapiv1.NodeField{
Source: node.Discoverable.Source(),
Value: strconv.FormatBool(node.Discoverable.GetB()),
Print: node.Discoverable.PrintB(),
}
ni.Container = &wwapiv1.NodeField{
Source: node.ContainerName.Source(),
Value: node.ContainerName.Get(),
Print: node.ContainerName.Print(),
}
ni.KernelOverride = &wwapiv1.NodeField{
Source: node.Kernel.Override.Source(),
Value: node.Kernel.Override.Get(),
Print: node.Kernel.Override.Print(),
}
ni.KernelArgs = &wwapiv1.NodeField{
Source: node.Kernel.Args.Source(),
Value: node.Kernel.Args.Get(),
Print: node.Kernel.Args.Print(),
}
ni.SystemOverlay = &wwapiv1.NodeField{
Source: node.SystemOverlay.Source(),
Value: node.SystemOverlay.Get(),
Print: node.SystemOverlay.Print(),
}
ni.RuntimeOverlay = &wwapiv1.NodeField{
Source: node.RuntimeOverlay.Source(),
Value: node.RuntimeOverlay.Get(),
Print: node.RuntimeOverlay.Print(),
}
ni.Ipxe = &wwapiv1.NodeField{
Source: node.Ipxe.Source(),
Value: node.Ipxe.Get(),
Print: node.Ipxe.Print(),
}
ni.Init = &wwapiv1.NodeField{
Source: node.Init.Source(),
Value: node.Init.Get(),
Print: node.Init.Print(),
}
ni.Root = &wwapiv1.NodeField{
Source: node.Root.Source(),
Value: node.Root.Get(),
Print: node.Root.Print(),
}
ni.AssetKey = &wwapiv1.NodeField{
Source: node.AssetKey.Source(),
Value: node.AssetKey.Get(),
Print: node.AssetKey.Print(),
}
ni.IpmiIpaddr = &wwapiv1.NodeField{
Source: node.Ipmi.Ipaddr.Source(),
Value: node.Ipmi.Ipaddr.Get(),
Print: node.Ipmi.Ipaddr.Print(),
}
ni.IpmiNetmask = &wwapiv1.NodeField{
Source: node.Ipmi.Netmask.Source(),
Value: node.Ipmi.Netmask.Get(),
Print: node.Ipmi.Netmask.Print(),
}
ni.IpmiPort = &wwapiv1.NodeField{
Source: node.Ipmi.Port.Source(),
Value: node.Ipmi.Port.Get(),
Print: node.Ipmi.Port.Print(),
}
ni.IpmiGateway = &wwapiv1.NodeField{
Source: node.Ipmi.Gateway.Source(),
Value: node.Ipmi.Gateway.Get(),
Print: node.Ipmi.Gateway.Print(),
}
ni.IpmiUserName = &wwapiv1.NodeField{
Source: node.Ipmi.UserName.Source(),
Value: node.Ipmi.UserName.Get(),
Print: node.Ipmi.UserName.Print(),
}
ni.IpmiPassword = &wwapiv1.NodeField{
Source: node.Ipmi.Password.Source(),
Value: node.Ipmi.Password.Get(),
Print: node.Ipmi.Password.Print(), // TODO: Password was removed from pprinted output, at least in some places.
}
ni.IpmiInterface = &wwapiv1.NodeField{
Source: node.Ipmi.Interface.Source(),
Value: node.Ipmi.Interface.Get(),
Print: node.Ipmi.Interface.Print(),
}
ni.Tags = map[string]*wwapiv1.NodeField{}
for keyname, keyvalue := range node.Tags {
ni.Tags[keyname] = new(wwapiv1.NodeField)
ni.Tags[keyname].Source = keyvalue.Source()
ni.Tags[keyname].Value = keyvalue.Get()
ni.Tags[keyname].Print = keyvalue.Print()
}
ni.NetDevs = map[string]*wwapiv1.NetDev{}
for name, netdev := range node.NetDevs {
ni.NetDevs[name] = &wwapiv1.NetDev{
Device: &wwapiv1.NodeField{
Source: netdev.Device.Source(),
Value: netdev.Device.Get(),
Print: netdev.Device.Print(),
},
Hwaddr: &wwapiv1.NodeField{
Source: netdev.Hwaddr.Source(),
Value: netdev.Hwaddr.Get(),
Print: netdev.Hwaddr.Print(),
},
Ipaddr: &wwapiv1.NodeField{
Source: netdev.Ipaddr.Source(),
Value: netdev.Ipaddr.Get(),
Print: netdev.Ipaddr.Print(),
},
Netmask: &wwapiv1.NodeField{
Source: netdev.Netmask.Source(),
Value: netdev.Netmask.Get(),
Print: netdev.Netmask.Print(),
},
Gateway: &wwapiv1.NodeField{
Source: netdev.Gateway.Source(),
Value: netdev.Gateway.Get(),
Print: netdev.Gateway.Print(),
},
Type: &wwapiv1.NodeField{
Source: netdev.Type.Source(),
Value: netdev.Type.Get(),
Print: netdev.Type.Print(),
},
Onboot: &wwapiv1.NodeField{
Source: netdev.OnBoot.Source(),
Value: strconv.FormatBool(netdev.OnBoot.GetB()),
Print: netdev.OnBoot.PrintB(),
},
Primary: &wwapiv1.NodeField{
Source: netdev.Primary.Source(),
Value: strconv.FormatBool(netdev.Primary.GetB()),
Print: netdev.Primary.PrintB(),
},
}
}
ni.Fields = GetFields(n)
nodeInfo = append(nodeInfo, &ni)
}
return