Changed backend node API to account for default and overrides for UI
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package add
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -20,6 +21,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("Added node: %s\n", a)
|
||||
}
|
||||
|
||||
nodeDB.Persist()
|
||||
|
||||
@@ -21,11 +21,11 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
nodeList, err := nodeDB.SearchByNameList(args)
|
||||
|
||||
for _, n := range nodeList {
|
||||
if SetGroup != "" && SetGroup != n.GroupName {
|
||||
if SetGroup != "" && SetGroup != n.GroupName.String() {
|
||||
wwlog.Printf(wwlog.DEBUG, "skipping node of different group: %s/%s\n", n.GroupName, n.Id)
|
||||
continue
|
||||
}
|
||||
err := nodeDB.DelNode(n.GroupName, n.Id)
|
||||
err := nodeDB.DelNode(n.GroupName.String(), n.Id.String())
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
} else {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
||||
@@ -38,32 +39,49 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
typeOfS := v.Type()
|
||||
fmt.Printf("################################################################################\n")
|
||||
for i := 0; i< v.NumField(); i++ {
|
||||
fmt.Printf("%-25s %s = %v\n", node.Fqdn, typeOfS.Field(i).Name, v.Field(i).Interface())
|
||||
//TODO: Fix for NetDevs and Interface should print Fprint() method
|
||||
fmt.Printf("%-25s %s = %v\n", node.Fqdn.String(), typeOfS.Field(i).Name, v.Field(i).Interface())
|
||||
}
|
||||
}
|
||||
|
||||
} else if ShowNet == true {
|
||||
fmt.Printf("%-22s %-10s %-20s %-16s %-16s %-16s %s\n", "NODE NAME", "DEVICE", "HWADDR", "IPADDR", "NETMASK", "GATEWAY", "TYPE")
|
||||
fmt.Printf("%-22s %-6s %-18s %-15s %-15s\n", "NODE NAME", "DEVICE", "HWADDR", "IPADDR", "GATEWAY")
|
||||
fmt.Println(strings.Repeat("=", 80))
|
||||
|
||||
for _, node := range nodes {
|
||||
for name, dev := range node.NetDevs {
|
||||
fmt.Printf("%-22s %-10s %-20s %-16s %-16s %-16s %s\n", node.Fqdn, name, dev.Hwaddr, dev.Ipaddr, dev.Netmask, dev.Gateway, dev.Type)
|
||||
if len(node.NetDevs) > 0 {
|
||||
for name, dev := range node.NetDevs {
|
||||
fmt.Printf("%-22s %-6s %-18s %-15s %-15s\n", node.Fqdn.String(), name, dev.Hwaddr, dev.Ipaddr, dev.Gateway)
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("%-22s %-6s %-18s %-15s %-15s\n", node.Fqdn.String(), "--", "--", "--", "--")
|
||||
}
|
||||
}
|
||||
|
||||
} else if ShowIpmi == true {
|
||||
fmt.Printf("%-22s %-16s %-20s %-20s\n", "NODE NAME", "IPMI IPADDR", "IPMI USERNAME", "IPMI PASSWORD")
|
||||
fmt.Println(strings.Repeat("=", 80))
|
||||
|
||||
for _, node := range nodes {
|
||||
fmt.Printf("%-22s %-16s %-20s %-20s\n", node.Fqdn, node.IpmiIpaddr, node.IpmiUserName, node.IpmiPassword)
|
||||
fmt.Printf("%-22s %-16s %-20s %-20s\n", node.Fqdn.String(), node.IpmiIpaddr.Fprint(), node.IpmiUserName.Fprint(), node.IpmiPassword.Fprint())
|
||||
}
|
||||
|
||||
} else if ShowLong == true {
|
||||
fmt.Printf("%-22s %-12s %-26s %-30s %-12s\n", "NODE NAME", "GROUP NAME", "KERNEL VERSION", "VNFS IMAGE", "R-OVERLAY")
|
||||
fmt.Println(strings.Repeat("=", 100))
|
||||
|
||||
for _, node := range nodes {
|
||||
fmt.Printf("%-22s %-12s %-26s %-30s %-12s\n", node.Fqdn.String(), node.GroupName.Fprint(), node.KernelVersion.Fprint(), node.Vnfs.Fprint(), node.RuntimeOverlay.Fprint())
|
||||
}
|
||||
|
||||
} else {
|
||||
fmt.Printf("%-22s %-16s %-30s %-30s %-16s\n", "NODE NAME", "GROUP NAME", "KERNEL VERSION", "VNFS IMAGE", "RUNTIME OVERLAY")
|
||||
fmt.Printf("%-22s %-26s %-30s\n", "NODE NAME", "KERNEL VERSION", "VNFS IMAGE")
|
||||
fmt.Println(strings.Repeat("=", 80))
|
||||
|
||||
for _, node := range nodes {
|
||||
fmt.Printf("%-22s %-16s %-30s %-30s %-16s\n", node.Fqdn, node.GroupName, node.KernelVersion, node.Vnfs, node.RuntimeOverlay)
|
||||
fmt.Printf("%-22s %-26s %-30s\n", node.Fqdn.String(), node.KernelVersion.Fprint(), node.Vnfs.Fprint())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,12 +12,14 @@ var (
|
||||
ShowNet bool
|
||||
ShowIpmi bool
|
||||
ShowAll bool
|
||||
ShowLong bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
baseCmd.PersistentFlags().BoolVarP(&ShowNet, "net", "n", false, "Show node network configurations")
|
||||
baseCmd.PersistentFlags().BoolVarP(&ShowIpmi, "ipmi", "i", false, "Show node IPMI configurations")
|
||||
baseCmd.PersistentFlags().BoolVarP(&ShowAll, "all", "a", false, "Show all node configurations")
|
||||
baseCmd.PersistentFlags().BoolVarP(&ShowLong, "long", "l", false, "Show long or wide format")
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
|
||||
@@ -34,13 +34,13 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
|
||||
for _, node := range nodeList {
|
||||
|
||||
if node.IpmiIpaddr == "" {
|
||||
if node.IpmiIpaddr.String() == "" {
|
||||
wwlog.Printf(wwlog.ERROR, "%s: No IPMI IP address\n", node.HostName)
|
||||
continue
|
||||
}
|
||||
|
||||
ipmiCmd := power.IPMI{
|
||||
HostName: node.IpmiIpaddr,
|
||||
HostName: node.IpmiIpaddr.String(),
|
||||
User: "ADMIN",
|
||||
Password: "ADMIN",
|
||||
AuthType: "MD5",
|
||||
|
||||
@@ -34,13 +34,13 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
|
||||
for _, node := range nodeList {
|
||||
|
||||
if node.IpmiIpaddr == "" {
|
||||
if node.IpmiIpaddr.String() == "" {
|
||||
wwlog.Printf(wwlog.ERROR, "%s: No IPMI IP address\n", node.HostName)
|
||||
continue
|
||||
}
|
||||
|
||||
ipmiCmd := power.IPMI{
|
||||
HostName: node.IpmiIpaddr,
|
||||
HostName: node.IpmiIpaddr.String(),
|
||||
User: "ADMIN",
|
||||
Password: "ADMIN",
|
||||
AuthType: "MD5",
|
||||
|
||||
@@ -34,13 +34,13 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
|
||||
for _, node := range nodeList {
|
||||
|
||||
if node.IpmiIpaddr == "" {
|
||||
if node.IpmiIpaddr.String() == "" {
|
||||
wwlog.Printf(wwlog.ERROR, "%s: No IPMI IP address\n", node.HostName)
|
||||
continue
|
||||
}
|
||||
|
||||
ipmiCmd := power.IPMI{
|
||||
HostName: node.IpmiIpaddr,
|
||||
HostName: node.IpmiIpaddr.String(),
|
||||
User: "ADMIN",
|
||||
Password: "ADMIN",
|
||||
AuthType: "MD5",
|
||||
|
||||
@@ -24,31 +24,37 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if len(args) > 0 {
|
||||
nodes, err = nodeDB.SearchByNameList(args)
|
||||
if SetNodeAll == true {
|
||||
nodes, err = nodeDB.FindAllNodes()
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
} else if len(args) > 0 {
|
||||
nodes, err = nodeDB.SearchByNameList(args)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
} else {
|
||||
cmd.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
for _, n := range nodes {
|
||||
wwlog.Printf(wwlog.VERBOSE, "Evaluating node: %s\n", n.Fqdn)
|
||||
wwlog.Printf(wwlog.VERBOSE, "Evaluating node: %s\n", n.Fqdn.String())
|
||||
if SetVnfs != "" {
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting vnfs to: %s\n", n.Fqdn, SetVnfs)
|
||||
err := nodeDB.SetNodeVal(n.Gid, n.Id, "vnfs", SetVnfs)
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting vnfs to: %s\n", n.Fqdn.String(), SetVnfs)
|
||||
err := nodeDB.SetNodeVal(n.Gid.String(), n.Id.String(), "vnfs", SetVnfs)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
if SetKernel != "" {
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting kernel to: %s\n", n.Fqdn, SetVnfs)
|
||||
err := nodeDB.SetNodeVal(n.Gid, n.Id, "kernel", SetKernel)
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting kernel to: %s\n", n.Fqdn.String(), SetKernel)
|
||||
err := nodeDB.SetNodeVal(n.Gid.String(), n.Id.String(), "kernel", SetKernel)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
@@ -56,7 +62,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
if SetDomainName != "" {
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting domain name to: %s\n", n.Fqdn, SetDomainName)
|
||||
err := nodeDB.SetNodeVal(n.Gid, n.Id, "domain", SetDomainName)
|
||||
err := nodeDB.SetNodeVal(n.Gid.String(), n.Id.String(), "domain", SetDomainName)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
@@ -64,7 +70,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
if SetIpxe != "" {
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting iPXE template to: %s\n", n.Fqdn, SetIpxe)
|
||||
err := nodeDB.SetNodeVal(n.Gid, n.Id, "ipxe", SetIpxe)
|
||||
err := nodeDB.SetNodeVal(n.Gid.String(), n.Id.String(), "ipxe", SetIpxe)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
@@ -72,7 +78,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
if SetRuntimeOverlay != "" {
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting runtime overlay to: %s\n", n.Fqdn, SetRuntimeOverlay)
|
||||
err := nodeDB.SetNodeVal(n.Gid, n.Id, "runtimeoverlay", SetRuntimeOverlay)
|
||||
err := nodeDB.SetNodeVal(n.Gid.String(), n.Id.String(), "runtimeoverlay", SetRuntimeOverlay)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
@@ -80,7 +86,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
if SetSystemOverlay != "" {
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting system overlay to: %s\n", n.Fqdn, SetSystemOverlay)
|
||||
err := nodeDB.SetNodeVal(n.Gid, n.Id, "systemoverlay", SetSystemOverlay)
|
||||
err := nodeDB.SetNodeVal(n.Gid.String(), n.Id.String(), "systemoverlay", SetSystemOverlay)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
@@ -88,7 +94,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
if SetHostname != "" {
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting hostname to: %s\n", n.Fqdn, SetHostname)
|
||||
err := nodeDB.SetNodeVal(n.Gid, n.Id, "hostname", SetHostname)
|
||||
err := nodeDB.SetNodeVal(n.Gid.String(), n.Id.String(), "hostname", SetHostname)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
@@ -96,7 +102,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
if SetIpmiIpaddr != "" {
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting IPMI IP address to: %s\n", n.Fqdn, SetIpmiIpaddr)
|
||||
err := nodeDB.SetNodeVal(n.Gid, n.Id, "ipmiipaddr", SetIpmiIpaddr)
|
||||
err := nodeDB.SetNodeVal(n.Gid.String(), n.Id.String(), "ipmiipaddr", SetIpmiIpaddr)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
@@ -104,7 +110,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
if SetIpmiUsername != "" {
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting IPMI IP username to: %s\n", n.Fqdn, SetIpmiUsername)
|
||||
err := nodeDB.SetNodeVal(n.Gid, n.Id, "ipmiusername", SetIpmiUsername)
|
||||
err := nodeDB.SetNodeVal(n.Gid.String(), n.Id.String(), "ipmiusername", SetIpmiUsername)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
@@ -112,7 +118,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
if SetIpmiPassword != "" {
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting IPMI IP password to: %s\n", n.Fqdn, SetIpmiPassword)
|
||||
err := nodeDB.SetNodeVal(n.Gid, n.Id, "ipmipassword", SetIpmiPassword)
|
||||
err := nodeDB.SetNodeVal(n.Gid.String(), n.Id.String(), "ipmipassword", SetIpmiPassword)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
@@ -127,7 +133,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
os.Exit(1)
|
||||
}
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Deleting network device: %s\n", n.Fqdn, SetNetDev)
|
||||
err := nodeDB.DelNodeNet(n.Gid, n.Id, SetNetDev)
|
||||
err := nodeDB.DelNodeNet(n.Gid.String(), n.Id.String(), SetNetDev)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
@@ -140,7 +146,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
os.Exit(1)
|
||||
}
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Ipaddr to: %s\n", n.Fqdn, SetNetDev, SetIpaddr)
|
||||
err := nodeDB.SetNodeNet(n.Gid, n.Id, SetNetDev, "ipaddr", SetIpaddr)
|
||||
err := nodeDB.SetNodeNet(n.Gid.String(), n.Id.String(), SetNetDev, "ipaddr", SetIpaddr)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
@@ -152,7 +158,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
os.Exit(1)
|
||||
}
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting netmask to: %s\n", n.Fqdn, SetNetDev, SetNetmask)
|
||||
err := nodeDB.SetNodeNet(n.Gid, n.Id, SetNetDev, "netmask", SetNetmask)
|
||||
err := nodeDB.SetNodeNet(n.Gid.String(), n.Id.String(), SetNetDev, "netmask", SetNetmask)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
@@ -164,7 +170,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
os.Exit(1)
|
||||
}
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting gateway to: %s\n", n.Fqdn, SetNetDev, SetGateway)
|
||||
err := nodeDB.SetNodeNet(n.Gid, n.Id, SetNetDev, "gateway", SetGateway)
|
||||
err := nodeDB.SetNodeNet(n.Gid.String(), n.Id.String(), SetNetDev, "gateway", SetGateway)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
@@ -176,7 +182,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
os.Exit(1)
|
||||
}
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting HW address to: %s\n", n.Fqdn, SetNetDev, SetHwaddr)
|
||||
err := nodeDB.SetNodeNet(n.Gid, n.Id, SetNetDev, "hwaddr", SetHwaddr)
|
||||
err := nodeDB.SetNodeNet(n.Gid.String(), n.Id.String(), SetNetDev, "hwaddr", SetHwaddr)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
@@ -185,17 +191,21 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if len(nodes) > 0 {
|
||||
q := fmt.Sprintf("Are you sure you want to modify %d nodes(s)", len(nodes))
|
||||
|
||||
prompt := promptui.Prompt{
|
||||
Label: q,
|
||||
IsConfirm: true,
|
||||
}
|
||||
|
||||
result, _ := prompt.Run()
|
||||
|
||||
if result == "y" || result == "yes" {
|
||||
if SetYes == true {
|
||||
nodeDB.Persist()
|
||||
} else {
|
||||
q := fmt.Sprintf("Are you sure you want to modify %d nodes(s)", len(nodes))
|
||||
|
||||
prompt := promptui.Prompt{
|
||||
Label: q,
|
||||
IsConfirm: true,
|
||||
}
|
||||
|
||||
result, _ := prompt.Run()
|
||||
|
||||
if result == "y" || result == "yes" {
|
||||
nodeDB.Persist()
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
@@ -25,7 +25,8 @@ var (
|
||||
SetIpmiIpaddr string
|
||||
SetIpmiUsername string
|
||||
SetIpmiPassword string
|
||||
|
||||
SetNodeAll bool
|
||||
SetYes bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -46,6 +47,9 @@ func init() {
|
||||
baseCmd.PersistentFlags().StringVarP(&SetGateway, "gateway", "G", "", "Set the node's network device gateway")
|
||||
baseCmd.PersistentFlags().StringVarP(&SetHwaddr, "hwaddr", "N", "", "Set the node's network device HW address")
|
||||
baseCmd.PersistentFlags().BoolVar(&SetNetDevDel, "delete", false, "Delete the node's network device")
|
||||
baseCmd.PersistentFlags().BoolVarP(&SetNodeAll, "all", "a", false, "Set all nodes")
|
||||
|
||||
baseCmd.PersistentFlags().BoolVarP(&SetYes, "yes", "y", false, "Set 'yes' to all questions asked")
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user