From 221e71b384c08c9e07765cdad92401ffab90bdd8 Mon Sep 17 00:00:00 2001 From: Gregory Kurtzer Date: Fri, 20 Nov 2020 17:59:06 -0800 Subject: [PATCH] A bunch of changes including reworking the assets -> node API --- etc/nodes.conf | 8 +- internal/app/warewulfd/response/ipxe.go | 11 +- internal/app/warewulfd/response/runtime.go | 10 +- internal/app/warewulfd/response/util.go | 23 ++- internal/app/wwctl/build/main.go | 84 ++------- internal/app/wwctl/kernel/build/main.go | 14 +- internal/app/wwctl/node/list/main.go | 59 +++++++ internal/app/wwctl/node/list/root.go | 25 +++ internal/app/wwctl/node/poweroff/power.go | 13 +- internal/app/wwctl/node/poweron/power.go | 13 +- internal/app/wwctl/node/powerstatus/power.go | 13 +- internal/app/wwctl/node/root.go | 3 + internal/app/wwctl/overlay/build/main.go | 14 +- internal/app/wwctl/overlay/chmod/main.go | 12 +- internal/app/wwctl/overlay/create/main.go | 13 +- internal/app/wwctl/overlay/delete/main.go | 12 +- internal/app/wwctl/overlay/edit/main.go | 12 +- internal/app/wwctl/overlay/imprt/main.go | 12 +- internal/app/wwctl/overlay/list/main.go | 12 +- internal/app/wwctl/overlay/mkdir/main.go | 12 +- internal/app/wwctl/vnfs/build/main.go | 14 +- internal/app/wwctl/vnfs/list/main.go | 27 +++ internal/app/wwctl/vnfs/list/root.go | 25 +++ internal/app/wwctl/vnfs/root.go | 3 +- internal/pkg/config/config.go | 39 ++-- .../pkg/{assets/assets.go => node/node.go} | 167 ++++-------------- internal/pkg/overlay/runtime.go | 4 +- internal/pkg/overlay/system.go | 4 +- 28 files changed, 367 insertions(+), 291 deletions(-) create mode 100644 internal/app/wwctl/node/list/main.go create mode 100644 internal/app/wwctl/node/list/root.go create mode 100644 internal/app/wwctl/vnfs/list/main.go create mode 100644 internal/app/wwctl/vnfs/list/root.go rename internal/pkg/{assets/assets.go => node/node.go} (69%) diff --git a/etc/nodes.conf b/etc/nodes.conf index a692cbb1..f05ac35e 100644 --- a/etc/nodes.conf +++ b/etc/nodes.conf @@ -13,7 +13,7 @@ nodegroups: system overlay: test netdevs: eth0: - hwaddr: xx:xx:xx:xx:aa + hwaddr: xx:xx:xx:xx:xx:aa ipaddr: 192.168.1.1 netmask: 255.255.255.0 gateway: 192.168.1.1 @@ -37,7 +37,7 @@ nodegroups: gateway: 192.168.1.1 type: ethernet ib0: - hwaddr: xx:xx:xx:xx:xx + hwaddr: xx:xx:xx:xx:xx:xx ipaddr: x.x.x.x netmask: x.x.x.x gateway: x.x.x.x @@ -47,11 +47,11 @@ nodegroups: ipmi ipaddr: x.x.x.x netdevs: eth0: - hwaddr: xx:xx:xx:xx:xx + hwaddr: xx:xx:xx:xx:xx:xx ipaddr: 192.168.1.101 netmask: 255.255.255.0 gateway: 192.168.1.1 ib0: - hwaddr: xx:xx:xx:xx:xx + hwaddr: xx:xx:xx:xx:xx:xx ipaddr: x.x.x.x netmask: x.x.x.x diff --git a/internal/app/warewulfd/response/ipxe.go b/internal/app/warewulfd/response/ipxe.go index 76336e6b..6a9e2d3b 100644 --- a/internal/app/warewulfd/response/ipxe.go +++ b/internal/app/warewulfd/response/ipxe.go @@ -2,8 +2,8 @@ package response import ( "fmt" - "github.com/hpcng/warewulf/internal/pkg/assets" "github.com/hpcng/warewulf/internal/pkg/config" + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/wwlog" "log" "net/http" @@ -26,13 +26,20 @@ type iPxeTemplate struct { func IpxeSend(w http.ResponseWriter, req *http.Request) { url := strings.Split(req.URL.Path, "/") + nodes, err := node.New() + if err != nil { + log.Printf("Could not read node configuration file: %s\n", err) + w.WriteHeader(503) + return + } + if url[2] == "" { log.Printf("ERROR: Bad iPXE request from %s\n", req.RemoteAddr) return } hwaddr := strings.ReplaceAll(url[2], "-", ":") - node, err := assets.FindByHwaddr(hwaddr) + node, err := nodes.FindByHwaddr(hwaddr) if err != nil { log.Printf("Could not find HW Addr: %s: %s\n", hwaddr, err) w.WriteHeader(404) diff --git a/internal/app/warewulfd/response/runtime.go b/internal/app/warewulfd/response/runtime.go index 0b0a4ea7..06b30309 100644 --- a/internal/app/warewulfd/response/runtime.go +++ b/internal/app/warewulfd/response/runtime.go @@ -2,8 +2,8 @@ package response import ( "fmt" - "github.com/hpcng/warewulf/internal/pkg/assets" "github.com/hpcng/warewulf/internal/pkg/config" + "github.com/hpcng/warewulf/internal/pkg/node" "log" "net/http" "strconv" @@ -12,6 +12,12 @@ import ( func RuntimeOverlaySend(w http.ResponseWriter, req *http.Request) { config := config.New() + nodes, err := node.New() + if err != nil { + log.Printf("Could not read node configuration file: %s\n", err) + w.WriteHeader(503) + return + } remote := strings.Split(req.RemoteAddr, ":") port, err := strconv.Atoi(remote[1]) @@ -34,7 +40,7 @@ func RuntimeOverlaySend(w http.ResponseWriter, req *http.Request) { } } - node, err := assets.FindByIpaddr(remote[0]) + node, err := nodes.FindByIpaddr(remote[0]) if err != nil { fmt.Printf("Could not find node by IP address: %s\n", remote[0]) w.WriteHeader(404) diff --git a/internal/app/warewulfd/response/util.go b/internal/app/warewulfd/response/util.go index 2eaad20a..793ef1fb 100644 --- a/internal/app/warewulfd/response/util.go +++ b/internal/app/warewulfd/response/util.go @@ -1,7 +1,8 @@ package response import ( - "github.com/hpcng/warewulf/internal/pkg/assets" + "fmt" + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/errors" "io" "log" @@ -11,23 +12,29 @@ import ( "strings" ) -func getSanity(req *http.Request) (assets.NodeInfo, error) { +func getSanity(req *http.Request) (node.NodeInfo, error) { url := strings.Split(req.URL.Path, "/") + var ret node.NodeInfo + + nodes, err := node.New() + if err != nil { + return ret, errors.New(fmt.Sprintf("%s", err)) + } hwaddr := strings.ReplaceAll(url[2], "-", ":") - node, err := assets.FindByHwaddr(hwaddr) + ret, err = nodes.FindByHwaddr(hwaddr) if err != nil { - return node, errors.New("Could not find node by HW address") + return ret, errors.New("Could not find node by HW address") } - if node.Fqdn == "" { + if ret.Fqdn == "" { log.Printf("UNKNOWN: %15s: %s\n", hwaddr, req.URL.Path) - return node, errors.New("Unknown node HW address: " + hwaddr) + return ret, errors.New("Unknown node HW address: " + hwaddr) } else { - log.Printf("REQ: %15s: %s\n", node.Fqdn, req.URL.Path) + log.Printf("REQ: %15s: %s\n", ret.Fqdn, req.URL.Path) } - return node, nil + return ret, nil } func sendFile(w http.ResponseWriter, filename string, sendto string) error { diff --git a/internal/app/wwctl/build/main.go b/internal/app/wwctl/build/main.go index 7db258ab..0a2f5edc 100644 --- a/internal/app/wwctl/build/main.go +++ b/internal/app/wwctl/build/main.go @@ -1,8 +1,8 @@ package build import ( - "github.com/hpcng/warewulf/internal/pkg/assets" "github.com/hpcng/warewulf/internal/pkg/kernel" + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/overlay" "github.com/hpcng/warewulf/internal/pkg/vnfs" "github.com/hpcng/warewulf/internal/pkg/wwlog" @@ -12,12 +12,18 @@ import ( func CobraRunE(cmd *cobra.Command, args []string) error { - var nodes []assets.NodeInfo + var nodes []node.NodeInfo showHelp := true + n, err := node.New() + if err != nil { + wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err) + os.Exit(1) + } + if len(args) > 0 { var err error - nodes, err = assets.SearchByName(args[0]) + nodes, err = n.SearchByName(args[0]) if err != nil { wwlog.Printf(wwlog.ERROR, "Could not find nodes for search term: %s\n", args[0]) os.Exit(1) @@ -25,7 +31,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } else { var err error - nodes, err = assets.FindAllNodes() + nodes, err = n.FindAllNodes() if err != nil { wwlog.Printf(wwlog.ERROR, "Could not get list of nodes: %s\n", err) os.Exit(1) @@ -82,73 +88,3 @@ func CobraRunE(cmd *cobra.Command, args []string) error { return nil } - - -/* -func CobraRunEA(cmd *cobra.Command, args []string) error { - var nodeList []assets.NodeInfo - - if buildAll == true { - wwlog.Printf(wwlog.VERBOSE, "Building all components\n") - buildVnfs = true - buildKernel = true - buildSystemOverlay = true; - buildRuntimeOverlay = true; - } - - if len(args) >= 1 { - nodeList, _ = assets.SearchByName(args[0]) - } else { - nodeList, _ = assets.FindAllNodes() - } - - if len(nodeList) == 0 { - wwlog.Printf(wwlog.ERROR, "No nodes found matching: '%s'\n", args[0]) - os.Exit(255) - } else { - wwlog.Printf(wwlog.VERBOSE, "Found matching nodes for build: %d\n", len(nodeList)) - } - - if buildVnfs == true { -// wwlog.Printf(wwlog.INFO, "===============================================================================\n") - - err := vnfs.Build(nodeList, buildForce) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - os.Exit(255) - } - } - - if buildKernel == true { -// wwlog.Printf(wwlog.INFO, "===============================================================================\n") - - err := kernel.Build(nodeList, buildForce) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - os.Exit(255) - } - } - - if buildSystemOverlay == true { -// wwlog.Printf(wwlog.INFO, "===============================================================================\n") - err := system_overlay.Build(nodeList, buildForce) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - os.Exit(255) - } - } - - if buildRuntimeOverlay == true { -// wwlog.Printf(wwlog.INFO, "===============================================================================\n") - err := runtime_overlay.Build(nodeList, buildForce) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - os.Exit(255) - } - } - - - return nil -} - - */ \ No newline at end of file diff --git a/internal/app/wwctl/kernel/build/main.go b/internal/app/wwctl/kernel/build/main.go index cc11403a..89f01653 100644 --- a/internal/app/wwctl/kernel/build/main.go +++ b/internal/app/wwctl/kernel/build/main.go @@ -1,20 +1,26 @@ package build import ( - "github.com/hpcng/warewulf/internal/pkg/assets" "github.com/hpcng/warewulf/internal/pkg/kernel" + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/spf13/cobra" "os" ) func CobraRunE(cmd *cobra.Command, args []string) error { - var nodes []assets.NodeInfo + var nodes []node.NodeInfo set := make(map[string]int) + n, err := node.New() + if err != nil { + wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err) + os.Exit(1) + } + if len(args) == 1 && ByNode == true { var err error - nodes, err = assets.SearchByName(args[0]) + nodes, err = n.SearchByName(args[0]) if err != nil { wwlog.Printf(wwlog.ERROR, "Could not find nodes for search term: %s\n", args[0]) os.Exit(1) @@ -26,7 +32,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } else if BuildAll == true { var err error - nodes, err = assets.FindAllNodes() + nodes, err = n.FindAllNodes() if err != nil { wwlog.Printf(wwlog.ERROR, "Could not get list of nodes: %s\n", err) os.Exit(1) diff --git a/internal/app/wwctl/node/list/main.go b/internal/app/wwctl/node/list/main.go new file mode 100644 index 00000000..c5ae1d03 --- /dev/null +++ b/internal/app/wwctl/node/list/main.go @@ -0,0 +1,59 @@ +package list + +import ( + "fmt" + "github.com/hpcng/warewulf/internal/pkg/node" + "github.com/hpcng/warewulf/internal/pkg/wwlog" + "github.com/spf13/cobra" + "os" +) + + + +func CobraRunE(cmd *cobra.Command, args []string) error { + var err error + var nodes []node.NodeInfo + + n, err := node.New() + if err != nil { + wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err) + os.Exit(1) + } + + if len(args) > 0 { + nodes, err = n.SearchByNameList(args) + } else { + nodes, err = n.FindAllNodes() + } + if err != nil { + wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err) + os.Exit(1) + } + + if ShowNet == true { + fmt.Printf("%-22s %-10s %-20s %-16s %-16s %-16s %s\n", "NODE NAME", "DEVICE", "HWADDR", "IPADDR", "NETMASK", "GATEWAY", "TYPE") + + 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) + } + } + + } else if ShowIpmi == true { + fmt.Printf("%-22s %-16s %-20s %-20s\n", "NODE NAME", "IPMI IPADDR", "IPMI USERNAME", "IPMI PASSWORD") + + for _, node := range nodes { + fmt.Printf("%-22s %-16s %-20s %-20s\n", node.Fqdn, node.IpmiIpaddr, node.IpmiUserName, node.IpmiPassword) + } + + } else { + fmt.Printf("%-22s %-30s %-30s %-16s %-16s\n", "NODE NAME", "KERNEL NAME", "VNFS IMAGE", "SYSTEM OVERLAY", "RUNTIME OVERLAY") + + for _, node := range nodes { + fmt.Printf("%-22s %-30s %-30s %-16s %-16s\n", node.Fqdn, node.KernelVersion, node.Vnfs, node.SystemOverlay, node.RuntimeOverlay) + } + } + + + return nil +} diff --git a/internal/app/wwctl/node/list/root.go b/internal/app/wwctl/node/list/root.go new file mode 100644 index 00000000..7d5d3048 --- /dev/null +++ b/internal/app/wwctl/node/list/root.go @@ -0,0 +1,25 @@ +package list + +import "github.com/spf13/cobra" + +var ( + baseCmd = &cobra.Command{ + Use: "list", + Short: "List all nodes", + Long: "List all nodes", + RunE: CobraRunE, + } + ShowNet bool + ShowIpmi 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") + +} + +// GetRootCommand returns the root cobra.Command for the application. +func GetCommand() *cobra.Command { + return baseCmd +} diff --git a/internal/app/wwctl/node/poweroff/power.go b/internal/app/wwctl/node/poweroff/power.go index b6f05a7d..3364fd88 100644 --- a/internal/app/wwctl/node/poweroff/power.go +++ b/internal/app/wwctl/node/poweroff/power.go @@ -1,7 +1,7 @@ package poweroff import ( - "github.com/hpcng/warewulf/internal/pkg/assets" + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/power" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/spf13/cobra" @@ -9,14 +9,17 @@ import ( ) func CobraRunE(cmd *cobra.Command, args []string) error { - var returnErr error = nil + var nodeList []node.NodeInfo - var nodeList []assets.NodeInfo + n, err := node.New() + if err != nil { + wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err) + os.Exit(1) + } if len(args) >= 1 { - //nodeList, _ = assets.SearchByName(args[0]) - nodeList, _ = assets.SearchByNameList(args) + nodeList, _ = n.SearchByNameList(args) } else { wwlog.Printf(wwlog.ERROR, "No requested nodes\n") os.Exit(255) diff --git a/internal/app/wwctl/node/poweron/power.go b/internal/app/wwctl/node/poweron/power.go index 6b5821ab..900177c2 100644 --- a/internal/app/wwctl/node/poweron/power.go +++ b/internal/app/wwctl/node/poweron/power.go @@ -1,7 +1,7 @@ package poweron import ( - "github.com/hpcng/warewulf/internal/pkg/assets" + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/power" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/spf13/cobra" @@ -9,14 +9,17 @@ import ( ) func CobraRunE(cmd *cobra.Command, args []string) error { - var returnErr error = nil + var nodeList []node.NodeInfo - var nodeList []assets.NodeInfo + n, err := node.New() + if err != nil { + wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err) + os.Exit(1) + } if len(args) >= 1 { - //nodeList, _ = assets.SearchByName(args[0]) - nodeList, _ = assets.SearchByNameList(args) + nodeList, _ = n.SearchByNameList(args) } else { wwlog.Printf(wwlog.ERROR, "No requested nodes\n") os.Exit(255) diff --git a/internal/app/wwctl/node/powerstatus/power.go b/internal/app/wwctl/node/powerstatus/power.go index f503389b..1f02fb57 100644 --- a/internal/app/wwctl/node/powerstatus/power.go +++ b/internal/app/wwctl/node/powerstatus/power.go @@ -1,7 +1,7 @@ package powerstatus import ( - "github.com/hpcng/warewulf/internal/pkg/assets" + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/power" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/spf13/cobra" @@ -9,14 +9,17 @@ import ( ) func CobraRunE(cmd *cobra.Command, args []string) error { - var returnErr error = nil + var nodeList []node.NodeInfo - var nodeList []assets.NodeInfo + n, err := node.New() + if err != nil { + wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err) + os.Exit(1) + } if len(args) >= 1 { - //nodeList, _ = assets.SearchByName(args[0]) - nodeList, _ = assets.SearchByNameList(args) + nodeList, _ = n.SearchByNameList(args) } else { wwlog.Printf(wwlog.ERROR, "No requested nodes\n") os.Exit(255) diff --git a/internal/app/wwctl/node/root.go b/internal/app/wwctl/node/root.go index 150ae6bc..c2b98d9a 100644 --- a/internal/app/wwctl/node/root.go +++ b/internal/app/wwctl/node/root.go @@ -1,6 +1,7 @@ package node import ( + "github.com/hpcng/warewulf/internal/app/wwctl/node/list" "github.com/hpcng/warewulf/internal/app/wwctl/node/poweron" "github.com/hpcng/warewulf/internal/app/wwctl/node/poweroff" "github.com/hpcng/warewulf/internal/app/wwctl/node/powerstatus" @@ -19,6 +20,8 @@ func init() { baseCmd.AddCommand(poweron.GetCommand()) baseCmd.AddCommand(poweroff.GetCommand()) baseCmd.AddCommand(powerstatus.GetCommand()) + baseCmd.AddCommand(list.GetCommand()) + } // GetRootCommand returns the root cobra.Command for the application. diff --git a/internal/app/wwctl/overlay/build/main.go b/internal/app/wwctl/overlay/build/main.go index 7ca3d49b..3dbb0eda 100644 --- a/internal/app/wwctl/overlay/build/main.go +++ b/internal/app/wwctl/overlay/build/main.go @@ -1,7 +1,7 @@ package build import ( - "github.com/hpcng/warewulf/internal/pkg/assets" + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/overlay" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/spf13/cobra" @@ -9,10 +9,16 @@ import ( ) func CobraRunE(cmd *cobra.Command, args []string) error { - var updateNodes []assets.NodeInfo + var updateNodes []node.NodeInfo + + n, err := node.New() + if err != nil { + wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err) + os.Exit(1) + } if len(args) > 0 && BuildAll == false { - nodes, err := assets.FindAllNodes() + nodes, err := n.FindAllNodes() if err != nil { wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err) os.Exit(1) @@ -27,7 +33,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } } else { var err error - updateNodes, err = assets.FindAllNodes() + updateNodes, err = n.FindAllNodes() if err != nil { wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err) os.Exit(1) diff --git a/internal/app/wwctl/overlay/chmod/main.go b/internal/app/wwctl/overlay/chmod/main.go index c03ef9de..4ce3c364 100644 --- a/internal/app/wwctl/overlay/chmod/main.go +++ b/internal/app/wwctl/overlay/chmod/main.go @@ -1,8 +1,8 @@ package chmod import ( - "github.com/hpcng/warewulf/internal/pkg/assets" "github.com/hpcng/warewulf/internal/pkg/config" + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/overlay" "github.com/hpcng/warewulf/internal/pkg/util" "github.com/hpcng/warewulf/internal/pkg/wwlog" @@ -49,13 +49,19 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } if NoOverlayUpdate == false { - nodes, err := assets.FindAllNodes() + n, err := node.New() + if err != nil { + wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err) + os.Exit(1) + } + + nodes, err := n.FindAllNodes() if err != nil { wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err) os.Exit(1) } - var updateNodes []assets.NodeInfo + var updateNodes []node.NodeInfo for _, node := range nodes { if SystemOverlay == true && node.SystemOverlay == overlayName { diff --git a/internal/app/wwctl/overlay/create/main.go b/internal/app/wwctl/overlay/create/main.go index 731d0a67..95d31c90 100644 --- a/internal/app/wwctl/overlay/create/main.go +++ b/internal/app/wwctl/overlay/create/main.go @@ -1,7 +1,7 @@ package create import ( - "github.com/hpcng/warewulf/internal/pkg/assets" + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/overlay" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/spf13/cobra" @@ -11,7 +11,6 @@ import ( func CobraRunE(cmd *cobra.Command, args []string) error { - if len(args) < 1 { cmd.Help() os.Exit(1) @@ -34,13 +33,19 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } if NoOverlayUpdate == false { - nodes, err := assets.FindAllNodes() + n, err := node.New() + if err != nil { + wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err) + os.Exit(1) + } + + nodes, err := n.FindAllNodes() if err != nil { wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err) os.Exit(1) } - var updateNodes []assets.NodeInfo + var updateNodes []node.NodeInfo for _, node := range nodes { if SystemOverlay == true && node.SystemOverlay == args[0] { diff --git a/internal/app/wwctl/overlay/delete/main.go b/internal/app/wwctl/overlay/delete/main.go index 709b0ad3..05fbbc25 100644 --- a/internal/app/wwctl/overlay/delete/main.go +++ b/internal/app/wwctl/overlay/delete/main.go @@ -2,8 +2,8 @@ package delete import ( "fmt" - "github.com/hpcng/warewulf/internal/pkg/assets" "github.com/hpcng/warewulf/internal/pkg/config" + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/overlay" "github.com/hpcng/warewulf/internal/pkg/util" "github.com/hpcng/warewulf/internal/pkg/wwlog" @@ -95,13 +95,19 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } if NoOverlayUpdate == false { - nodes, err := assets.FindAllNodes() + n, err := node.New() + if err != nil { + wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err) + os.Exit(1) + } + + nodes, err := n.FindAllNodes() if err != nil { wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err) os.Exit(1) } - var updateNodes []assets.NodeInfo + var updateNodes []node.NodeInfo for _, node := range nodes { if SystemOverlay == true && node.SystemOverlay == args[0] { diff --git a/internal/app/wwctl/overlay/edit/main.go b/internal/app/wwctl/overlay/edit/main.go index b53fe5b5..1b68e538 100644 --- a/internal/app/wwctl/overlay/edit/main.go +++ b/internal/app/wwctl/overlay/edit/main.go @@ -2,8 +2,8 @@ package edit import ( "fmt" - "github.com/hpcng/warewulf/internal/pkg/assets" "github.com/hpcng/warewulf/internal/pkg/config" + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/overlay" "github.com/hpcng/warewulf/internal/pkg/util" "github.com/hpcng/warewulf/internal/pkg/wwlog" @@ -93,13 +93,19 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } if NoOverlayUpdate == false { - nodes, err := assets.FindAllNodes() + n, err := node.New() + if err != nil { + wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err) + os.Exit(1) + } + + nodes, err := n.FindAllNodes() if err != nil { wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err) os.Exit(1) } - var updateNodes []assets.NodeInfo + var updateNodes []node.NodeInfo for _, node := range nodes { if SystemOverlay == true && node.SystemOverlay == args[0] { diff --git a/internal/app/wwctl/overlay/imprt/main.go b/internal/app/wwctl/overlay/imprt/main.go index 8035176e..0ce1c3b1 100644 --- a/internal/app/wwctl/overlay/imprt/main.go +++ b/internal/app/wwctl/overlay/imprt/main.go @@ -1,8 +1,8 @@ package imprt import ( - "github.com/hpcng/warewulf/internal/pkg/assets" "github.com/hpcng/warewulf/internal/pkg/config" + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/overlay" "github.com/hpcng/warewulf/internal/pkg/util" "github.com/hpcng/warewulf/internal/pkg/wwlog" @@ -45,13 +45,19 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } if NoOverlayUpdate == false { - nodes, err := assets.FindAllNodes() + n, err := node.New() + if err != nil { + wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err) + os.Exit(1) + } + + nodes, err := n.FindAllNodes() if err != nil { wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err) os.Exit(1) } - var updateNodes []assets.NodeInfo + var updateNodes []node.NodeInfo for _, node := range nodes { if SystemOverlay == true && node.SystemOverlay == overlayName { diff --git a/internal/app/wwctl/overlay/list/main.go b/internal/app/wwctl/overlay/list/main.go index 1257c18a..1b51fff9 100644 --- a/internal/app/wwctl/overlay/list/main.go +++ b/internal/app/wwctl/overlay/list/main.go @@ -2,8 +2,8 @@ package list import ( "fmt" - "github.com/hpcng/warewulf/internal/pkg/assets" "github.com/hpcng/warewulf/internal/pkg/config" + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/overlay" "github.com/hpcng/warewulf/internal/pkg/util" "github.com/hpcng/warewulf/internal/pkg/wwlog" @@ -17,7 +17,13 @@ func CobraRunE(cmd *cobra.Command, args []string) error { set := make(map[string]int) var o []string var err error - var nodeList []assets.NodeInfo + var nodeList []node.NodeInfo + + n, err := node.New() + if err != nil { + wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err) + os.Exit(1) + } if SystemOverlay == true { if ListLong == false { @@ -39,7 +45,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { return err } - nodeList, err = assets.FindAllNodes() + nodeList, err = n.FindAllNodes() if err != nil { wwlog.Printf(wwlog.ERROR, "Could not get node configuration: %s\n", err) return err diff --git a/internal/app/wwctl/overlay/mkdir/main.go b/internal/app/wwctl/overlay/mkdir/main.go index 956f9682..62dfe7c8 100644 --- a/internal/app/wwctl/overlay/mkdir/main.go +++ b/internal/app/wwctl/overlay/mkdir/main.go @@ -2,8 +2,8 @@ package mkdir import ( "fmt" - "github.com/hpcng/warewulf/internal/pkg/assets" "github.com/hpcng/warewulf/internal/pkg/config" + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/overlay" "github.com/hpcng/warewulf/internal/pkg/util" "github.com/hpcng/warewulf/internal/pkg/wwlog" @@ -42,13 +42,19 @@ func CobraRunE(cmd *cobra.Command, args []string) error { fmt.Printf("Created directory within overlay: %s:%s\n", args[0], args[1]) if NoOverlayUpdate == false { - nodes, err := assets.FindAllNodes() + n, err := node.New() + if err != nil { + wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err) + os.Exit(1) + } + + nodes, err := n.FindAllNodes() if err != nil { wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err) os.Exit(1) } - var updateNodes []assets.NodeInfo + var updateNodes []node.NodeInfo for _, node := range nodes { if SystemOverlay == true && node.SystemOverlay == args[0] { diff --git a/internal/app/wwctl/vnfs/build/main.go b/internal/app/wwctl/vnfs/build/main.go index e33a51bb..92590ae8 100644 --- a/internal/app/wwctl/vnfs/build/main.go +++ b/internal/app/wwctl/vnfs/build/main.go @@ -2,7 +2,7 @@ package build import ( "fmt" - "github.com/hpcng/warewulf/internal/pkg/assets" + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/vnfs" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/spf13/cobra" @@ -10,12 +10,18 @@ import ( ) func CobraRunE(cmd *cobra.Command, args []string) error { - var nodes []assets.NodeInfo + var nodes []node.NodeInfo set := make(map[string]int) + n, err := node.New() + if err != nil { + wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err) + os.Exit(1) + } + if len(args) == 1 && ByNode == true { var err error - nodes, err = assets.SearchByName(args[0]) + nodes, err = n.SearchByName(args[0]) if err != nil { wwlog.Printf(wwlog.ERROR, "Could not find nodes for search term: %s\n", args[0]) os.Exit(1) @@ -27,7 +33,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } else if BuildAll == true { var err error - nodes, err = assets.FindAllNodes() + nodes, err = n.FindAllNodes() if err != nil { wwlog.Printf(wwlog.ERROR, "Could not get list of nodes: %s\n", err) os.Exit(1) diff --git a/internal/app/wwctl/vnfs/list/main.go b/internal/app/wwctl/vnfs/list/main.go new file mode 100644 index 00000000..045fb2df --- /dev/null +++ b/internal/app/wwctl/vnfs/list/main.go @@ -0,0 +1,27 @@ +package list + +import ( + "fmt" + "github.com/hpcng/warewulf/internal/pkg/config" + "github.com/hpcng/warewulf/internal/pkg/wwlog" + "github.com/spf13/cobra" + "io/ioutil" + "os" +) + +func CobraRunE(cmd *cobra.Command, args []string) error { + config := config.New() + + files, err := ioutil.ReadDir(config.VnfsImageParentDir()) + if err != nil { + wwlog.Printf(wwlog.ERROR, "%s\n", err) + os.Exit(1) + } + + for _, f := range files { + fmt.Println(f.Name()) + } + + fmt.Printf("VNFS LIST: work in progress: %s\n", config.VnfsImageParentDir()) + return nil +} \ No newline at end of file diff --git a/internal/app/wwctl/vnfs/list/root.go b/internal/app/wwctl/vnfs/list/root.go new file mode 100644 index 00000000..42ce77dc --- /dev/null +++ b/internal/app/wwctl/vnfs/list/root.go @@ -0,0 +1,25 @@ +package list + +import "github.com/spf13/cobra" + +var ( + baseCmd = &cobra.Command{ + Use: "list", + Short: "List VNFS images", + Long: "List VNFS images ", + RunE: CobraRunE, + } + SystemOverlay bool + BuildAll bool +) + +func init() { + baseCmd.PersistentFlags().BoolVarP(&SystemOverlay, "system", "s", false, "Show System Overlays as well") + baseCmd.PersistentFlags().BoolVarP(&BuildAll, "all", "a", false, "Build all overlays (runtime and system)") + +} + +// GetRootCommand returns the root cobra.Command for the application. +func GetCommand() *cobra.Command { + return baseCmd +} diff --git a/internal/app/wwctl/vnfs/root.go b/internal/app/wwctl/vnfs/root.go index ab32a8d6..851d1d2b 100644 --- a/internal/app/wwctl/vnfs/root.go +++ b/internal/app/wwctl/vnfs/root.go @@ -2,6 +2,7 @@ package vnfs import ( "github.com/hpcng/warewulf/internal/app/wwctl/vnfs/build" + "github.com/hpcng/warewulf/internal/app/wwctl/vnfs/list" "github.com/spf13/cobra" ) @@ -16,7 +17,7 @@ var ( func init() { baseCmd.AddCommand(build.GetCommand()) - + baseCmd.AddCommand(list.GetCommand()) } // GetRootCommand returns the root cobra.Command for the application. diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go index 60276073..5f3f6a35 100644 --- a/internal/pkg/config/config.go +++ b/internal/pkg/config/config.go @@ -84,6 +84,14 @@ func (self *Config) RuntimeOverlayDir() string { return path.Join(self.OverlayDir(), "/runtime") } +func (self *Config) VnfsImageParentDir() string { + return fmt.Sprintf("%s/provision/vnfs/", self.LocalStateDir) +} + +func (self *Config) VnfsChrootParentDir() string { + return fmt.Sprintf("%s/chroot/", self.LocalStateDir) +} + func (self *Config) SystemOverlaySource(overlayName string) string { if overlayName == "" { wwlog.Printf(wwlog.ERROR, "System overlay name is not defined\n") @@ -141,20 +149,6 @@ func (self *Config) KmodsImage(kernelVersion string) string { return fmt.Sprintf("%s/provision/kernel/kmods-%s.img", self.LocalStateDir, kernelVersion) } -func (self *Config) VnfsImage(vnfsNameClean string) string { - if vnfsNameClean == "" { - wwlog.Printf(wwlog.ERROR, "VNFS name is not defined\n") - return "" - } - - if util.TaintCheck(vnfsNameClean, "^[a-zA-Z0-9-._:]+$") == false { - wwlog.Printf(wwlog.ERROR, "Runtime overlay name contains illegal characters: %s\n", vnfsNameClean) - return "" - } - - return fmt.Sprintf("%s/provision/vnfs/%s.img.gz", self.LocalStateDir, vnfsNameClean) -} - func (self *Config) SystemOverlayImage(nodeName string) string { if nodeName == "" { wwlog.Printf(wwlog.ERROR, "Node name is not defined\n") @@ -183,6 +177,21 @@ func (self *Config) RuntimeOverlayImage(nodeName string) string { return fmt.Sprintf("%s/provision/overlays/runtime/%s.img", self.LocalStateDir, nodeName) } + +func (self *Config) VnfsImage(vnfsNameClean string) string { + if vnfsNameClean == "" { + wwlog.Printf(wwlog.ERROR, "VNFS name is not defined\n") + return "" + } + + if util.TaintCheck(vnfsNameClean, "^[a-zA-Z0-9-._:]+$") == false { + wwlog.Printf(wwlog.ERROR, "Runtime overlay name contains illegal characters: %s\n", vnfsNameClean) + return "" + } + + return path.Join(self.VnfsImageParentDir(), vnfsNameClean) +} + func (self *Config) VnfsChroot(vnfsNameClean string) string { if vnfsNameClean == "" { wwlog.Printf(wwlog.ERROR, "VNFS name is not defined\n") @@ -194,6 +203,6 @@ func (self *Config) VnfsChroot(vnfsNameClean string) string { return "" } - return fmt.Sprintf("%s/chroot/%s.img", self.LocalStateDir, vnfsNameClean) + return path.Join(self.VnfsChrootParentDir(), vnfsNameClean) } diff --git a/internal/pkg/assets/assets.go b/internal/pkg/node/node.go similarity index 69% rename from internal/pkg/assets/assets.go rename to internal/pkg/node/node.go index e027ad53..c69f29fa 100644 --- a/internal/pkg/assets/assets.go +++ b/internal/pkg/node/node.go @@ -1,19 +1,15 @@ -package assets +package node import ( "fmt" "github.com/hpcng/warewulf/internal/pkg/config" + "github.com/hpcng/warewulf/internal/pkg/errors" "github.com/hpcng/warewulf/internal/pkg/util" "github.com/hpcng/warewulf/internal/pkg/vnfs" "github.com/hpcng/warewulf/internal/pkg/wwlog" "gopkg.in/yaml.v2" "io/ioutil" - // "os" - - // "os" "regexp" - - "github.com/hpcng/warewulf/internal/pkg/errors" ) const ConfigFile = "/etc/warewulf/nodes.conf" @@ -50,6 +46,8 @@ type nodeEntry struct { KernelVersion string `yaml:"kernel version"` KernelArgs string `yaml:"kernel args"` IpmiIpaddr string `yaml:"ipmi ipaddr"` + IpmiUserName string `yaml:"ipmi username"` + IpmiPassword string `yaml:"ipmi password"` NetDevs map[string]netDevs } @@ -74,25 +72,32 @@ type NodeInfo struct { KernelVersion string KernelArgs string IpmiIpaddr string + IpmiUserName string + IpmiPassword string NetDevs map[string]netDevs } -func FindAllNodes() ([]NodeInfo, error) { - var c nodeYaml - var ret []NodeInfo - config := config.New() +type nodeInfoContainer struct { + Nodes []NodeInfo +} +func New() (nodeInfoContainer, error) { + var c nodeYaml + var ret nodeInfoContainer + + config := config.New() + wwlog.Printf(wwlog.DEBUG, "Opening configuration file: %s\n", ConfigFile) data, err := ioutil.ReadFile(ConfigFile) if err != nil { fmt.Printf("error reading node configuration file\n") - return nil, err + return ret, err } err = yaml.Unmarshal(data, &c) if err != nil { - return nil, err + return ret, err } for groupname, group := range c.NodeGroups { @@ -102,6 +107,8 @@ func FindAllNodes() ([]NodeInfo, error) { n.GroupName = groupname n.HostName = node.Hostname n.IpmiIpaddr = node.IpmiIpaddr + n.IpmiUserName = node.IpmiUserName + n.IpmiPassword = node.IpmiPassword n.Vnfs = group.Vnfs n.SystemOverlay = group.SystemOverlay @@ -161,7 +168,7 @@ func FindAllNodes() ([]NodeInfo, error) { v := vnfs.New(n.Vnfs) n.VnfsDir = config.VnfsChroot(v.NameClean()) - ret = append(ret, n) + ret.Nodes = append(ret.Nodes, n) } } @@ -169,15 +176,17 @@ func FindAllNodes() ([]NodeInfo, error) { } -func FindByHwaddr(hwa string) (NodeInfo, error) { + + +func (nodes *nodeInfoContainer) FindAllNodes() ([]NodeInfo, error) { + return nodes.Nodes, nil +} + + +func (nodes *nodeInfoContainer) FindByHwaddr(hwa string) (NodeInfo, error) { var ret NodeInfo - nodeList, err := FindAllNodes() - if err != nil { - return ret, err - } - - for _, node := range nodeList { + for _, node := range nodes.Nodes { for _, dev := range node.NetDevs { if dev.Hwaddr == hwa { return node, nil @@ -188,15 +197,10 @@ func FindByHwaddr(hwa string) (NodeInfo, error) { return ret, errors.New("No nodes found with HW Addr: " + hwa) } -func FindByIpaddr(ipaddr string) (NodeInfo, error) { +func (nodes *nodeInfoContainer) FindByIpaddr(ipaddr string) (NodeInfo, error) { var ret NodeInfo - nodeList, err := FindAllNodes() - if err != nil { - return ret, err - } - - for _, node := range nodeList { + for _, node := range nodes.Nodes { for _, dev := range node.NetDevs { if dev.Ipaddr == ipaddr { return node, nil @@ -207,15 +211,10 @@ func FindByIpaddr(ipaddr string) (NodeInfo, error) { return ret, errors.New("No nodes found with IP Addr: " + ipaddr) } -func SearchByName(search string) ([]NodeInfo, error) { +func (nodes *nodeInfoContainer) SearchByName(search string) ([]NodeInfo, error) { var ret []NodeInfo - nodeList, err := FindAllNodes() - if err != nil { - return ret, err - } - - for _, node := range nodeList { + for _, node := range nodes.Nodes { b, _ := regexp.MatchString(search, node.Fqdn) if b == true { ret = append(ret, node) @@ -225,16 +224,11 @@ func SearchByName(search string) ([]NodeInfo, error) { return ret, nil } -func SearchByNameList(searchList []string) ([]NodeInfo, error) { +func (nodes *nodeInfoContainer) SearchByNameList(searchList []string) ([]NodeInfo, error) { var ret []NodeInfo - nodeList, err := FindAllNodes() - if err != nil { - return ret, err - } - for _, search := range searchList { - for _, node := range nodeList { + for _, node := range nodes.Nodes { b, _ := regexp.MatchString(search, node.Fqdn) if b == true { ret = append(ret, node) @@ -244,94 +238,3 @@ func SearchByNameList(searchList []string) ([]NodeInfo, error) { return ret, nil } - -/* -func FindAllVnfs() ([]string, error) { - var ret []string - set := make(map[string]bool) - - nodeList, err := FindAllNodes() - if err != nil { - return ret, err - } - - for _, node := range nodeList { - if node.Vnfs != "" { - set[node.Vnfs] = true - } - } - - for entry := range set { - ret = append(ret, entry) - } - - return ret, nil -} - -func FindAllKernels() ([]string, error) { - var ret []string - set := make(map[string]bool) - - nodeList, err := FindAllNodes() - if err != nil { - return ret, err - } - - for _, node := range nodeList { - if node.KernelVersion != "" { - set[node.KernelVersion] = true - } - } - - for entry := range set { - ret = append(ret, entry) - } - - return ret, nil -} - -func ListSystemOverlays() ([]string, error) { - var ret []string - set := make(map[string]bool) - - nodeList, err := FindAllNodes() - if err != nil { - return ret, err - } - - for _, node := range nodeList { - if node.SystemOverlay != "" { - set[node.SystemOverlay] = true - } - } - - for entry := range set { - ret = append(ret, entry) - } - - return ret, nil -} - -func ListRuntimeOverlays() ([]string, error) { - var ret []string - set := make(map[string]bool) - - nodeList, err := FindAllNodes() - if err != nil { - return ret, err - } - - for _, node := range nodeList { - if node.RuntimeOverlay != "" { - set[node.RuntimeOverlay] = true - } - } - - for entry := range set { - ret = append(ret, entry) - } - - return ret, nil -} - -*/ diff --git a/internal/pkg/overlay/runtime.go b/internal/pkg/overlay/runtime.go index cc7192fb..b49cad90 100644 --- a/internal/pkg/overlay/runtime.go +++ b/internal/pkg/overlay/runtime.go @@ -2,9 +2,9 @@ package overlay import ( "fmt" - "github.com/hpcng/warewulf/internal/pkg/assets" "github.com/hpcng/warewulf/internal/pkg/config" "github.com/hpcng/warewulf/internal/pkg/errors" + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/util" "github.com/hpcng/warewulf/internal/pkg/wwlog" "io/ioutil" @@ -53,7 +53,7 @@ func RuntimeOverlayInit(name string) error { } -func RuntimeBuild(nodeList []assets.NodeInfo, force bool) error { +func RuntimeBuild(nodeList []node.NodeInfo, force bool) error { config := config.New() wwlog.SetIndent(4) diff --git a/internal/pkg/overlay/system.go b/internal/pkg/overlay/system.go index 88c529b3..08416eac 100644 --- a/internal/pkg/overlay/system.go +++ b/internal/pkg/overlay/system.go @@ -2,9 +2,9 @@ package overlay import ( "fmt" - "github.com/hpcng/warewulf/internal/pkg/assets" "github.com/hpcng/warewulf/internal/pkg/config" "github.com/hpcng/warewulf/internal/pkg/errors" + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/util" "github.com/hpcng/warewulf/internal/pkg/wwlog" "io/ioutil" @@ -53,7 +53,7 @@ func SystemOverlayInit(name string) error { } -func SystemBuild(nodeList []assets.NodeInfo, force bool) error { +func SystemBuild(nodeList []node.NodeInfo, force bool) error { config := config.New() wwlog.SetIndent(4)