Templated iPxe config properly and added "Kernel Args" node config

This commit is contained in:
Gregory Kurtzer
2020-11-11 23:32:27 -08:00
parent 9c1b28932e
commit 663d3bb653
4 changed files with 48 additions and 27 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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 {

View File

@@ -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"