Moving warewulfd code around and implementing new API for config.*()
This commit is contained in:
@@ -1,69 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"github.com/hpcng/warewulf/internal/pkg/assets"
|
||||
"github.com/hpcng/warewulf/internal/pkg/config"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func ipxeSend(w http.ResponseWriter, req *http.Request) {
|
||||
url := strings.Split(req.URL.Path, "/")
|
||||
|
||||
if url[2] == "" {
|
||||
log.Printf("ERROR: Bad iPXE request from %s\n", req.RemoteAddr)
|
||||
return
|
||||
}
|
||||
|
||||
hwaddr := strings.ReplaceAll(url[2], "-", ":")
|
||||
node, err := assets.FindByHwaddr(hwaddr)
|
||||
if err != nil {
|
||||
log.Printf("Could not find HW Addr: %s: %s\n", hwaddr, err)
|
||||
w.WriteHeader(404)
|
||||
return
|
||||
}
|
||||
|
||||
if node.HostName != "" {
|
||||
log.Printf("IPXE: %15s: %s\n", node.Fqdn, req.URL.Path)
|
||||
|
||||
conf, err := config.New()
|
||||
if err != nil {
|
||||
log.Printf("Could not get config: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
ipxeTemplate := fmt.Sprintf("/etc/warewulf/ipxe/%s.ipxe", node.Ipxe)
|
||||
sourceFD, err := os.Open(ipxeTemplate)
|
||||
if err != nil {
|
||||
log.Printf("ERROR: Could not open iPXE Template: %s\n", err)
|
||||
w.WriteHeader(404)
|
||||
return
|
||||
}
|
||||
|
||||
scanner := bufio.NewScanner(sourceFD)
|
||||
|
||||
for scanner.Scan() {
|
||||
newLine := scanner.Text()
|
||||
|
||||
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)
|
||||
}
|
||||
log.Printf("SEND: %15s: %s\n", node.Fqdn, ipxeTemplate)
|
||||
|
||||
} else {
|
||||
log.Printf("ERROR: iPXE request from unknown Node (hwaddr=%s)\n", url[2])
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hpcng/warewulf/internal/pkg/config"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func kernelSend(w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
node, err := getSanity(req)
|
||||
if err != nil {
|
||||
w.WriteHeader(404)
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
if node.KernelVersion != "" {
|
||||
fileName := fmt.Sprintf("%s/provision/kernel/vmlinuz-%s", config.LocalStateDir, node.KernelVersion)
|
||||
|
||||
err := sendFile(w, fileName, node.Fqdn)
|
||||
if err != nil {
|
||||
log.Printf("ERROR: %s\n", err)
|
||||
} else {
|
||||
log.Printf("SEND: %15s: %s\n", node.Fqdn, fileName)
|
||||
}
|
||||
|
||||
} else {
|
||||
w.WriteHeader(503)
|
||||
log.Printf("ERROR: No 'kernel version' set for node %s\n", node.Fqdn)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hpcng/warewulf/internal/pkg/config"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func kmodsSend(w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
node, err := getSanity(req)
|
||||
if err != nil {
|
||||
w.WriteHeader(404)
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
if node.KernelVersion != "" {
|
||||
fileName := fmt.Sprintf("%s/provision/kernel/kmods-%s.img", config.LocalStateDir, node.KernelVersion)
|
||||
|
||||
err := sendFile(w, fileName, node.Fqdn)
|
||||
if err != nil {
|
||||
log.Printf("ERROR: %s\n", err)
|
||||
} else {
|
||||
log.Printf("SEND: %15s: %s\n", node.Fqdn, fileName)
|
||||
}
|
||||
|
||||
} else {
|
||||
w.WriteHeader(503)
|
||||
log.Printf("ERROR: No 'kernel version' set for node %s\n", node.Fqdn)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hpcng/warewulf/internal/pkg/assets"
|
||||
"github.com/hpcng/warewulf/internal/pkg/config"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func runtimeOverlaySend(w http.ResponseWriter, req *http.Request) {
|
||||
remote := strings.Split(req.RemoteAddr, ":")
|
||||
port, err := strconv.Atoi(remote[1])
|
||||
if err != nil {
|
||||
log.Printf("Could not convert port to integer: %s\n", remote[1])
|
||||
w.WriteHeader(503)
|
||||
return
|
||||
}
|
||||
|
||||
config, err := config.New()
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: Could not load configuration file: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
if config.InsecureRuntime == false {
|
||||
if port >= 1024 {
|
||||
log.Panicf("DENIED: Connection coming from non-privledged port: %s\n", req.RemoteAddr)
|
||||
w.WriteHeader(401)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
node, err := assets.FindByIpaddr(remote[0])
|
||||
if err != nil {
|
||||
fmt.Printf("Could not find node by IP address: %s\n", remote[0])
|
||||
w.WriteHeader(404)
|
||||
return
|
||||
}
|
||||
|
||||
if node.Fqdn == "" {
|
||||
log.Printf("UNKNOWN: %15s: %s\n", remote[0], req.URL.Path)
|
||||
w.WriteHeader(404)
|
||||
return
|
||||
} else {
|
||||
log.Printf("REQ: %15s: %s\n", node.Fqdn, req.URL.Path)
|
||||
}
|
||||
|
||||
if node.RuntimeOverlay != "" {
|
||||
fileName := fmt.Sprintf("%s/provision/overlays/runtime/%s.img", config.LocalStateDir, node.Fqdn)
|
||||
|
||||
err := sendFile(w, fileName, node.Fqdn)
|
||||
if err != nil {
|
||||
log.Printf("ERROR: %s\n", err)
|
||||
} else {
|
||||
log.Printf("SEND: %15s: %s\n", node.Fqdn, fileName)
|
||||
}
|
||||
} else {
|
||||
w.WriteHeader(503)
|
||||
log.Printf("ERROR: No 'runtime system-overlay' set for node %s\n", node.Fqdn)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hpcng/warewulf/internal/pkg/config"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func systemOverlaySend(w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
node, err := getSanity(req)
|
||||
if err != nil {
|
||||
w.WriteHeader(404)
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
if node.SystemOverlay != "" {
|
||||
fileName := fmt.Sprintf("%s/provision/overlays/system/%s.img", config.LocalStateDir, node.Fqdn)
|
||||
|
||||
err := sendFile(w, fileName, node.Fqdn)
|
||||
if err != nil {
|
||||
log.Printf("ERROR: %s\n", err)
|
||||
} else {
|
||||
log.Printf("SEND: %15s: %s\n", node.Fqdn, fileName)
|
||||
}
|
||||
} else {
|
||||
w.WriteHeader(503)
|
||||
log.Printf("ERROR: No 'system system-overlay' set for node %s\n", node.Fqdn)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/vnfs"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func vnfsSend(w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
node, err := getSanity(req)
|
||||
if err != nil {
|
||||
w.WriteHeader(404)
|
||||
log.Panicln(err)
|
||||
return
|
||||
}
|
||||
|
||||
if node.Vnfs != "" {
|
||||
v := vnfs.New(node.Vnfs)
|
||||
|
||||
err := sendFile(w, v.Image(), node.Fqdn)
|
||||
if err != nil {
|
||||
log.Printf("ERROR: %s\n", err)
|
||||
} else {
|
||||
log.Printf("SEND: %15s: %s\n", node.Fqdn, v.Image())
|
||||
}
|
||||
} else {
|
||||
w.WriteHeader(503)
|
||||
log.Printf("ERROR: No VNFS set for node %s\n", node.Fqdn)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/assets"
|
||||
"github.com/hpcng/warewulf/internal/pkg/errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// TODO: https://github.com/danderson/netboot/blob/master/pixiecore/dhcp.go
|
||||
// TODO: https://github.com/pin/tftp
|
||||
|
||||
//const LocalStateDir = "/var/warewulf"
|
||||
|
||||
func getSanity(req *http.Request) (assets.NodeInfo, error) {
|
||||
url := strings.Split(req.URL.Path, "/")
|
||||
|
||||
hwaddr := strings.ReplaceAll(url[2], "-", ":")
|
||||
node, err := assets.FindByHwaddr(hwaddr)
|
||||
if err != nil {
|
||||
return node, errors.New("Could not find node by HW address")
|
||||
}
|
||||
|
||||
if node.Fqdn == "" {
|
||||
log.Printf("UNKNOWN: %15s: %s\n", hwaddr, req.URL.Path)
|
||||
return node, errors.New("Unknown node HW address: " + hwaddr)
|
||||
} else {
|
||||
log.Printf("REQ: %15s: %s\n", node.Fqdn, req.URL.Path)
|
||||
}
|
||||
|
||||
return node, nil
|
||||
}
|
||||
|
||||
func sendFile(w http.ResponseWriter, filename string, sendto string) error {
|
||||
|
||||
fd, err := os.Open(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
FileHeader := make([]byte, 512)
|
||||
fd.Read(FileHeader)
|
||||
FileContentType := http.DetectContentType(FileHeader)
|
||||
FileStat, _ := fd.Stat()
|
||||
FileSize := strconv.FormatInt(FileStat.Size(), 10)
|
||||
|
||||
w.Header().Set("Content-Disposition", "attachment; filename=kernel")
|
||||
w.Header().Set("Content-Type", FileContentType)
|
||||
w.Header().Set("Content-Length", FileSize)
|
||||
|
||||
fd.Seek(0, 0)
|
||||
io.Copy(w, fd)
|
||||
|
||||
fd.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
http.HandleFunc("/ipxe/", ipxeSend)
|
||||
http.HandleFunc("/kernel/", kernelSend)
|
||||
http.HandleFunc("/kmods/", kmodsSend)
|
||||
http.HandleFunc("/vnfs/", vnfsSend)
|
||||
http.HandleFunc("/overlay-system/", systemOverlaySend)
|
||||
http.HandleFunc("/overlay-runtime", runtimeOverlaySend)
|
||||
|
||||
http.ListenAndServe(":9873", nil)
|
||||
}
|
||||
27
internal/app/warewulfd/warewulfd.go
Normal file
27
internal/app/warewulfd/warewulfd.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package warewulfd
|
||||
|
||||
import (
|
||||
warewulfd_responses "github.com/hpcng/warewulf/internal/app/warewulfd/warewulfd-reponses"
|
||||
"github.com/spf13/cobra"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// TODO: https://github.com/danderson/netboot/blob/master/pixiecore/dhcp.go
|
||||
// TODO: https://github.com/pin/tftp
|
||||
|
||||
//const LocalStateDir = "/var/warewulf"
|
||||
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
|
||||
http.HandleFunc("/ipxe/", warewulfd_responses.IpxeSend)
|
||||
http.HandleFunc("/kernel/", warewulfd_responses.KernelSend)
|
||||
http.HandleFunc("/kmods/", warewulfd_responses.KmodsSend)
|
||||
http.HandleFunc("/vnfs/", warewulfd_responses.VnfsSend)
|
||||
http.HandleFunc("/overlay-system/", warewulfd_responses.SystemOverlaySend)
|
||||
http.HandleFunc("/overlay-runtime", warewulfd_responses.RuntimeOverlaySend)
|
||||
|
||||
http.ListenAndServe(":9873", nil)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -11,9 +11,8 @@ import (
|
||||
"path"
|
||||
)
|
||||
|
||||
const kernelProvisionPath = "/provision/kernel/"
|
||||
|
||||
func Build(nodeList []assets.NodeInfo, force bool) error {
|
||||
config := config.New()
|
||||
set := make(map[string]int)
|
||||
|
||||
wwlog.Printf(wwlog.INFO, "Importing Kernels:\n")
|
||||
@@ -29,12 +28,13 @@ func Build(nodeList []assets.NodeInfo, force bool) error {
|
||||
for kernelVersion := range set {
|
||||
kernelImage := "/boot/vmlinuz-"+kernelVersion
|
||||
kernelDrivers := "/lib/modules/"+kernelVersion
|
||||
kernelDestination := path.Join(config.LocalStateDir, kernelProvisionPath, "vmlinuz-"+kernelVersion)
|
||||
driversDestination := path.Join(config.LocalStateDir, kernelProvisionPath, "kmods-"+kernelVersion+".img")
|
||||
kernelDestination := config.KernelImage(kernelVersion)
|
||||
driversDestination := config.KmodsImage(kernelVersion)
|
||||
|
||||
// Create the destination paths just in case it doesn't exist
|
||||
os.MkdirAll(path.Dir(kernelDestination), 0755)
|
||||
os.MkdirAll(path.Dir(driversDestination), 0755)
|
||||
|
||||
// Create the kernel destination path just in case it doesn't exist
|
||||
os.MkdirAll(path.Join(config.LocalStateDir, kernelProvisionPath), 0755)
|
||||
|
||||
if _, err := os.Stat(kernelImage); err == nil {
|
||||
if util.PathIsNewer(kernelImage, kernelDestination) && force == false {
|
||||
|
||||
@@ -27,12 +27,14 @@ func fileInclude(path string) string {
|
||||
|
||||
func Build(nodeList []assets.NodeInfo, force bool) error {
|
||||
wwlog.Printf(wwlog.INFO, "Building Runtime Overlays:\n")
|
||||
config := config.New()
|
||||
|
||||
wwlog.SetIndent(4)
|
||||
|
||||
for _, node := range nodeList {
|
||||
if node.RuntimeOverlay != "" {
|
||||
OverlayDir := path.Join(config.LocalStateDir, "/overlays/runtime/", node.RuntimeOverlay)
|
||||
OverlayFile := path.Join(config.LocalStateDir, "/provision/overlays/runtime/", node.Fqdn+".img")
|
||||
OverlayDir := config.RuntimeOverlaySource(node.RuntimeOverlay)
|
||||
OverlayFile := config.RuntimeOverlayImage(node.Fqdn)
|
||||
|
||||
wwlog.Printf(wwlog.VERBOSE, "Building Runtime Overlay for: %s\n", node.Fqdn)
|
||||
|
||||
|
||||
@@ -27,12 +27,14 @@ func fileInclude(path string) string {
|
||||
|
||||
func Build(nodeList []assets.NodeInfo, force bool) error {
|
||||
wwlog.Printf(wwlog.INFO, "Building System Overlays:\n")
|
||||
config := config.New()
|
||||
|
||||
wwlog.SetIndent(4)
|
||||
|
||||
for _, node := range nodeList {
|
||||
if node.SystemOverlay != "" {
|
||||
OverlayDir := path.Join(config.LocalStateDir, "/overlays/system/", node.SystemOverlay)
|
||||
OverlayFile := path.Join(config.LocalStateDir, "/provision/overlays/system/", node.Fqdn+".img")
|
||||
OverlayDir := config.SystemOverlaySource(node.SystemOverlay)
|
||||
OverlayFile := config.SystemOverlayImage(node.Fqdn)
|
||||
|
||||
wwlog.Printf(wwlog.VERBOSE, "Building System Overlay for: %s\n", node.Fqdn)
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package vnfs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hpcng/warewulf/internal/pkg/config"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/vnfs"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
@@ -10,6 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func BuildContainerdir(v vnfs.VnfsObject) {
|
||||
config := config.New()
|
||||
|
||||
if _, err := os.Stat(v.Source()); err != nil {
|
||||
wwlog.Printf(wwlog.INFO, "%-35s: Skipping (bad path)\n", v.Name())
|
||||
@@ -17,31 +19,35 @@ func BuildContainerdir(v vnfs.VnfsObject) {
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.DEBUG, "Checking if there have been any updates to the VNFS directory\n")
|
||||
if util.PathIsNewer(v.Source(), v.Image()) {
|
||||
if util.PathIsNewer(v.Source(), config.VnfsImage(v.NameClean())) {
|
||||
if buildForce == false {
|
||||
wwlog.Printf(wwlog.INFO, "%-35s: Skipping, VNFS is current\n", v.Name())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.DEBUG, "Making the directory: %s\n", path.Dir(v.Image()))
|
||||
err := os.MkdirAll(path.Dir(v.Image()), 0755)
|
||||
wwlog.Printf(wwlog.DEBUG, "Making the directory: %s\n", path.Dir(config.VnfsImage(v.NameClean())))
|
||||
err := os.MkdirAll(path.Dir(config.VnfsImage(v.NameClean())), 0755)
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.DEBUG, "Building VNFS image: '%s' -> '%s'\n", v.Source(), v.Image())
|
||||
err = buildVnfs(v.Source(), v.Image())
|
||||
wwlog.Printf(wwlog.DEBUG, "Building VNFS image: '%s' -> '%s'\n", v.Source(), config.VnfsImage(v.NameClean()))
|
||||
err = buildVnfs(v.Source(), config.VnfsImage(v.NameClean()))
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.DEBUG, "Building links for Warewulf access to chroot\n")
|
||||
err = buildLinks(v, v.Source())
|
||||
// Setup links from OCI rootfs to chroot path
|
||||
_ = os.Remove(config.VnfsChroot(v.NameClean()) + "-link")
|
||||
err = os.Symlink(v.Source(), config.VnfsChroot(v.NameClean())+"-link")
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
err = os.Rename(config.VnfsChroot(v.NameClean())+"-link", config.VnfsChroot(v.NameClean()))
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
||||
@@ -11,13 +11,13 @@ import (
|
||||
"path"
|
||||
)
|
||||
|
||||
const (
|
||||
OciCacheDir = config.LocalStateDir + "/oci"
|
||||
VnfsHashDir = config.LocalStateDir + "/oci/vnfs/hash/"
|
||||
)
|
||||
|
||||
func BuildDocker(v vnfs.VnfsObject) {
|
||||
wwlog.Printf(wwlog.VERBOSE, "Building OCI Container: %s\n", v.Source())
|
||||
config := config.New()
|
||||
|
||||
OciCacheDir := config.LocalStateDir + "/oci"
|
||||
VnfsHashDir := config.LocalStateDir + "/oci/vnfs"
|
||||
|
||||
c, err := oci.NewCache(oci.OptSetCachePath(OciCacheDir))
|
||||
if err != nil {
|
||||
@@ -34,7 +34,7 @@ func BuildDocker(v vnfs.VnfsObject) {
|
||||
|
||||
hashDestination := VnfsHashDir + path.Base(sourcePath)
|
||||
|
||||
name, err := os.Readlink(v.Image())
|
||||
name, err := os.Readlink(config.VnfsImage(v.NameClean()))
|
||||
if err == nil {
|
||||
if name == hashDestination {
|
||||
wwlog.Printf(wwlog.INFO, "%-35s: Skipping, VNFS is current\n", v.Name())
|
||||
@@ -47,12 +47,12 @@ func BuildDocker(v vnfs.VnfsObject) {
|
||||
fmt.Printf("ERROR: %s\n", err)
|
||||
return
|
||||
}
|
||||
err = os.MkdirAll(path.Dir(v.Image()), 0755)
|
||||
err = os.MkdirAll(path.Dir(config.VnfsImage(v.NameClean())), 0755)
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: %s\n", err)
|
||||
return
|
||||
}
|
||||
err = os.MkdirAll(path.Dir(v.Root()), 0755)
|
||||
err = os.MkdirAll(path.Dir(config.VnfsChroot(v.NameClean())), 0755)
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: %s\n", err)
|
||||
return
|
||||
@@ -68,19 +68,29 @@ func BuildDocker(v vnfs.VnfsObject) {
|
||||
|
||||
wwlog.Printf(wwlog.VERBOSE, "Finalizing Build\n")
|
||||
|
||||
_ = os.Remove(v.Image() + "-link")
|
||||
err = os.Symlink(hashDestination, v.Image()+"-link")
|
||||
// Setup links from OCI image to provision path
|
||||
_ = os.Remove(config.VnfsImage(v.NameClean()) + "-link")
|
||||
err = os.Symlink(hashDestination, config.VnfsImage(v.NameClean())+"-link")
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
err = os.Rename(v.Image()+"-link", v.Image())
|
||||
err = os.Rename(config.VnfsImage(v.NameClean())+"-link", config.VnfsImage(v.NameClean()))
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err = buildLinks(v, sourcePath)
|
||||
// Setup links from OCI rootfs to chroot path
|
||||
_ = os.Remove(config.VnfsChroot(v.NameClean()) + "-link")
|
||||
err = os.Symlink(sourcePath, config.VnfsChroot(v.NameClean())+"-link")
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
err = os.Rename(config.VnfsChroot(v.NameClean())+"-link", config.VnfsChroot(v.NameClean()))
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
||||
wwlog.Printf(wwlog.INFO, "%-35s: Done\n", v.Name())
|
||||
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
package vnfs
|
||||
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hpcng/warewulf/internal/pkg/vnfs"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
)
|
||||
|
||||
func buildVnfs(source string, dest string) error {
|
||||
@@ -16,26 +12,3 @@ func buildVnfs(source string, dest string) error {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func buildLinks(v vnfs.VnfsObject, source string) error {
|
||||
|
||||
// Just incase the temporary link location is present, remove it if we can
|
||||
_ = os.Remove(v.Root() + "-link")
|
||||
|
||||
// Just incase the directory doesn't exist, make it
|
||||
_ = os.MkdirAll(path.Dir(v.Root()), 0755)
|
||||
|
||||
// Link to a temporary location so we can atomically move the link into place
|
||||
err := os.Symlink(source, v.Root()+"-link")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Atomically move the link into place
|
||||
err = os.Rename(v.Root()+"-link", v.Root())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -2,12 +2,8 @@ package assets
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hpcng/warewulf/internal/pkg/vnfs"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"gopkg.in/yaml.v2"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
// "os"
|
||||
|
||||
// "os"
|
||||
@@ -138,6 +134,7 @@ func FindAllNodes() ([]NodeInfo, error) {
|
||||
n.Fqdn = node.Hostname
|
||||
}
|
||||
|
||||
/*
|
||||
if b, _ := regexp.MatchString(`^[a-z\-]+://`, n.Vnfs); b == true {
|
||||
//if strings.HasPrefix(n.Vnfs, "docker://") {
|
||||
//TODO: This is a kludge and shouldn't be done here. We need to go back
|
||||
@@ -149,6 +146,7 @@ func FindAllNodes() ([]NodeInfo, error) {
|
||||
} else {
|
||||
wwlog.Printf(wwlog.ERROR, "Configuration 'Vnfs' is invalid for node: %s\n", n.Fqdn)
|
||||
}
|
||||
*/
|
||||
|
||||
ret = append(ret, n)
|
||||
}
|
||||
|
||||
@@ -2,15 +2,13 @@ package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/kelseyhightower/envconfig"
|
||||
"gopkg.in/yaml.v2"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
const (
|
||||
SysConfDir = "/etc/warewulf/"
|
||||
LocalStateDir = "/var/warewulf"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Port int `yaml:"warewulfd port", envconfig:"WAREWULFD_PORT"`
|
||||
@@ -21,34 +19,76 @@ type Config struct {
|
||||
LocalStateDir string `yaml:"local state dir"`
|
||||
}
|
||||
|
||||
func New() (Config, error) {
|
||||
var c Config
|
||||
var c Config
|
||||
|
||||
fd, err := ioutil.ReadFile(SysConfDir + "warewulf.conf")
|
||||
func init() {
|
||||
fd, err := ioutil.ReadFile("/etc/warewulf/warewulf.conf")
|
||||
if err != nil {
|
||||
return c, err
|
||||
wwlog.Printf(wwlog.ERROR, "Could not read config file: %s\n", err)
|
||||
os.Exit(255)
|
||||
}
|
||||
|
||||
err = yaml.Unmarshal(fd, &c)
|
||||
if err != nil {
|
||||
return c, err
|
||||
wwlog.Printf(wwlog.ERROR, "Could not unmarshal config file: %s\n", err)
|
||||
os.Exit(255)
|
||||
}
|
||||
|
||||
err = envconfig.Process("", &c)
|
||||
if err != nil {
|
||||
return c, err
|
||||
wwlog.Printf(wwlog.ERROR, "Could not obtain environment configuration: %s\n", err)
|
||||
os.Exit(255)
|
||||
}
|
||||
|
||||
if c.Ipaddr == "" {
|
||||
fmt.Printf("ERROR: 'warewulf ipaddr' has not been set in %s\n", SysConfDir+"warewulf.conf")
|
||||
fmt.Printf("ERROR: 'warewulf ipaddr' has not been set in /etc/warewulf/warewulf.conf\n")
|
||||
}
|
||||
|
||||
if c.SysConfDir == "" {
|
||||
c.SysConfDir = SysConfDir
|
||||
c.SysConfDir = "/etc/warewulf"
|
||||
}
|
||||
if c.LocalStateDir == "" {
|
||||
c.LocalStateDir = LocalStateDir
|
||||
c.LocalStateDir = "/var/warewulf"
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func New() (Config) {
|
||||
return c
|
||||
}
|
||||
|
||||
func (self *Config) NodeConfig() (string) {
|
||||
return fmt.Sprintf("%s/nodes.conf", self.LocalStateDir)
|
||||
}
|
||||
|
||||
func (self *Config) SystemOverlaySource(overlayName string) (string) {
|
||||
return fmt.Sprintf("%s/overlays/system/%s", self.LocalStateDir, overlayName)
|
||||
}
|
||||
|
||||
func (self *Config) RuntimeOverlaySource(overlayName string) (string) {
|
||||
return fmt.Sprintf("%s/overlays/runtime/%s", self.LocalStateDir, overlayName)
|
||||
}
|
||||
|
||||
func (self *Config) KernelImage(kernelVersion string) (string) {
|
||||
return fmt.Sprintf("%s/kernel/vmlinuz-%s", self.LocalStateDir, kernelVersion)
|
||||
}
|
||||
|
||||
func (self *Config) KmodsImage(kernelVersion string) (string) {
|
||||
return fmt.Sprintf("%s/kernel/kmods-%s.img", self.LocalStateDir, kernelVersion)
|
||||
}
|
||||
|
||||
func (self *Config) VnfsImage(vnfsNameClean string) (string) {
|
||||
return fmt.Sprintf("%s/vnfs/%s.img.gz", self.LocalStateDir, vnfsNameClean)
|
||||
}
|
||||
|
||||
func (self *Config) SystemOverlayImage(nodeName string) (string) {
|
||||
return fmt.Sprintf("%s/overlay/system/%s.img", self.LocalStateDir, nodeName)
|
||||
}
|
||||
|
||||
func (self *Config) RuntimeOverlayImage(nodeName string) (string) {
|
||||
return fmt.Sprintf("%s/overlay/runtime/%s.img", self.LocalStateDir, nodeName)
|
||||
}
|
||||
|
||||
func (self *Config) VnfsChroot(vnfsNameClean string) (string) {
|
||||
return fmt.Sprintf("%s/chroot/%s.img", self.LocalStateDir, vnfsNameClean)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
package vnfs
|
||||
|
||||
import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/config"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type VnfsObject struct {
|
||||
SourcePath string
|
||||
RootPath string
|
||||
ImagePath string
|
||||
}
|
||||
|
||||
func New(s string) VnfsObject {
|
||||
@@ -20,7 +17,6 @@ func New(s string) VnfsObject {
|
||||
return ret
|
||||
}
|
||||
|
||||
|
||||
func (self *VnfsObject) Name() string {
|
||||
if self.SourcePath == "" {
|
||||
return ""
|
||||
@@ -52,21 +48,4 @@ func (self *VnfsObject) Source() string {
|
||||
}
|
||||
|
||||
return self.SourcePath
|
||||
}
|
||||
|
||||
|
||||
func (self *VnfsObject) Image() string {
|
||||
if self.SourcePath == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
return config.LocalStateDir + "/provision/vnfs/" + self.NameClean() + ".img.gz"
|
||||
}
|
||||
|
||||
func (self *VnfsObject) Root() string {
|
||||
if self.SourcePath == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
return config.LocalStateDir + "/chroots/" + self.NameClean()
|
||||
}
|
||||
}
|
||||
@@ -15,11 +15,11 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
logLevel uint
|
||||
logLevel = INFO
|
||||
Indent string
|
||||
)
|
||||
|
||||
func SetLevel(level uint) {
|
||||
func SetLevel(level int) {
|
||||
logLevel = level
|
||||
|
||||
if level == DEBUG {
|
||||
@@ -35,7 +35,7 @@ func SetIndent(i int) {
|
||||
Indent = strings.Repeat(" ", i)
|
||||
}
|
||||
|
||||
func prefixLevel(level uint) {
|
||||
func prefixLevel(level int) {
|
||||
if level == DEBUG {
|
||||
log.SetPrefix("[DEBUG] "+Indent)
|
||||
} else if level == VERBOSE {
|
||||
@@ -51,7 +51,7 @@ func prefixLevel(level uint) {
|
||||
}
|
||||
}
|
||||
|
||||
func Println(level uint, message string) {
|
||||
func Println(level int, message string) {
|
||||
if level <= logLevel {
|
||||
prefixLevel(level)
|
||||
log.Println(message)
|
||||
@@ -60,7 +60,7 @@ func Println(level uint, message string) {
|
||||
log.SetPrefix("[LOG] "+Indent)
|
||||
}
|
||||
|
||||
func Printf(level uint, message string, a...interface{}) {
|
||||
func Printf(level int, message string, a...interface{}) {
|
||||
if level <= logLevel {
|
||||
prefixLevel(level)
|
||||
log.Printf(message, a...)
|
||||
|
||||
Reference in New Issue
Block a user