diff --git a/internal/app/warewulfd/response/ipxe.go b/internal/app/warewulfd/response/ipxe.go index 11194c6e..d4efa341 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/config" "github.com/hpcng/warewulf/internal/pkg/node" + "github.com/hpcng/warewulf/internal/pkg/warewulfconf" "github.com/hpcng/warewulf/internal/pkg/wwlog" "log" "net/http" @@ -13,16 +13,15 @@ import ( ) type iPxeTemplate struct { - Hostname string - Fqdn string - Vnfs string - Hwaddr string - Ipaddr string - Port string - Kernelargs string + Hostname string + Fqdn string + Vnfs string + Hwaddr string + Ipaddr string + Port string + Kernelargs string } - func IpxeSend(w http.ResponseWriter, req *http.Request) { url := strings.Split(req.URL.Path, "/") @@ -47,9 +46,13 @@ func IpxeSend(w http.ResponseWriter, req *http.Request) { } if node.Id.Defined() == true { - conf := config.New() + conf, err := warewulfconf.New() + if err != nil { + wwlog.Printf(wwlog.ERROR, "%s\n", err) + return + } - log.Printf("IPXE: %15s: %s\n", node.Fqdn.Get(), req.URL.Path) + log.Printf("IPXE: %15s: %s\n", node.Id.Get(), req.URL.Path) // TODO: Fix template path to use config package ipxeTemplate := fmt.Sprintf("/etc/warewulf/ipxe/%s.ipxe", node.Ipxe.Get()) @@ -62,10 +65,10 @@ func IpxeSend(w http.ResponseWriter, req *http.Request) { var replace iPxeTemplate - replace.Fqdn = node.Fqdn.Get() + replace.Fqdn = node.Id.Get() replace.Ipaddr = conf.Ipaddr - replace.Port = strconv.Itoa(conf.Port) - replace.Hostname = node.HostName.Get() + replace.Port = strconv.Itoa(conf.Warewulf.Port) + replace.Hostname = node.Id.Get() replace.Hwaddr = url[2] replace.Vnfs = node.Vnfs.Get() replace.Kernelargs = node.KernelArgs.Get() @@ -76,7 +79,7 @@ func IpxeSend(w http.ResponseWriter, req *http.Request) { return } - log.Printf("SEND: %15s: %s\n", node.Fqdn.Get(), ipxeTemplate) + log.Printf("SEND: %15s: %s\n", node.Id.Get(), ipxeTemplate) } else { log.Printf("ERROR: iPXE request from unknown Node (hwaddr=%s)\n", url[2]) diff --git a/internal/app/warewulfd/response/kernel.go b/internal/app/warewulfd/response/kernel.go index f9fac3b9..a7683617 100644 --- a/internal/app/warewulfd/response/kernel.go +++ b/internal/app/warewulfd/response/kernel.go @@ -7,7 +7,6 @@ import ( ) func KernelSend(w http.ResponseWriter, req *http.Request) { - config := config.New() node, err := getSanity(req) if err != nil { @@ -19,16 +18,16 @@ func KernelSend(w http.ResponseWriter, req *http.Request) { if node.KernelVersion.Defined() == true { fileName := config.KernelImage(node.KernelVersion.Get()) - err := sendFile(w, fileName, node.Fqdn.Get()) + err := sendFile(w, fileName, node.Id.Get()) if err != nil { log.Printf("ERROR: %s\n", err) } else { - log.Printf("SEND: %15s: %s\n", node.Fqdn.Get(), fileName) + log.Printf("SEND: %15s: %s\n", node.Id.Get(), fileName) } } else { w.WriteHeader(503) - log.Printf("ERROR: No 'kernel version' set for node %s\n", node.Fqdn.Get()) + log.Printf("ERROR: No 'kernel version' set for node %s\n", node.Id.Get()) } return diff --git a/internal/app/warewulfd/response/kmods.go b/internal/app/warewulfd/response/kmods.go index 00db3605..c4366008 100644 --- a/internal/app/warewulfd/response/kmods.go +++ b/internal/app/warewulfd/response/kmods.go @@ -7,7 +7,6 @@ import ( ) func KmodsSend(w http.ResponseWriter, req *http.Request) { - config := config.New() node, err := getSanity(req) if err != nil { @@ -19,16 +18,16 @@ func KmodsSend(w http.ResponseWriter, req *http.Request) { if node.KernelVersion.Defined() == true { fileName := config.KmodsImage(node.KernelVersion.Get()) - err := sendFile(w, fileName, node.Fqdn.Get()) + err := sendFile(w, fileName, node.Id.Get()) if err != nil { log.Printf("ERROR: %s\n", err) } else { - log.Printf("SEND: %15s: %s\n", node.Fqdn.Get(), fileName) + log.Printf("SEND: %15s: %s\n", node.Id.Get(), fileName) } } else { w.WriteHeader(503) - log.Printf("ERROR: No 'kernel version' set for node %s\n", node.Fqdn.Get()) + log.Printf("ERROR: No 'kernel version' set for node %s\n", node.Id.Get()) } return diff --git a/internal/app/warewulfd/response/runtime.go b/internal/app/warewulfd/response/runtime.go index 7c784a85..ec6291b7 100644 --- a/internal/app/warewulfd/response/runtime.go +++ b/internal/app/warewulfd/response/runtime.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/hpcng/warewulf/internal/pkg/config" "github.com/hpcng/warewulf/internal/pkg/node" + "github.com/hpcng/warewulf/internal/pkg/warewulfconf" "log" "net/http" "strconv" @@ -11,7 +12,13 @@ import ( ) func RuntimeOverlaySend(w http.ResponseWriter, req *http.Request) { - config := config.New() + conf, err := warewulfconf.New() + if err != nil { + log.Printf("Could not read Warewulf configuration file: %s\n", err) + w.WriteHeader(503) + return + } + nodes, err := node.New() if err != nil { log.Printf("Could not read node configuration file: %s\n", err) @@ -32,7 +39,7 @@ func RuntimeOverlaySend(w http.ResponseWriter, req *http.Request) { return } - if config.InsecureRuntime == false { + if conf.Warewulf.Secure == true { if port >= 1024 { log.Panicf("DENIED: Connection coming from non-privledged port: %s\n", req.RemoteAddr) w.WriteHeader(401) @@ -52,21 +59,21 @@ func RuntimeOverlaySend(w http.ResponseWriter, req *http.Request) { w.WriteHeader(404) return } else { - log.Printf("REQ: %15s: %s\n", node.Fqdn.Get(), req.URL.Path) + log.Printf("REQ: %15s: %s\n", node.Id.Get(), req.URL.Path) } if node.RuntimeOverlay.Defined() == true { - fileName := config.RuntimeOverlayImage(node.Fqdn.Get()) + fileName := config.RuntimeOverlayImage(node.Id.Get()) - err := sendFile(w, fileName, node.Fqdn.Get()) + err := sendFile(w, fileName, node.Id.Get()) if err != nil { log.Printf("ERROR: %s\n", err) } else { - log.Printf("SEND: %15s: %s\n", node.Fqdn.Get(), fileName) + log.Printf("SEND: %15s: %s\n", node.Id.Get(), fileName) } } else { w.WriteHeader(503) - log.Printf("ERROR: No 'runtime system-overlay' set for node %s\n", node.Fqdn.Get()) + log.Printf("ERROR: No 'runtime system-overlay' set for node %s\n", node.Id.Get()) } return diff --git a/internal/app/warewulfd/response/system.go b/internal/app/warewulfd/response/system.go index 2a28cd56..3a3cf285 100644 --- a/internal/app/warewulfd/response/system.go +++ b/internal/app/warewulfd/response/system.go @@ -7,8 +7,6 @@ import ( ) func SystemOverlaySend(w http.ResponseWriter, req *http.Request) { - config := config.New() - node, err := getSanity(req) if err != nil { w.WriteHeader(404) @@ -17,17 +15,17 @@ func SystemOverlaySend(w http.ResponseWriter, req *http.Request) { } if node.SystemOverlay.Defined() == true { - fileName := config.SystemOverlayImage(node.Fqdn.Get()) + fileName := config.SystemOverlayImage(node.Id.Get()) - err := sendFile(w, fileName, node.Fqdn.Get()) + err := sendFile(w, fileName, node.Id.Get()) if err != nil { log.Printf("ERROR: %s\n", err) } else { - log.Printf("SEND: %15s: %s\n", node.Fqdn.Get(), fileName) + log.Printf("SEND: %15s: %s\n", node.Id.Get(), fileName) } } else { w.WriteHeader(503) - log.Printf("ERROR: No 'system system-overlay' set for node %s\n", node.Fqdn.Get()) + log.Printf("ERROR: No 'system system-overlay' set for node %s\n", node.Id.Get()) } return diff --git a/internal/app/warewulfd/response/util.go b/internal/app/warewulfd/response/util.go index f4ccc79a..8ef67270 100644 --- a/internal/app/warewulfd/response/util.go +++ b/internal/app/warewulfd/response/util.go @@ -27,12 +27,7 @@ func getSanity(req *http.Request) (node.NodeInfo, error) { return ret, errors.New("Could not find node by HW address") } - if ret.Fqdn.Defined() == false { - log.Printf("UNKNOWN: %15s: %s\n", hwaddr, req.URL.Path) - return ret, errors.New("Unknown node HW address: " + hwaddr) - } else { - log.Printf("REQ: %15s: %s\n", ret.Fqdn.Get(), req.URL.Path) - } + log.Printf("REQ: %15s: %s\n", ret.Id.Get(), req.URL.Path) return ret, nil } diff --git a/internal/app/warewulfd/response/vnfs.go b/internal/app/warewulfd/response/vnfs.go index e6e84a18..5ef72c0e 100644 --- a/internal/app/warewulfd/response/vnfs.go +++ b/internal/app/warewulfd/response/vnfs.go @@ -20,19 +20,19 @@ func VnfsSend(w http.ResponseWriter, req *http.Request) { v, err := vnfs.Load(node.Vnfs.Get()) if err != nil { w.WriteHeader(503) - log.Printf("ERROR: Could not load VNFS: %s\n", node.Fqdn.Get()) + log.Printf("ERROR: Could not load VNFS: %s\n", node.Id.Get()) return } - err = sendFile(w, v.Image, node.Fqdn.Get()) + err = sendFile(w, v.Image, node.Id.Get()) if err != nil { log.Printf("ERROR1: %s\n", err) } else { - log.Printf("SEND: %15s: %s\n", node.Fqdn.Get(), v.Image) + log.Printf("SEND: %15s: %s\n", node.Id.Get(), v.Image) } } else { w.WriteHeader(503) - log.Printf("ERROR: No VNFS set for node %s\n", node.Fqdn.Get()) + log.Printf("ERROR: No VNFS set for node %s\n", node.Id.Get()) } return diff --git a/internal/app/wwctl/group/add/main.go b/internal/app/wwctl/group/add/main.go deleted file mode 100644 index 8b4bdadb..00000000 --- a/internal/app/wwctl/group/add/main.go +++ /dev/null @@ -1,29 +0,0 @@ -package add - -import ( - "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 { - nodeDB, err := node.New() - if err != nil { - wwlog.Printf(wwlog.ERROR, "Failed opening node database: %s\n", err) - os.Exit(1) - } - - for _, g := range args { - err = nodeDB.AddGroup(SetController, g) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - os.Exit(1) - } - } - - nodeDB.Persist() - - return nil -} - diff --git a/internal/app/wwctl/group/add/root.go b/internal/app/wwctl/group/add/root.go deleted file mode 100644 index c0f52360..00000000 --- a/internal/app/wwctl/group/add/root.go +++ /dev/null @@ -1,24 +0,0 @@ -package add - -import "github.com/spf13/cobra" - -var ( - baseCmd = &cobra.Command{ - Use: "add", - Short: "Add a new node group", - Long: "Add a new node group ", - RunE: CobraRunE, - Args: cobra.MinimumNArgs(1), - } - SetController string -) - -func init() { - baseCmd.PersistentFlags().StringVarP(&SetController, "controller", "c", "localhost", "Controller to add group to") - -} - -// GetRootCommand returns the root cobra.Command for the application. -func GetCommand() *cobra.Command { - return baseCmd -} diff --git a/internal/app/wwctl/group/delete/main.go b/internal/app/wwctl/group/delete/main.go deleted file mode 100644 index 5e3120c5..00000000 --- a/internal/app/wwctl/group/delete/main.go +++ /dev/null @@ -1,61 +0,0 @@ -package delete - -import ( - "fmt" - "github.com/hpcng/warewulf/internal/pkg/node" - "github.com/hpcng/warewulf/internal/pkg/wwlog" - "github.com/manifoldco/promptui" - "github.com/spf13/cobra" - "os" -) - -func CobraRunE(cmd *cobra.Command, args []string) error { - var count int - var numNodes int - - nodeDB, err := node.New() - if err != nil { - wwlog.Printf(wwlog.ERROR, "Failed to open node database: %s\n", err) - os.Exit(1) - } - - nodes, err := nodeDB. FindAllNodes() - if err != nil { - wwlog.Printf(wwlog.ERROR, "Could not load all nodes: %s\n", err) - os.Exit(1) - } - - for _, g := range args { - err := nodeDB.DelGroup(SetController, g) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - } else { - for _, n := range nodes { - if n.Gid.Get() == g { - numNodes ++ - } - } - count ++ - } - } - - if count > 0 { - q := fmt.Sprintf("Are you sure you want to delete %d group(s) (%d nodes)", count, numNodes) - - prompt := promptui.Prompt{ - Label: q, - IsConfirm: true, - } - - result, _ := prompt.Run() - - if result == "y" || result == "yes" { - nodeDB.Persist() - } - - } else { - wwlog.Printf(wwlog.INFO, "No groups found\n") - } - - return nil -} diff --git a/internal/app/wwctl/group/delete/root.go b/internal/app/wwctl/group/delete/root.go deleted file mode 100644 index bb343acd..00000000 --- a/internal/app/wwctl/group/delete/root.go +++ /dev/null @@ -1,22 +0,0 @@ -package delete - -import "github.com/spf13/cobra" - -var ( - baseCmd = &cobra.Command{ - Use: "delete", - Short: "Add a new node group", - Long: "Add a new node group ", - RunE: CobraRunE, - } - SetController string -) - -func init() { - baseCmd.PersistentFlags().StringVarP(&SetController, "controller", "c", "default", "Controller to add group to") -} - -// GetRootCommand returns the root cobra.Command for the application. -func GetCommand() *cobra.Command { - return baseCmd -} diff --git a/internal/app/wwctl/group/list/main.go b/internal/app/wwctl/group/list/main.go deleted file mode 100644 index e1154c9d..00000000 --- a/internal/app/wwctl/group/list/main.go +++ /dev/null @@ -1,51 +0,0 @@ -package list - -import ( - "fmt" - "github.com/hpcng/warewulf/internal/pkg/node" - "github.com/hpcng/warewulf/internal/pkg/wwlog" - "github.com/spf13/cobra" - "os" - "strings" -) - -func CobraRunE(cmd *cobra.Command, args []string) error { - nodeDB, err := node.New() - if err != nil { - wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err) - os.Exit(1) - } - - groups, err := nodeDB.FindAllGroups() - if err != nil { - wwlog.Printf(wwlog.ERROR, "Could not find all nodes: %s\n", err) - os.Exit(1) - } - - if ShowAll == true { - for _, group := range groups { - fmt.Printf("################################################################################\n") - fmt.Printf("%-20s %-18s %8s: %s\n", group.Id.Get(), "Id", group.Id.Source(), group.Id.Print()) - fmt.Printf("%-20s %-18s %8s: %s\n", group.Id.Get(), "Controller", group.Cid.Source(), group.Cid.Print()) - fmt.Printf("%-20s %-18s %8s: %s\n", group.Id.Get(), "DomainName", group.DomainName.Source(), group.DomainName.Print()) - fmt.Printf("%-20s %-18s %8s: %s\n", group.Id.Get(), "VNFS", group.Vnfs.Source(), group.Vnfs.Print()) - fmt.Printf("%-20s %-18s %8s: %s\n", group.Id.Get(), "KernelVersion", group.KernelVersion.Source(), group.KernelVersion.Print()) - fmt.Printf("%-20s %-18s %8s: %s\n", group.Id.Get(), "KernelArgs", group.KernelArgs.Source(), group.KernelArgs.Print()) - fmt.Printf("%-20s %-18s %8s: %s\n", group.Id.Get(), "RuntimeOverlay", group.RuntimeOverlay.Source(), group.RuntimeOverlay.Print()) - fmt.Printf("%-20s %-18s %8s: %s\n", group.Id.Get(), "SystemOverlay", group.SystemOverlay.Source(), group.SystemOverlay.Print()) - fmt.Printf("%-20s %-18s %8s: %s\n", group.Id.Get(), "IPMI Netmask", group.IpmiNetmask.Source(), group.IpmiNetmask.Print()) - fmt.Printf("%-20s %-18s %8s: %s\n", group.Id.Get(), "IPMI UserName", group.IpmiUserName.Source(), group.IpmiUserName.Print()) - fmt.Printf("%-20s %-18s %8s: %s\n", group.Id.Get(), "IPMI Password", group.IpmiPassword.Source(), group.IpmiPassword.Print()) - fmt.Printf("%-20s %-18s %8s: %s\n", group.Id.Get(), "Ipxe", group.Ipxe.Source(), group.Ipxe.Print()) - fmt.Printf("%-20s %-18s %8s: %s\n", group.Id.Get(), "Profiles", "group", strings.Join(group.Profiles, ",")) - - } - } else { - fmt.Printf("%-22s %-16s %-16s %s\n", "GROUP NAME", "DOMAINNAME", "CONTROLLER", "PROFILES") - for _, g := range groups { - fmt.Printf("%-22s %-16s %-16s %s\n", g.Id.Get(), g.DomainName.Get(), g.Cid.Get(), strings.Join(g.Profiles, ",")) - } - } - - return nil -} diff --git a/internal/app/wwctl/group/list/root.go b/internal/app/wwctl/group/list/root.go deleted file mode 100644 index 5d0183f8..00000000 --- a/internal/app/wwctl/group/list/root.go +++ /dev/null @@ -1,23 +0,0 @@ -package list - -import "github.com/spf13/cobra" - -var ( - baseCmd = &cobra.Command{ - Use: "list", - Short: "List group configurations", - Long: "List group configurations ", - RunE: CobraRunE, - } - ShowAll bool -) - -func init() { - baseCmd.PersistentFlags().BoolVarP(&ShowAll, "all", "a", false, "Show all node configurations") - -} - -// GetRootCommand returns the root cobra.Command for the application. -func GetCommand() *cobra.Command { - return baseCmd -} diff --git a/internal/app/wwctl/group/root.go b/internal/app/wwctl/group/root.go deleted file mode 100644 index 98cf1ebb..00000000 --- a/internal/app/wwctl/group/root.go +++ /dev/null @@ -1,29 +0,0 @@ -package group - -import ( - "github.com/hpcng/warewulf/internal/app/wwctl/group/add" - "github.com/hpcng/warewulf/internal/app/wwctl/group/delete" - "github.com/hpcng/warewulf/internal/app/wwctl/group/list" - "github.com/hpcng/warewulf/internal/app/wwctl/group/set" - "github.com/spf13/cobra" -) - -var ( - baseCmd = &cobra.Command{ - Use: "group", - Short: "Group management", - Long: "Management of group settings and power management", - } -) - -func init() { - baseCmd.AddCommand(list.GetCommand()) - baseCmd.AddCommand(set.GetCommand()) - baseCmd.AddCommand(add.GetCommand()) - baseCmd.AddCommand(delete.GetCommand()) -} - -// GetRootCommand returns the root cobra.Command for the application. -func GetCommand() *cobra.Command { - return baseCmd -} diff --git a/internal/app/wwctl/group/set/main.go b/internal/app/wwctl/group/set/main.go deleted file mode 100644 index 6808f2ce..00000000 --- a/internal/app/wwctl/group/set/main.go +++ /dev/null @@ -1,183 +0,0 @@ -package set - -import ( - "fmt" - "github.com/hpcng/warewulf/internal/pkg/node" - "github.com/hpcng/warewulf/internal/pkg/util" - "github.com/hpcng/warewulf/internal/pkg/wwlog" - "github.com/manifoldco/promptui" - "github.com/spf13/cobra" - "os" -) - -func CobraRunE(cmd *cobra.Command, args []string) error { - var err error - var groups []node.GroupInfo - - nodeDB, err := node.New() - if err != nil { - wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err) - os.Exit(1) - } - - if err != nil { - wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err) - os.Exit(1) - } - - if len(args) == 0 { - args = append(args, "default") - } - - if SetGroupAll == true { - groups, err = nodeDB.FindAllGroups() - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - os.Exit(1) - } - - } else { - var tmp []node.GroupInfo - tmp, err = nodeDB.FindAllGroups() - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - os.Exit(1) - } - - for _, a := range args { - for _, g := range tmp { - if g.Id.Get() == a { - groups = append(groups, g) - } - } - } - } - - for _, g := range groups { - - if SetDomainName != "" { - wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting domain name to: %s\n", g.Id, SetDomainName) - - g.DomainName.SetGroup(SetDomainName) - err := nodeDB.GroupUpdate(g) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - os.Exit(1) - } - } - if SetVnfs != "" { - wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting VNFS to: %s\n", g.Id, SetVnfs) - - g.Vnfs.SetGroup(SetVnfs) - err := nodeDB.GroupUpdate(g) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - os.Exit(1) - } - } - if SetKernel != "" { - wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting kernel to: %s\n", g.Id, SetKernel) - - g.KernelVersion.SetGroup(SetKernel) - err := nodeDB.GroupUpdate(g) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - os.Exit(1) - } - } - if SetIpmiNetmask != "" { - wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting IPMI username to: %s\n", g.Id, SetIpmiNetmask) - - g.IpmiNetmask.SetGroup(SetIpmiNetmask) - err := nodeDB.GroupUpdate(g) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - os.Exit(1) - } - } - if SetIpmiUsername != "" { - wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting IPMI username to: %s\n", g.Id, SetIpmiUsername) - - g.IpmiUserName.SetGroup(SetIpmiUsername) - err := nodeDB.GroupUpdate(g) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - os.Exit(1) - } - } - if SetIpmiPassword != "" { - wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting IPMI password to: %s\n", g.Id, SetIpmiPassword) - - g.IpmiPassword.SetGroup(SetIpmiPassword) - err := nodeDB.GroupUpdate(g) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - os.Exit(1) - } - } - if SetSystemOverlay != "" { - wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting system overlay to: %s\n", g.Id, SetSystemOverlay) - - g.SystemOverlay.SetGroup(SetSystemOverlay) - err := nodeDB.GroupUpdate(g) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - os.Exit(1) - } - } - if SetRuntimeOverlay != "" { - wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting runtime overlay to: %s\n", g.Id, SetRuntimeOverlay) - - g.RuntimeOverlay.SetGroup(SetRuntimeOverlay) - err := nodeDB.GroupUpdate(g) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - os.Exit(1) - } - } - - if len(SetAddProfile) > 0 { - for _, p := range SetAddProfile { - wwlog.Printf(wwlog.VERBOSE, "Adding profile to '%s': '%s'\n", g.Id, p) - g.Profiles = util.SliceAddUniqueElement(g.Profiles, p) - } - err := nodeDB.GroupUpdate(g) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - os.Exit(1) - } - } - if len(SetDelProfile) > 0 { - for _, p := range SetDelProfile { - wwlog.Printf(wwlog.VERBOSE, "Removing profile to '%s': '%s'\n", g.Id, p) - g.Profiles = util.SliceRemoveElement(g.Profiles, p) - } - err := nodeDB.GroupUpdate(g) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - os.Exit(1) - } - } - - } - - if len(groups) > 0 { - q := fmt.Sprintf("Are you sure you want to modify %d group(s)", len(groups)) - - prompt := promptui.Prompt{ - Label: q, - IsConfirm: true, - } - - result, _ := prompt.Run() - - if result == "y" || result == "yes" { - nodeDB.Persist() - } - - } else { - fmt.Printf("No groups found\n") - } - - return nil -} diff --git a/internal/app/wwctl/group/set/root.go b/internal/app/wwctl/group/set/root.go deleted file mode 100644 index e0fd632b..00000000 --- a/internal/app/wwctl/group/set/root.go +++ /dev/null @@ -1,49 +0,0 @@ -package set - -import "github.com/spf13/cobra" - -var ( - baseCmd = &cobra.Command{ - Use: "set", - Short: "Set group configurations", - Long: "Set group configurations ", - RunE: CobraRunE, - } - SetVnfs string - SetKernel string - SetDomainName string - SetIpxe string - SetRuntimeOverlay string - SetSystemOverlay string - SetClearNodes bool - SetIpmiNetmask string - SetIpmiUsername string - SetIpmiPassword string - SetGroupAll bool - SetAddProfile []string - SetDelProfile []string -) - -func init() { - baseCmd.PersistentFlags().StringVarP(&SetVnfs, "vnfs", "V", "", "Set node Virtual Node File System (VNFS)") - baseCmd.PersistentFlags().StringVarP(&SetKernel, "kernel", "K", "", "Set Kernel version for nodes") - baseCmd.PersistentFlags().StringVarP(&SetDomainName, "domain", "D", "", "Set the node's domain name") - baseCmd.PersistentFlags().StringVarP(&SetIpxe, "ipxe", "P", "", "Set the node's iPXE template name") - baseCmd.PersistentFlags().StringVarP(&SetRuntimeOverlay, "runtime", "R", "", "Set the node's runtime overlay") - baseCmd.PersistentFlags().StringVarP(&SetSystemOverlay, "system", "S", "", "Set the node's system overlay") - baseCmd.PersistentFlags().StringVar(&SetIpmiNetmask, "ipminetmask", "", "Set the node's IPMI netmask") - baseCmd.PersistentFlags().StringVar(&SetIpmiUsername, "ipmiuser", "", "Set the node's IPMI username") - baseCmd.PersistentFlags().StringVar(&SetIpmiPassword, "ipmipass", "", "Set the node's IPMI password") - - baseCmd.PersistentFlags().StringSliceVarP(&SetAddProfile, "addprofile", "p", []string{}, "Add Profile(s) to group") - baseCmd.PersistentFlags().StringSliceVarP(&SetDelProfile, "delprofile", "r", []string{}, "Remove Profile(s) to group") - - baseCmd.PersistentFlags().BoolVarP(&SetClearNodes, "clear", "c", false, "Clear node configurations when setting parent group") - baseCmd.PersistentFlags().BoolVarP(&SetGroupAll, "all", "a", false, "Set all nodes") - -} - -// GetRootCommand returns the root cobra.Command for the application. -func GetCommand() *cobra.Command { - return baseCmd -} diff --git a/internal/app/wwctl/kernel/list/main.go b/internal/app/wwctl/kernel/list/main.go index db55ba4d..87b25e76 100644 --- a/internal/app/wwctl/kernel/list/main.go +++ b/internal/app/wwctl/kernel/list/main.go @@ -13,7 +13,6 @@ import ( ) func CobraRunE(cmd *cobra.Command, args []string) error { - config := config.New() nconfig, _ := node.New() nodes, _ := nconfig.FindAllNodes() nodemap := make(map[string]int) diff --git a/internal/app/wwctl/overlay/chmod/main.go b/internal/app/wwctl/overlay/chmod/main.go index 1891e808..0621a10c 100644 --- a/internal/app/wwctl/overlay/chmod/main.go +++ b/internal/app/wwctl/overlay/chmod/main.go @@ -13,7 +13,6 @@ import ( ) func CobraRunE(cmd *cobra.Command, args []string) error { - config := config.New() var overlaySourceDir string overlayName := args[0] fileName := args[2] diff --git a/internal/app/wwctl/overlay/delete/main.go b/internal/app/wwctl/overlay/delete/main.go index faa334b6..606f910a 100644 --- a/internal/app/wwctl/overlay/delete/main.go +++ b/internal/app/wwctl/overlay/delete/main.go @@ -14,7 +14,6 @@ import ( func CobraRunE(cmd *cobra.Command, args []string) error { var overlayPath string - config := config.New() if SystemOverlay == true { overlayPath = config.SystemOverlaySource(args[0]) diff --git a/internal/app/wwctl/overlay/edit/main.go b/internal/app/wwctl/overlay/edit/main.go index b303e86a..7f308a83 100644 --- a/internal/app/wwctl/overlay/edit/main.go +++ b/internal/app/wwctl/overlay/edit/main.go @@ -14,8 +14,7 @@ import ( ) func CobraRunE(cmd *cobra.Command, args []string) error { - config := config.New() - editor := config.Editor + editor := os.Getenv("EDITOR") var overlaySourceDir string if SystemOverlay == true { diff --git a/internal/app/wwctl/overlay/imprt/main.go b/internal/app/wwctl/overlay/imprt/main.go index 45079cbc..08d67af4 100644 --- a/internal/app/wwctl/overlay/imprt/main.go +++ b/internal/app/wwctl/overlay/imprt/main.go @@ -12,7 +12,6 @@ import ( ) func CobraRunE(cmd *cobra.Command, args []string) error { - config := config.New() overlayName := args[0] source := args[1] var dest string diff --git a/internal/app/wwctl/overlay/list/main.go b/internal/app/wwctl/overlay/list/main.go index c5a7bfdc..918df167 100644 --- a/internal/app/wwctl/overlay/list/main.go +++ b/internal/app/wwctl/overlay/list/main.go @@ -13,7 +13,6 @@ import ( ) func CobraRunE(cmd *cobra.Command, args []string) error { - config := config.New() set := make(map[string]int) var o []string var err error @@ -54,11 +53,11 @@ func CobraRunE(cmd *cobra.Command, args []string) error { for _, node := range nodeList { if SystemOverlay == true { if node.SystemOverlay.Get() != "" { - set[node.SystemOverlay.Get()] ++ + set[node.SystemOverlay.Get()]++ } } else { if node.RuntimeOverlay.Get() != "" { - set[node.RuntimeOverlay.Get()] ++ + set[node.RuntimeOverlay.Get()]++ } } } diff --git a/internal/app/wwctl/overlay/mkdir/main.go b/internal/app/wwctl/overlay/mkdir/main.go index 0b9c5f0f..fee39fd4 100644 --- a/internal/app/wwctl/overlay/mkdir/main.go +++ b/internal/app/wwctl/overlay/mkdir/main.go @@ -13,7 +13,6 @@ import ( ) func CobraRunE(cmd *cobra.Command, args []string) error { - config := config.New() var overlaySourceDir string // mode := uint32(strconv.ParseUint(PermMode, 8, 32)) diff --git a/internal/app/wwctl/overlay/show/main.go b/internal/app/wwctl/overlay/show/main.go index d75485e1..5d08b3bd 100644 --- a/internal/app/wwctl/overlay/show/main.go +++ b/internal/app/wwctl/overlay/show/main.go @@ -12,7 +12,6 @@ import ( ) func CobraRunE(cmd *cobra.Command, args []string) error { - config := config.New() var overlaySourceDir string overlayName := args[0] fileName := args[1] @@ -44,4 +43,4 @@ func CobraRunE(cmd *cobra.Command, args []string) error { fmt.Print(string(f)) return nil -} \ No newline at end of file +} diff --git a/internal/app/wwctl/ready/main.go b/internal/app/wwctl/ready/main.go index b58d0ef2..af7e7ef0 100644 --- a/internal/app/wwctl/ready/main.go +++ b/internal/app/wwctl/ready/main.go @@ -12,7 +12,6 @@ import ( ) func CobraRunE(cmd *cobra.Command, args []string) error { - config := config.New() n, err := node.New() if err != nil { diff --git a/internal/app/wwctl/root.go b/internal/app/wwctl/root.go index 5228430d..03efec60 100644 --- a/internal/app/wwctl/root.go +++ b/internal/app/wwctl/root.go @@ -6,6 +6,7 @@ import ( "github.com/hpcng/warewulf/internal/app/wwctl/overlay" "github.com/hpcng/warewulf/internal/app/wwctl/profile" "github.com/hpcng/warewulf/internal/app/wwctl/ready" + "github.com/hpcng/warewulf/internal/app/wwctl/service" "github.com/hpcng/warewulf/internal/app/wwctl/vnfs" "github.com/hpcng/warewulf/internal/pkg/wwlog" @@ -36,7 +37,7 @@ func init() { rootCmd.AddCommand(kernel.GetCommand()) // rootCmd.AddCommand(group.GetCommand()) rootCmd.AddCommand(profile.GetCommand()) - //rootCmd.AddCommand(service.GetCommand()) + rootCmd.AddCommand(service.GetCommand()) rootCmd.AddCommand(ready.GetCommand()) } diff --git a/internal/app/wwctl/service/dhcp/main.go b/internal/app/wwctl/service/dhcp/main.go index d6707a34..74c6aab4 100644 --- a/internal/app/wwctl/service/dhcp/main.go +++ b/internal/app/wwctl/service/dhcp/main.go @@ -5,6 +5,7 @@ import ( "github.com/brotherpowers/ipsubnet" "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/util" + "github.com/hpcng/warewulf/internal/pkg/warewulfconf" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/spf13/cobra" "net" @@ -28,133 +29,120 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } func ConfigureDHCP() error { + var d dhcpTemplate + var templateFile string + nodeDB, err := node.New() if err != nil { wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err) os.Exit(1) } - controllers, err := nodeDB.FindAllControllers() + controller, err := warewulfconf.New() + if err != nil { + wwlog.Printf(wwlog.ERROR, "%s\n", err) + os.Exit(1) + } + + if controller.Ipaddr == "" { + wwlog.Printf(wwlog.ERROR, "The Warewulf IP Address is not properly configured\n") + os.Exit(1) + } + + if controller.Netmask == "" { + wwlog.Printf(wwlog.ERROR, "The Warewulf Netmask is not properly configured\n") + os.Exit(1) + } + + if controller.Dhcp.Enabled == false { + wwlog.Printf(wwlog.INFO, "This system is not configured as a Warewulf DHCP controller\n") + os.Exit(1) + } + + if controller.Dhcp.RangeStart == "" { + wwlog.Printf(wwlog.ERROR, "Configuration is not defined: `dhcpd range start`\n") + os.Exit(1) + } + + if controller.Dhcp.RangeEnd == "" { + wwlog.Printf(wwlog.ERROR, "Configuration is not defined: `dhcpd range end`\n") + os.Exit(1) + } + + if controller.Dhcp.ConfigFile == "" { + controller.Dhcp.ConfigFile = "/etc/dhcp/dhcpd.conf" + } + + nodes, err := nodeDB.FindAllNodes() if err != nil { wwlog.Printf(wwlog.ERROR, "Could not find all controllers: %s\n", err) os.Exit(1) } - for _, controller := range controllers { - var templateFile string - var d dhcpTemplate - var configured bool + for _, node := range nodes { + d.Nodes = append(d.Nodes, node) + } - addrs, err := net.InterfaceAddrs() - if err != nil { - wwlog.Printf(wwlog.ERROR, "Could not get network interfaces: %s\n", err) - os.Exit(1) - } - - for _, address := range addrs { - if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { - if ipnet.IP.String() == controller.Ipaddr { - m, _ := ipnet.Mask.Size() - sub := ipsubnet.SubnetCalculator(ipnet.IP.String(), m) - - d.Ipaddr = ipnet.IP.String() - d.Network = sub.GetNetworkPortion() - d.Netmask = sub.GetSubnetMask() - d.RangeStart = controller.Services.Dhcp.RangeStart - d.RangeEnd = controller.Services.Dhcp.RangeEnd - configured = true - break - } - } - } - - hostname, err := os.Hostname() - if err != nil { - wwlog.Printf(wwlog.ERROR, "Could not obtain system's hostname\n") - os.Exit(1) - } - if hostname != controller.Fqdn { - wwlog.Printf(wwlog.WARN, "The system hostname does not match Warewulf config: %s != %s\n", hostname, controller.Fqdn) - } - - if configured == false { - wwlog.Printf(wwlog.ERROR, "Could not identify this system in the Warewulf configuration by it's IP address\n") - os.Exit(1) - } - - if controller.Services.Dhcp.ConfigFile == "" { - wwlog.Printf(wwlog.ERROR, "Could not locate the DHCP configuration file for this controller\n") - os.Exit(1) - } - - if _, ok := nodeDB.Controllers[controller.Id]; !ok { - wwlog.Printf(wwlog.ERROR, "We should never get here, but since we did, Hello! %s\n", err) - os.Exit(1) - } - - nodes, err := nodeDB.FindAllNodes() - if err != nil { - wwlog.Printf(wwlog.ERROR, "Could not find all controllers: %s\n", err) - os.Exit(1) - } - - for _, node := range nodes { - d.Nodes = append(d.Nodes, node) - } - - if controller.Services.Dhcp.Template == "" { - templateFile = "/etc/warewulf/dhcp/default-dhcpd.conf" + if controller.Dhcp.Template == "" { + templateFile = "/etc/warewulf/dhcp/default-dhcpd.conf" + } else { + if strings.HasPrefix(controller.Dhcp.Template, "/") { + templateFile = controller.Dhcp.Template } else { - if strings.HasPrefix(controller.Services.Dhcp.Template, "/") { - templateFile = controller.Services.Dhcp.Template - } else { - templateFile = fmt.Sprintf("/etc/warewulf/dhcp/%s-dhcpd.conf", controller.Services.Dhcp.Template) - } + templateFile = fmt.Sprintf("/etc/warewulf/dhcp/%s-dhcpd.conf", controller.Dhcp.Template) } + } - tmpl, err := template.New(path.Base(templateFile)).ParseFiles(templateFile) + tmpl, err := template.New(path.Base(templateFile)).ParseFiles(templateFile) + if err != nil { + wwlog.Printf(wwlog.ERROR, "%s\n", err) + os.Exit(1) + } + + mask := net.IPMask(net.ParseIP(controller.Netmask).To4()) + size, _ := mask.Size() + + sub := ipsubnet.SubnetCalculator(controller.Ipaddr, size) + + d.Ipaddr = controller.Ipaddr + d.Network = sub.GetNetworkPortion() + d.Netmask = sub.GetSubnetMask() + d.RangeStart = controller.Dhcp.RangeStart + d.RangeEnd = controller.Dhcp.RangeEnd + + if DoConfig == true { + fmt.Printf("Writing the DHCP configuration file\n") + configWriter, err := os.OpenFile(controller.Dhcp.ConfigFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0640) + if err != nil { + wwlog.Printf(wwlog.ERROR, "%s\n", err) + os.Exit(1) + } + defer configWriter.Close() + err = tmpl.Execute(configWriter, d) if err != nil { wwlog.Printf(wwlog.ERROR, "%s\n", err) os.Exit(1) } - if DoConfig == true { - fmt.Printf("Writing the DHCP configuration file\n") - configWriter, err := os.OpenFile(controller.Services.Dhcp.ConfigFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0640) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - os.Exit(1) - } - defer configWriter.Close() - err = tmpl.Execute(configWriter, d) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - os.Exit(1) - } - - fmt.Printf("Enabling and restarting the DHCP services\n") - if controller.Services.Dhcp.EnableCmd != "" { - util.ExecInteractive("/bin/sh", "-c", controller.Services.Dhcp.EnableCmd) - } else { - util.ExecInteractive("/bin/sh", "-c", "systemctl enable dhcpd") - } - if controller.Services.Dhcp.RestartCmd != "" { - util.ExecInteractive("/bin/sh", "-c", controller.Services.Dhcp.RestartCmd) - } else { - util.ExecInteractive("/bin/sh", "-c", "systemctl restart dhcpd") - } - + fmt.Printf("Enabling and restarting the DHCP services\n") + if controller.Dhcp.Enable != "" { + util.ExecInteractive("/bin/sh", "-c", controller.Dhcp.Enable) } else { - err = tmpl.Execute(os.Stdout, d) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - os.Exit(1) - } - + util.ExecInteractive("/bin/sh", "-c", "systemctl enable dhcpd") + } + if controller.Dhcp.Restart != "" { + util.ExecInteractive("/bin/sh", "-c", controller.Dhcp.Restart) + } else { + util.ExecInteractive("/bin/sh", "-c", "systemctl restart dhcpd") + } + + } else { + err = tmpl.Execute(os.Stdout, d) + if err != nil { + wwlog.Printf(wwlog.ERROR, "%s\n", err) + os.Exit(1) } - // Just in case we get here, we've now finished the loop - break } return nil diff --git a/internal/app/wwctl/vnfs/build/main.go b/internal/app/wwctl/vnfs/build/main.go index 4b48fc09..5952aba4 100644 --- a/internal/app/wwctl/vnfs/build/main.go +++ b/internal/app/wwctl/vnfs/build/main.go @@ -29,7 +29,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { for _, node := range nodes { if node.Vnfs.Defined() == true { - set[node.Vnfs.Get()] ++ + set[node.Vnfs.Get()]++ } } @@ -43,12 +43,13 @@ func CobraRunE(cmd *cobra.Command, args []string) error { for _, node := range nodes { if node.Vnfs.Defined() == true { - set[node.Vnfs.Get()] ++ + wwlog.Printf(wwlog.VERBOSE, "Adding VNFS to list: %s (%s)\n", node.Vnfs.Get(), node.Id.Get()) + set[node.Vnfs.Get()]++ } } } else if len(args) == 1 { - set[args[0]] ++ + set[args[0]]++ } else { cmd.Usage() os.Exit(1) @@ -64,4 +65,4 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } return nil -} \ No newline at end of file +} diff --git a/internal/app/wwctl/vnfs/list/main.go b/internal/app/wwctl/vnfs/list/main.go index 85bf6296..212fcbdf 100644 --- a/internal/app/wwctl/vnfs/list/main.go +++ b/internal/app/wwctl/vnfs/list/main.go @@ -14,13 +14,12 @@ import ( ) func CobraRunE(cmd *cobra.Command, args []string) error { - config := config.New() nconfig, _ := node.New() nodes, _ := nconfig.FindAllNodes() nodemap := make(map[string]int) for _, n := range nodes { - nodemap[n.Vnfs.Get()] ++ + nodemap[n.Vnfs.Get()]++ } images, _ := ioutil.ReadDir(config.VnfsImageParentDir()) @@ -32,7 +31,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { v, err := vnfs.Load(file.Name()) if err == nil { var vnfs_size int64 - if util.IsFile( config.VnfsImage(file.Name())) { + if util.IsFile(config.VnfsImage(file.Name())) { s, _ := os.Stat(config.VnfsImage(file.Name())) vnfs_size = s.Size() / 1024 } @@ -48,7 +47,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { if util.IsDir(path.Join(config.VnfsImageParentDir(), file.Name())) { var vnfs_size int64 - if util.IsFile( config.VnfsImage(file.Name())) { + if util.IsFile(config.VnfsImage(file.Name())) { s, _ := os.Stat(config.VnfsImage(file.Name())) vnfs_size = s.Size() / 1024 } @@ -61,4 +60,4 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } } return nil -} \ No newline at end of file +}