Cleanups and minor fixups
This commit is contained in:
@@ -2,6 +2,7 @@ package container
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hpcng/warewulf/internal/pkg/errors"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"os"
|
||||
@@ -9,46 +10,40 @@ import (
|
||||
"path"
|
||||
)
|
||||
|
||||
func Build(name string, buildForce bool) {
|
||||
func Build(name string, buildForce bool) (string, error) {
|
||||
|
||||
rootfsPath := RootFsDir(name)
|
||||
imagePath := ImageFile(name)
|
||||
|
||||
if ValidSource(name) == false {
|
||||
wwlog.Printf(wwlog.INFO, "%-35s: Skipping (bad path)\n", name)
|
||||
return
|
||||
return "", errors.New("Container does not exist")
|
||||
}
|
||||
|
||||
if buildForce == false {
|
||||
wwlog.Printf(wwlog.DEBUG, "Checking if there have been any updates to the VNFS directory\n")
|
||||
if util.PathIsNewer(rootfsPath, imagePath) {
|
||||
wwlog.Printf(wwlog.INFO, "%-35s: Skipping, VNFS is current\n", name)
|
||||
return
|
||||
return "Skipping (VNFS is current)", nil
|
||||
}
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.DEBUG, "Making parent directory for: %s\n", name)
|
||||
err := os.MkdirAll(path.Dir(imagePath), 0755)
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: %s\n", err)
|
||||
return
|
||||
return "Failed creating directory", err
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.DEBUG, "Making parent directory for: %s\n", rootfsPath)
|
||||
err = os.MkdirAll(path.Dir(rootfsPath), 0755)
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: %s\n", err)
|
||||
return
|
||||
return "Failed creating directory", err
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.DEBUG, "Building VNFS image: '%s' -> '%s'\n", rootfsPath, imagePath)
|
||||
cmd := fmt.Sprintf("cd %s; find . | cpio --quiet -o -H newc | gzip -c > \"%s\"", rootfsPath, imagePath)
|
||||
err = exec.Command("/bin/sh", "-c", cmd).Run()
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "Failed building VNFS: %s\n", err)
|
||||
return
|
||||
return "Failed building VNFS", err
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.INFO, "%-35s: Done\n", name)
|
||||
|
||||
return "Done", nil
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ func ListKernels() ([]string, error) {
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func Build(kernelVersion string) error {
|
||||
func Build(kernelVersion string) (string, error) {
|
||||
|
||||
kernelImage := "/boot/vmlinuz-" + kernelVersion
|
||||
kernelDrivers := "/lib/modules/" + kernelVersion
|
||||
@@ -81,20 +81,19 @@ func Build(kernelVersion string) error {
|
||||
os.MkdirAll(path.Dir(driversDestination), 0755)
|
||||
|
||||
if util.IsFile(kernelImage) == false {
|
||||
return errors.New("Could not locate kernel image: " + kernelImage)
|
||||
return "", errors.New("Could not locate kernel image")
|
||||
}
|
||||
|
||||
if util.IsDir(kernelDrivers) == false {
|
||||
return errors.New("Could not locate kernel drivers: " + kernelDrivers)
|
||||
return "", errors.New("Could not locate kernel drivers")
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.VERBOSE, "Setting up Kernel\n")
|
||||
if _, err := os.Stat(kernelImage); err == nil {
|
||||
err := util.CopyFile(kernelImage, kernelDestination)
|
||||
if err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
wwlog.Printf(wwlog.INFO, "%-45s: Done\n", "vmlinuz-"+kernelVersion)
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.VERBOSE, "Building Kernel driver image\n")
|
||||
@@ -102,10 +101,9 @@ func Build(kernelVersion string) error {
|
||||
cmd := fmt.Sprintf("cd /; find .%s | cpio --quiet -o -H newc -F \"%s\"", kernelDrivers, driversDestination)
|
||||
err := exec.Command("/bin/sh", "-c", cmd).Run()
|
||||
if err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
wwlog.Printf(wwlog.INFO, "%-45s: Done\n", "kmods-"+kernelVersion+".img")
|
||||
}
|
||||
|
||||
return nil
|
||||
return "Done", nil
|
||||
}
|
||||
|
||||
@@ -57,11 +57,11 @@ func IpxeSend(w http.ResponseWriter, req *http.Request) {
|
||||
// If we failed to find a node, let's see if we can add one...
|
||||
var netdev string
|
||||
|
||||
wwlog.Printf(wwlog.INFO, "Node was not found, looking for discoverable nodes...\n")
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node was not found, looking for discoverable nodes...\n")
|
||||
|
||||
n, netdev, err = nodeDB.FindDiscoverableNode()
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.WARN, "Node was not found, no nodes are discoverable...\n")
|
||||
wwlog.Printf(wwlog.WARN, "No nodes are set as discoverable...\n")
|
||||
unconfiguredNode = true
|
||||
|
||||
} else {
|
||||
@@ -79,7 +79,9 @@ func IpxeSend(w http.ResponseWriter, req *http.Request) {
|
||||
wwlog.Printf(wwlog.ERROR, "Could not persist new node configuration while adding node: %s\n", n.Id.Get())
|
||||
unconfiguredNode = true
|
||||
} else {
|
||||
wwlog.Printf(wwlog.INFO, "Building System Overlay:\n")
|
||||
_ = overlay.BuildSystemOverlay([]node.NodeInfo{n})
|
||||
wwlog.Printf(wwlog.INFO, "Building Runtime Overlay:\n")
|
||||
_ = overlay.BuildRuntimeOverlay([]node.NodeInfo{n})
|
||||
}
|
||||
}
|
||||
@@ -89,9 +91,7 @@ func IpxeSend(w http.ResponseWriter, req *http.Request) {
|
||||
if unconfiguredNode == true {
|
||||
log.Printf("UNCONFIGURED NODE: %15s\n", hwaddr)
|
||||
|
||||
ipxeTemplate := fmt.Sprintf("/etc/warewulf/ipxe/unconfigured.ipxe", n.Ipxe.Get())
|
||||
|
||||
tmpl, err := template.ParseFiles(ipxeTemplate)
|
||||
tmpl, err := template.ParseFiles("/etc/warewulf/ipxe/unconfigured.ipxe")
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user