From b068c187aff651b066bb9cafa6e7e7b3832200b4 Mon Sep 17 00:00:00 2001 From: Gregory Kurtzer Date: Mon, 24 Jan 2022 01:29:05 +0000 Subject: [PATCH] Update wwclient to send hwaddr and asset/uuid tags --- cmd/wwclient/wwclient.go | 26 ++++++++++++++++++++++---- etc/ipxe/arm_image.ipxe | 2 +- etc/ipxe/default.ipxe | 2 +- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/cmd/wwclient/wwclient.go b/cmd/wwclient/wwclient.go index 85999468..c0f7cf3b 100644 --- a/cmd/wwclient/wwclient.go +++ b/cmd/wwclient/wwclient.go @@ -7,6 +7,7 @@ import ( "net/http" "os" "os/exec" + "strings" "time" "github.com/hpcng/warewulf/internal/pkg/warewulfconf" @@ -49,8 +50,7 @@ func main() { if conf.Warewulf.Secure { // Setup local port to something privileged (<1024) localTCPAddr.Port = 987 - } else { - fmt.Printf("INFO: Running from an insecure port\n") + wwlog.Printf(wwlog.INFO, "Running from trusted port\n") } webclient := &http.Client{ @@ -68,12 +68,30 @@ func main() { }, } - smbiosDump, _ := smbios.New() + smbiosDump, err := smbios.New() + if err != nil { + wwlog.Printf(wwlog.ERROR, "Could not get SMBIOS info: %s\n", err) + os.Exit(1) + } sysinfoDump := smbiosDump.SystemInformation() localUUID, _ := sysinfoDump.UUID() x := smbiosDump.SystemEnclosure() tag := x.AssetTagNumber() + cmdline, err := os.ReadFile("/proc/cmdline") + if err != nil { + wwlog.Printf(wwlog.ERROR, "Could not read from /proc/cmdline: %s\n", err) + os.Exit(1) + } + + wwid_tmp := strings.Split(string(cmdline), "wwid=") + if len(wwid_tmp) < 2 { + wwlog.Printf(wwlog.ERROR, "'wwid' is not defined in /proc/cmdline\n") + os.Exit(1) + } + + wwid := strings.Split(wwid_tmp[1], " ")[0] + for { var resp *http.Response counter := 0 @@ -81,7 +99,7 @@ func main() { for { var err error - getString := fmt.Sprintf("http://%s:%d/overlay-runtime?assetkey=%s&uuid=%s", conf.Ipaddr, conf.Warewulf.Port, tag, localUUID) + getString := fmt.Sprintf("http://%s:%d/overlay-runtime/%s?assetkey=%s&uuid=%s", conf.Ipaddr, conf.Warewulf.Port, wwid, tag, localUUID) resp, err = webclient.Get(getString) if err == nil { break diff --git a/etc/ipxe/arm_image.ipxe b/etc/ipxe/arm_image.ipxe index ee5da3cc..5014dec5 100644 --- a/etc/ipxe/arm_image.ipxe +++ b/etc/ipxe/arm_image.ipxe @@ -17,7 +17,7 @@ initrd --name kmods ${base}/kmods/{{.Hwaddr}}?assetkey=${asset}&uuid=${uuid} initrd --name system ${base}/overlay-system/{{.Hwaddr}}?assetkey=${asset}&uuid=${uuid} || goto reboot initrd --name runtime ${base}/overlay-runtime/{{.Hwaddr}}?assetkey=${asset}&uuid=${uuid} || goto reboot -boot kernel initrd=container initrd=kmods initrd=system initrd=runtime {{.KernelArgs}} || goto reboot +boot kernel initrd=container initrd=kmods initrd=system initrd=runtime wwid={{.Hwaddr}} {{.KernelArgs}} || goto reboot :reboot echo diff --git a/etc/ipxe/default.ipxe b/etc/ipxe/default.ipxe index c5123134..4512d637 100644 --- a/etc/ipxe/default.ipxe +++ b/etc/ipxe/default.ipxe @@ -17,7 +17,7 @@ imgextract --name kmods ${base}/kmods/{{.Hwaddr}}?assetkey=${asset}&uuid=${uuid} imgextract --name system ${base}/overlay-system/{{.Hwaddr}}?assetkey=${asset}&uuid=${uuid} || goto reboot imgextract --name runtime ${base}/overlay-runtime/{{.Hwaddr}}?assetkey=${asset}&uuid=${uuid} || goto reboot -boot kernel initrd=container initrd=kmods initrd=system initrd=runtime {{.KernelArgs}} || goto reboot +boot kernel initrd=container initrd=kmods initrd=system initrd=runtime wwid={{.Hwaddr}} {{.KernelArgs}} || goto reboot :reboot echo