feat(baremetal-agent): support using tftp to download kernel and initrd (#19064)

This commit is contained in:
Zexi Li
2023-12-21 00:50:48 +08:00
committed by GitHub
parent 4bfe55428f
commit 5a02dfc7c0
7 changed files with 31 additions and 23 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
FROM registry.cn-beijing.aliyuncs.com/yunionio/baremetal-base:v0.3.9-20230812.0
FROM registry.cn-beijing.aliyuncs.com/yunionio/baremetal-base:v0.3.9-20231219.0
MAINTAINER "Zexi Li <lizexi@yunionyun.com>"
+1 -1
View File
@@ -1,7 +1,7 @@
#FROM --platform=linux/amd64 registry.cn-beijing.aliyuncs.com/yunionio/centos-build:1.1-4 as build
#RUN yum install -y https://iso.yunion.cn/vm-images/baremetal-pxerom-1.1.0-21092209.x86_64.rpm
#RUN yum install -y http://192.168.23.50:8083/baremetal-pxerom-1.1.0-21092209.x86_64.rpm
FROM registry.cn-beijing.aliyuncs.com/yunionio/yunionos:v0.1.8-20230812.0 as yunionos
FROM registry.cn-beijing.aliyuncs.com/yunionio/yunionos:v3.10.8-20231215.0 as yunionos
FROM centos:8 as grub-stage
+1 -1
View File
@@ -30,7 +30,7 @@ WEBCONSOLE_BASE_VERSION = 20230731.2
webconsole-base:
$(DOCKER_BUILDX)/webconsole-base:$(WEBCONSOLE_BASE_VERSION) -f ./Dockerfile.webconsole-base .
BAREMETAL_BASE_VERSION = v0.3.9-20230812.0
BAREMETAL_BASE_VERSION = v0.3.9-20231219.1
baremetal-base:
$(DOCKER_BUILDX)/baremetal-base:$(BAREMETAL_BASE_VERSION) -f ./Dockerfile.baremetal-base .
+1
View File
@@ -211,6 +211,7 @@ var (
"force_dhcp_probe_ipmi",
"tftp_block_size_in_bytes",
"tftp_max_timeout_retries",
"enable_grub_tftp_download",
"lengthy_worker_count",
"short_worker_count",
// "default_ipmi_password",
+9 -9
View File
@@ -1061,7 +1061,7 @@ func (b *SBaremetalInstance) GetNotifyUrl() string {
return fmt.Sprintf("%s/baremetals/%s/notify", b.manager.Agent.GetListenUri(), b.GetId())
}
func (b *SBaremetalInstance) getTftpEndpoint() (string, error) {
func (b *SBaremetalInstance) getHTTPEndpoint() (string, error) {
serverIP, err := b.manager.Agent.GetDHCPServerIP()
if err != nil {
return "", errors.Wrap(err, "GetDHCPServerIP")
@@ -1069,8 +1069,8 @@ func (b *SBaremetalInstance) getTftpEndpoint() (string, error) {
return fmt.Sprintf("%s:%d", serverIP, o.Options.Port+1000), nil
}
func (b *SBaremetalInstance) getTftpFileUrl(filename string) string {
endpoint, err := b.getTftpEndpoint()
func (b *SBaremetalInstance) getHTTPFileUrl(filename string) string {
endpoint, err := b.getHTTPEndpoint()
if err != nil {
log.Errorf("Get http file server endpoint: %v", err)
return filename
@@ -1123,7 +1123,7 @@ func (b *SBaremetalInstance) getIsolinuxConf() string {
func (b *SBaremetalInstance) getSyslinuxPath(filename string, isTftp bool) string {
if isTftp {
return b.getTftpFileUrl(filename)
return b.getHTTPFileUrl(filename)
} else {
return filename
}
@@ -1203,12 +1203,12 @@ func (b *SBaremetalInstance) getGrubPXEConf(isTftp bool) string {
kernelArgs = fmt.Sprintf("root=/dev/nfs nfsroot=%s rw", o.Options.NfsBootRootfs)
}
var resp string
endpoint, err := b.getTftpEndpoint()
endpoint, err := b.getHTTPEndpoint()
if err != nil {
log.Fatalf("getTftpEndpoint %s", err)
log.Fatalf("getHTTPEndpoint %s", err)
}
if b.NeedPXEBoot() {
resp = grub.GetYunionOSConfig(3, endpoint, kernel, kernelArgs, initrd)
resp = grub.GetYunionOSConfig(3, endpoint, kernel, kernelArgs, initrd, o.Options.EnableGrubTftpDownload)
} else {
resp = grub.GetAutoFindConfig()
b.ClearSSHConfig()
@@ -1229,8 +1229,8 @@ LABEL start
kernel := "vmlinuz"
initramfs := "initrd.img"
if isTftp {
kernel = b.getTftpFileUrl("kernel")
initramfs = b.getTftpFileUrl("initramfs")
kernel = b.getHTTPFileUrl("kernel")
initramfs = b.getHTTPFileUrl("initramfs")
}
resp += fmt.Sprintf(" kernel %s\n", kernel)
args := []string{
+4 -3
View File
@@ -52,9 +52,10 @@ type BaremetalOptions struct {
LogFetchIntervalSeconds int `help:"interval to fetch baremetal log, default is 900 seconds" default:"900"`
SendMetricsIntervalSeconds int `help:"interval to send baremetal metrics, default is 300 seconds" default:"300"`
TftpFileMap map[string]string `help:"map of filename to real file path for tftp"`
BootLoader string `help:"PXE boot loader" default:"grub"`
UseMegaRaidPerccli bool `help:"Use MegaRAID perccli" default:"false"`
TftpFileMap map[string]string `help:"map of filename to real file path for tftp"`
BootLoader string `help:"PXE boot loader" default:"grub"`
EnableGrubTftpDownload bool `help:"Enable grub using tftp to download kernel and initrd"`
UseMegaRaidPerccli bool `help:"Use MegaRAID perccli" default:"false"`
NfsBootRootfs string `help:"nfs root fs URL"`
+14 -8
View File
@@ -14,16 +14,22 @@
package grub
import "fmt"
import (
"fmt"
"strings"
)
func GetYunionOSConfig(sleepTime int, httpSite, kernel string, kernelArgs string, initrd string) string {
kernel = fmt.Sprintf("(http,${http_site})/tftp/%s", kernel)
// kernel = fmt.Sprintf("(tftp,10.127.100.2)/%s", kernel)
initrd = fmt.Sprintf("(http,${http_site})/tftp/%s", initrd)
// initrd = fmt.Sprintf("(tftp,10.127.100.2)/%s", initrd)
func GetYunionOSConfig(sleepTime int, httpSite, kernel string, kernelArgs string, initrd string, useTftpDownload bool) string {
if useTftpDownload {
site := strings.Split(httpSite, ":")[0]
kernel = fmt.Sprintf("(tftp,%s)/%s", site, kernel)
initrd = fmt.Sprintf("(tftp,%s)/%s", site, initrd)
} else {
kernel = fmt.Sprintf("(http,%s)/tftp/%s", httpSite, kernel)
initrd = fmt.Sprintf("(http,%s)/tftp/%s", httpSite, initrd)
}
return fmt.Sprintf(`
set timeout=%d
set http_site=%s
menuentry 'YunionOS for PXE' --class os {
echo "Loading linux %s ..."
linux %s %s
@@ -31,7 +37,7 @@ menuentry 'YunionOS for PXE' --class os {
echo "Loading initrd %s ..."
initrd %s
}
`, sleepTime, httpSite, kernel, kernel, kernelArgs, initrd, initrd)
`, sleepTime, kernel, kernel, kernelArgs, initrd, initrd)
}
// REF: https://github.com/bluebanquise/infrastructure/blob/master/packages/ipxe-bluebanquise/grub2-efi-autofind.cfg