From 663d3bb653ef07a9da595c4c9d9195e7e42ba184 Mon Sep 17 00:00:00 2001 From: Gregory Kurtzer Date: Wed, 11 Nov 2020 23:32:27 -0800 Subject: [PATCH] Templated iPxe config properly and added "Kernel Args" node config --- etc/ipxe/default.ipxe | 14 ++--- etc/nodes.conf | 2 + .../app/warewulfd/warewulfd-reponses/ipxe.go | 52 ++++++++++++------- internal/pkg/assets/assets.go | 7 +++ 4 files changed, 48 insertions(+), 27 deletions(-) diff --git a/etc/ipxe/default.ipxe b/etc/ipxe/default.ipxe index 8f69ab18..e2aac7a9 100644 --- a/etc/ipxe/default.ipxe +++ b/etc/ipxe/default.ipxe @@ -2,14 +2,14 @@ echo echo ================================================================================ -echo Warewulf v4 now booting: @FQDN@ +echo Warewulf v4 now booting: {{.Fqdn}} echo echo -set base http://@IPADDR@:@PORT@/ +set base http://{{.Ipaddr}}:{{.Port}}/ -kernel ${base}/kernel/@HWADDR@ crashkernel=no quiet || reboot -initrd ${base}/vnfs/@HWADDR@ || reboot -initrd ${base}/kmods/@HWADDR@ || reboot -initrd ${base}/overlay-system/@HWADDR@ || reboot -boot || reboot +kernel ${base}/kernel/{{.Hwaddr}} {{.Kernelargs}} || reboot +initrd ${base}/vnfs/{{.Hwaddr}} || reboot +initrd ${base}/kmods/{{.Hwaddr}} || reboot +initrd ${base}/overlay-system/{{.Hwaddr}} || reboot +boot || reboot diff --git a/etc/nodes.conf b/etc/nodes.conf index 8ca76f27..cba94e39 100644 --- a/etc/nodes.conf +++ b/etc/nodes.conf @@ -9,6 +9,7 @@ nodegroups: n0000: hostname: localtest kernel version: 3.10.0-1127.el7.x86_64 + kernel args: crashkernel=no quiet system overlay: test netdevs: eth0: @@ -23,6 +24,7 @@ nodegroups: runtime overlay: default domain suffix: group2 kernel version: 3.10.0-1127.el7.x86_64 + kernel args: crashkernel=no quiet nodes: n0000: hostname: n0000 diff --git a/internal/app/warewulfd/warewulfd-reponses/ipxe.go b/internal/app/warewulfd/warewulfd-reponses/ipxe.go index 0cb2b262..6a4b44a5 100644 --- a/internal/app/warewulfd/warewulfd-reponses/ipxe.go +++ b/internal/app/warewulfd/warewulfd-reponses/ipxe.go @@ -1,17 +1,28 @@ package warewulfd_responses import ( - "bufio" "fmt" "github.com/hpcng/warewulf/internal/pkg/assets" "github.com/hpcng/warewulf/internal/pkg/config" + "github.com/hpcng/warewulf/internal/pkg/wwlog" "log" "net/http" - "os" "strconv" "strings" + "text/template" ) +type iPxeTemplate struct { + 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, "/") @@ -29,34 +40,35 @@ func IpxeSend(w http.ResponseWriter, req *http.Request) { } if node.HostName != "" { - log.Printf("IPXE: %15s: %s\n", node.Fqdn, req.URL.Path) - conf := config.New() + log.Printf("IPXE: %15s: %s\n", node.Fqdn, req.URL.Path) + + // TODO: Fix template path to use config package ipxeTemplate := fmt.Sprintf("/etc/warewulf/ipxe/%s.ipxe", node.Ipxe) - sourceFD, err := os.Open(ipxeTemplate) + + tmpl, err := template.ParseFiles(ipxeTemplate) if err != nil { - log.Printf("ERROR: Could not open iPXE Template: %s\n", err) - w.WriteHeader(404) + wwlog.Printf(wwlog.ERROR, "%s\n", err) return } - scanner := bufio.NewScanner(sourceFD) + var replace iPxeTemplate - for scanner.Scan() { - newLine := scanner.Text() + replace.Fqdn = node.Fqdn + replace.Ipaddr = conf.Ipaddr + replace.Port = strconv.Itoa(conf.Port) + replace.Hostname = node.HostName + replace.Hwaddr = url[2] + replace.Vnfs = node.Vnfs + replace.Kernelargs = node.KernelArgs - // TODO: Update this to use templates instead of replaces - newLine = strings.ReplaceAll(newLine, "@HWADDR@", url[2]) - newLine = strings.ReplaceAll(newLine, "@IPADDR@", conf.Ipaddr) - newLine = strings.ReplaceAll(newLine, "@HOSTNAME@", node.HostName) - newLine = strings.ReplaceAll(newLine, "@FQDN@", node.Fqdn) - newLine = strings.ReplaceAll(newLine, "@PORT@", strconv.Itoa(conf.Port)) - // TODO: Add KernelArgs to nodes.conf - //newLine = strings.ReplaceAll(newLine, "@KERNELARGS@", node.KernelArgs) - - fmt.Fprintln(w, newLine) + err = tmpl.Execute(w, replace) + if err != nil { + wwlog.Printf(wwlog.ERROR, "%s\n", err) + return } + log.Printf("SEND: %15s: %s\n", node.Fqdn, ipxeTemplate) } else { diff --git a/internal/pkg/assets/assets.go b/internal/pkg/assets/assets.go index 66ece834..7aad5b42 100644 --- a/internal/pkg/assets/assets.go +++ b/internal/pkg/assets/assets.go @@ -34,6 +34,7 @@ type nodeGroup struct { RuntimeOverlay string `yaml:"runtime system-overlay""` DomainSuffix string `yaml:"domain suffix"` KernelVersion string `yaml:"kernel version"` + KernelArgs string `yaml:"kernel args"` Nodes map[string]nodeEntry } @@ -45,6 +46,7 @@ type nodeEntry struct { RuntimeOverlay string `yaml:"runtime system-overlay"` DomainSuffix string `yaml:"domain suffix"` KernelVersion string `yaml:"kernel version"` + KernelArgs string `yaml:"kernel args"` IpmiIpaddr string `yaml:"ipmi ipaddr"` NetDevs map[string]netDevs } @@ -68,6 +70,7 @@ type NodeInfo struct { SystemOverlay string RuntimeOverlay string KernelVersion string + KernelArgs string NetDevs map[string]netDevs } @@ -99,6 +102,7 @@ func FindAllNodes() ([]NodeInfo, error) { n.SystemOverlay = group.SystemOverlay n.RuntimeOverlay = group.RuntimeOverlay n.KernelVersion = group.KernelVersion + n.KernelArgs = group.KernelArgs n.DomainName = group.DomainSuffix n.Ipxe = group.Ipxe n.NetDevs = node.NetDevs @@ -121,6 +125,9 @@ func FindAllNodes() ([]NodeInfo, error) { if node.Ipxe != "" { n.Ipxe = node.Ipxe } + if node.KernelArgs != "" { + n.KernelArgs = node.KernelArgs + } if n.RuntimeOverlay == "" { n.RuntimeOverlay = "default"