Updates around VNFS restructure and kernel restructure. More coming.

This commit is contained in:
Gregory Kurtzer
2020-12-05 16:43:30 -08:00
parent 4efb27a82f
commit 0095b55624
28 changed files with 791 additions and 425 deletions

View File

@@ -6,17 +6,75 @@ import (
"github.com/hpcng/warewulf/internal/pkg/errors"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"io/ioutil"
"os"
"os/exec"
"path"
)
func ParentDir() string {
return path.Join(config.LocalStateDir, "provision/kernel")
}
func KernelImage(kernelVersion string) string {
if kernelVersion == "" {
wwlog.Printf(wwlog.ERROR, "Kernel Version is not defined\n")
return ""
}
if util.ValidString(kernelVersion, "^[a-zA-Z0-9-._]+$") == false {
wwlog.Printf(wwlog.ERROR, "Runtime overlay name contains illegal characters: %s\n", kernelVersion)
return ""
}
return path.Join(ParentDir(), kernelVersion, "vmlinuz")
}
func KmodsImage(kernelVersion string) string {
if kernelVersion == "" {
wwlog.Printf(wwlog.ERROR, "Kernel Version is not defined\n")
return ""
}
if util.ValidString(kernelVersion, "^[a-zA-Z0-9-._]+$") == false {
wwlog.Printf(wwlog.ERROR, "Runtime overlay name contains illegal characters: %s\n", kernelVersion)
return ""
}
return path.Join(ParentDir(), kernelVersion, "kmods.img")
}
func ListKernels() ([]string, error) {
var ret []string
err := os.MkdirAll(ParentDir(), 0755)
if err != nil {
return ret, errors.New("Could not create Kernel parent directory: " + ParentDir())
}
wwlog.Printf(wwlog.DEBUG, "Searching for Kernel image directories: %s\n", ParentDir())
kernels, err := ioutil.ReadDir(ParentDir())
if err != nil {
return ret, err
}
for _, kernel := range kernels {
wwlog.Printf(wwlog.VERBOSE, "Found Kernel: %s\n", kernel.Name())
ret = append(ret, kernel.Name())
}
return ret, nil
}
func Build(kernelVersion string) error {
kernelImage := "/boot/vmlinuz-" + kernelVersion
kernelDrivers := "/lib/modules/" + kernelVersion
kernelDestination := config.KernelImage(kernelVersion)
driversDestination := config.KmodsImage(kernelVersion)
kernelDestination := KernelImage(kernelVersion)
driversDestination := KmodsImage(kernelVersion)
// Create the destination paths just in case it doesn't exist
os.MkdirAll(path.Dir(kernelDestination), 0755)
@@ -30,6 +88,7 @@ func Build(kernelVersion string) error {
return errors.New("Could not locate kernel drivers: " + kernelDrivers)
}
wwlog.Printf(wwlog.VERBOSE, "Setting up Kernel\n")
if _, err := os.Stat(kernelImage); err == nil {
err := util.CopyFile(kernelImage, kernelDestination)
if err != nil {
@@ -38,6 +97,7 @@ func Build(kernelVersion string) error {
wwlog.Printf(wwlog.INFO, "%-45s: Done\n", "vmlinuz-"+kernelVersion)
}
wwlog.Printf(wwlog.VERBOSE, "Building Kernel driver image\n")
if _, err := os.Stat(kernelDrivers); err == nil {
cmd := fmt.Sprintf("cd /; find .%s | cpio --quiet -o -H newc -F \"%s\"", kernelDrivers, driversDestination)
err := exec.Command("/bin/sh", "-c", cmd).Run()