From f3ec8ee923314f1fd49e780028be5a855b7c235a Mon Sep 17 00:00:00 2001 From: Gregory Kurtzer Date: Mon, 9 Nov 2020 17:24:35 -0800 Subject: [PATCH] Lots of cleanups, added vnfs package and utilizing config package for constants --- cmd/warewulfd/ipxe.go | 4 +- cmd/warewulfd/kernel.go | 5 ++- cmd/warewulfd/kmods.go | 5 ++- cmd/warewulfd/runtime.go | 4 +- cmd/warewulfd/system.go | 5 ++- cmd/warewulfd/vnfs.go | 11 +++-- cmd/warewulfd/warewulfd.go | 14 +++--- cmd/wwbuild/overlay-runtime.go | 59 +++++++++++++------------- cmd/wwbuild/overlay-system.go | 9 ++-- cmd/wwbuild/vnfs-local.go | 14 ++++-- cmd/wwbuild/vnfs-oci.go | 43 +++++++++++++------ cmd/wwbuild/vnfs.go | 22 ++++++++++ cmd/wwbuild/wwbuild.go | 10 +++-- etc/nodes.conf | 2 +- internal/pkg/assets/assets.go | 5 ++- internal/pkg/config/config.go | 24 ++++++++--- internal/pkg/oci/puller.go | 4 +- internal/pkg/vnfs/vnfs.go | 51 ++++++++++++++++++++++ overlays/runtime/default/etc/group.in | 4 +- overlays/runtime/default/etc/passwd.in | 4 +- 20 files changed, 206 insertions(+), 93 deletions(-) create mode 100644 internal/pkg/vnfs/vnfs.go diff --git a/cmd/warewulfd/ipxe.go b/cmd/warewulfd/ipxe.go index 534f6baf..e735df80 100644 --- a/cmd/warewulfd/ipxe.go +++ b/cmd/warewulfd/ipxe.go @@ -12,7 +12,7 @@ import ( "strings" ) -func ipxe(w http.ResponseWriter, req *http.Request) { +func ipxeSend(w http.ResponseWriter, req *http.Request) { url := strings.Split(req.URL.Path, "/") if url[2] == "" { @@ -58,12 +58,10 @@ func ipxe(w http.ResponseWriter, req *http.Request) { // 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]) } diff --git a/cmd/warewulfd/kernel.go b/cmd/warewulfd/kernel.go index 10a5477b..db406f6c 100644 --- a/cmd/warewulfd/kernel.go +++ b/cmd/warewulfd/kernel.go @@ -2,11 +2,12 @@ package main import ( "fmt" + "github.com/hpcng/warewulf/internal/pkg/config" "log" "net/http" ) -func kernel(w http.ResponseWriter, req *http.Request) { +func kernelSend(w http.ResponseWriter, req *http.Request) { node, err := getSanity(req) if err != nil { @@ -16,7 +17,7 @@ func kernel(w http.ResponseWriter, req *http.Request) { } if node.KernelVersion != "" { - fileName := fmt.Sprintf("%s/provision/kernel/vmlinuz-%s", LocalStateDir, node.KernelVersion) + fileName := fmt.Sprintf("%s/provision/kernel/vmlinuz-%s", config.LocalStateDir, node.KernelVersion) err := sendFile(w, fileName, node.Fqdn) if err != nil { diff --git a/cmd/warewulfd/kmods.go b/cmd/warewulfd/kmods.go index 0a090811..7af8de57 100644 --- a/cmd/warewulfd/kmods.go +++ b/cmd/warewulfd/kmods.go @@ -2,11 +2,12 @@ package main import ( "fmt" + "github.com/hpcng/warewulf/internal/pkg/config" "log" "net/http" ) -func kmods(w http.ResponseWriter, req *http.Request) { +func kmodsSend(w http.ResponseWriter, req *http.Request) { node, err := getSanity(req) if err != nil { @@ -15,7 +16,7 @@ func kmods(w http.ResponseWriter, req *http.Request) { return } if node.KernelVersion != "" { - fileName := fmt.Sprintf("%s/provision/kernel/kmods-%s.img", LocalStateDir, node.KernelVersion) + fileName := fmt.Sprintf("%s/provision/kernel/kmods-%s.img", config.LocalStateDir, node.KernelVersion) err := sendFile(w, fileName, node.Fqdn) if err != nil { diff --git a/cmd/warewulfd/runtime.go b/cmd/warewulfd/runtime.go index 0cc793f7..7ee88283 100644 --- a/cmd/warewulfd/runtime.go +++ b/cmd/warewulfd/runtime.go @@ -10,7 +10,7 @@ import ( "strings" ) -func runtimeOverlay(w http.ResponseWriter, req *http.Request) { +func runtimeOverlaySend(w http.ResponseWriter, req *http.Request) { remote := strings.Split(req.RemoteAddr, ":") port, err := strconv.Atoi(remote[1]) if err != nil { @@ -49,7 +49,7 @@ func runtimeOverlay(w http.ResponseWriter, req *http.Request) { } if node.RuntimeOverlay != "" { - fileName := fmt.Sprintf("%s/provision/overlays/runtime/%s.img", LocalStateDir, node.Fqdn) + fileName := fmt.Sprintf("%s/provision/overlays/runtime/%s.img", config.LocalStateDir, node.Fqdn) err := sendFile(w, fileName, node.Fqdn) if err != nil { diff --git a/cmd/warewulfd/system.go b/cmd/warewulfd/system.go index 3f3f6ea9..7efe428b 100644 --- a/cmd/warewulfd/system.go +++ b/cmd/warewulfd/system.go @@ -2,11 +2,12 @@ package main import ( "fmt" + "github.com/hpcng/warewulf/internal/pkg/config" "log" "net/http" ) -func systemOverlay(w http.ResponseWriter, req *http.Request) { +func systemOverlaySend(w http.ResponseWriter, req *http.Request) { node, err := getSanity(req) if err != nil { @@ -16,7 +17,7 @@ func systemOverlay(w http.ResponseWriter, req *http.Request) { } if node.SystemOverlay != "" { - fileName := fmt.Sprintf("%s/provision/overlays/system/%s.img", LocalStateDir, node.Fqdn) + fileName := fmt.Sprintf("%s/provision/overlays/system/%s.img", config.LocalStateDir, node.Fqdn) err := sendFile(w, fileName, node.Fqdn) if err != nil { diff --git a/cmd/warewulfd/vnfs.go b/cmd/warewulfd/vnfs.go index b7747a2a..675a3ffc 100644 --- a/cmd/warewulfd/vnfs.go +++ b/cmd/warewulfd/vnfs.go @@ -1,13 +1,12 @@ package main import ( - "fmt" + "github.com/hpcng/warewulf/internal/pkg/vnfs" "log" "net/http" - "path" ) -func vnfs(w http.ResponseWriter, req *http.Request) { +func vnfsSend(w http.ResponseWriter, req *http.Request) { node, err := getSanity(req) if err != nil { @@ -17,13 +16,13 @@ func vnfs(w http.ResponseWriter, req *http.Request) { } if node.Vnfs != "" { - fileName := fmt.Sprintf("%s/provision/vnfs/%s.img.gz", LocalStateDir, path.Base(node.Vnfs)) + v := vnfs.New(node.Vnfs) - err := sendFile(w, fileName, node.Fqdn) + 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, fileName) + log.Printf("SEND: %15s: %s\n", node.Fqdn, v.Image()) } } else { w.WriteHeader(503) diff --git a/cmd/warewulfd/warewulfd.go b/cmd/warewulfd/warewulfd.go index 912c1516..1cf34ed0 100644 --- a/cmd/warewulfd/warewulfd.go +++ b/cmd/warewulfd/warewulfd.go @@ -15,7 +15,7 @@ import ( // TODO: https://github.com/danderson/netboot/blob/master/pixiecore/dhcp.go // TODO: https://github.com/pin/tftp -const LocalStateDir = "/var/warewulf" +//const LocalStateDir = "/var/warewulf" func getSanity(req *http.Request) (assets.NodeInfo, error) { url := strings.Split(req.URL.Path, "/") @@ -62,12 +62,12 @@ func sendFile(w http.ResponseWriter, filename string, sendto string) error { func main() { - http.HandleFunc("/ipxe/", ipxe) - http.HandleFunc("/kernel/", kernel) - http.HandleFunc("/kmods/", kmods) - http.HandleFunc("/vnfs/", vnfs) - http.HandleFunc("/overlay-system/", systemOverlay) - http.HandleFunc("/overlay-runtime", runtimeOverlay) + 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) } diff --git a/cmd/wwbuild/overlay-runtime.go b/cmd/wwbuild/overlay-runtime.go index a1ca74b7..6e077c87 100644 --- a/cmd/wwbuild/overlay-runtime.go +++ b/cmd/wwbuild/overlay-runtime.go @@ -3,6 +3,7 @@ package main import ( "fmt" "github.com/hpcng/warewulf/internal/pkg/assets" + "github.com/hpcng/warewulf/internal/pkg/config" "github.com/hpcng/warewulf/internal/pkg/util" "os" "os/exec" @@ -13,22 +14,22 @@ import ( func overlayRuntime(node assets.NodeInfo, replace map[string]string, wg *sync.WaitGroup) { defer wg.Done() - OverlayDir := fmt.Sprintf("%s/overlays/runtime/%s", LocalStateDir, node.RuntimeOverlay) - OverlayFile := fmt.Sprintf("%s/provision/overlays/runtime/%s.img", LocalStateDir, node.Fqdn) -/* - destModTime := time.Time{} - destMod, err := os.Stat(OverlayFile) - if err == nil { - destModTime = destMod.ModTime() - } - configMod, err := os.Stat("/etc/warewulf/nodes.conf") - if err != nil { - fmt.Printf("ERROR: could not find node file: /etc/warewulf/nodes.conf") - os.Exit(1) - } - configModTime := configMod.ModTime() - sourceModTime, _ := util.DirModTime(OverlayDir) -*/ + OverlayDir := fmt.Sprintf("%s/overlays/runtime/%s", config.LocalStateDir, node.RuntimeOverlay) + OverlayFile := fmt.Sprintf("%s/provision/overlays/runtime/%s.img", config.LocalStateDir, node.Fqdn) + /* + destModTime := time.Time{} + destMod, err := os.Stat(OverlayFile) + if err == nil { + destModTime = destMod.ModTime() + } + configMod, err := os.Stat("/etc/warewulf/nodes.conf") + if err != nil { + fmt.Printf("ERROR: could not find node file: /etc/warewulf/nodes.conf") + os.Exit(1) + } + configModTime := configMod.ModTime() + sourceModTime, _ := util.DirModTime(OverlayDir) + */ err := os.MkdirAll(path.Dir(OverlayFile), 0755) if err != nil { fmt.Printf("ERROR: %s\n", err) @@ -39,20 +40,20 @@ func overlayRuntime(node assets.NodeInfo, replace map[string]string, wg *sync.Wa fmt.Printf("ERROR: %s\n", err) return } -// if sourceModTime.After(destModTime) || configModTime.After(destModTime) { - fmt.Printf("RUNTIME: %s\n", node.Fqdn) + // if sourceModTime.After(destModTime) || configModTime.After(destModTime) { + fmt.Printf("RUNTIME: %s\n", node.Fqdn) - overlayDest := "/tmp/.overlay-" + util.RandomString(16) - BuildOverlayDir(OverlayDir, overlayDest, replace) + overlayDest := "/tmp/.overlay-" + util.RandomString(16) + BuildOverlayDir(OverlayDir, overlayDest, replace) - cmd := fmt.Sprintf("cd %s && find . | cpio --quiet -o -H newc -F \"%s\"", overlayDest, OverlayFile) - err = exec.Command("/bin/sh", "-c", cmd).Run() - if err != nil { - fmt.Printf("%s", err) - } + cmd := fmt.Sprintf("cd %s && find . | cpio --quiet -o -H newc -F \"%s\"", overlayDest, OverlayFile) + err = exec.Command("/bin/sh", "-c", cmd).Run() + if err != nil { + fmt.Printf("%s", err) + } - os.RemoveAll(overlayDest) -// } else { -// fmt.Printf("RUNTIME: %s (skipped no changes)\n", node.Fqdn) -// } + os.RemoveAll(overlayDest) + // } else { + // fmt.Printf("RUNTIME: %s (skipped no changes)\n", node.Fqdn) + // } } diff --git a/cmd/wwbuild/overlay-system.go b/cmd/wwbuild/overlay-system.go index eaba6315..0cfaca23 100644 --- a/cmd/wwbuild/overlay-system.go +++ b/cmd/wwbuild/overlay-system.go @@ -3,6 +3,7 @@ package main import ( "fmt" "github.com/hpcng/warewulf/internal/pkg/assets" + "github.com/hpcng/warewulf/internal/pkg/config" "github.com/hpcng/warewulf/internal/pkg/util" "os" "os/exec" @@ -14,17 +15,17 @@ import ( func overlaySystem(node assets.NodeInfo, replace map[string]string, wg *sync.WaitGroup) { defer wg.Done() - OverlayDir := fmt.Sprintf("%s/overlays/system/%s", LocalStateDir, node.SystemOverlay) - OverlayFile := fmt.Sprintf("%s/provision/overlays/system/%s.img", LocalStateDir, node.Fqdn) + OverlayDir := fmt.Sprintf("%s/overlays/system/%s", config.LocalStateDir, node.SystemOverlay) + OverlayFile := fmt.Sprintf("%s/provision/overlays/system/%s.img", config.LocalStateDir, node.Fqdn) destModTime := time.Time{} destMod, err := os.Stat(OverlayFile) if err == nil { destModTime = destMod.ModTime() } - configMod, err := os.Stat("/etc/warewulf/nodes.conf") + configMod, err := os.Stat(config.SysConfDir + "nodes.conf") if err != nil { - fmt.Printf("ERROR: could not find node file: /etc/warewulf/nodes.conf\n") + fmt.Printf("ERROR: could not find node file: nodes.conf\n", config.SysConfDir) os.Exit(1) } configModTime := configMod.ModTime() diff --git a/cmd/wwbuild/vnfs-local.go b/cmd/wwbuild/vnfs-local.go index 4a0fdb0c..91e5babb 100644 --- a/cmd/wwbuild/vnfs-local.go +++ b/cmd/wwbuild/vnfs-local.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/hpcng/warewulf/internal/pkg/vnfs" "os" "path" "sync" @@ -9,22 +10,29 @@ import ( func vnfsLocalBuild(vnfsPath string, wg *sync.WaitGroup) { defer wg.Done() + v := vnfs.New(vnfsPath) if _, err := os.Stat(vnfsPath); err == nil { // TODO: Build VNFS to temporary file and move to real location when complete atomically // TODO: Check time stamps of sourcedir and build file to see if we need to rebuild or skip - vnfsDestination := fmt.Sprintf("%s/provision/vnfs/%s.img.gz", LocalStateDir, path.Base(vnfsPath)) + //vnfsDestination := fmt.Sprintf("%s/provision/vnfs/%s.img.gz", LocalStateDir, path.Base(vnfsPath)) fmt.Printf("Building local Container: %s\n", vnfsPath) - err := os.MkdirAll(path.Dir(vnfsDestination), 0755) + err := os.MkdirAll(path.Dir(v.Image()), 0755) if err != nil { fmt.Printf("ERROR: %s\n", err) return } - err = buildVnfs(vnfsPath, vnfsDestination) + err = buildVnfs(vnfsPath, v.Image()) + if err != nil { + fmt.Printf("ERROR: %s\n", err) + os.Exit(1) + } + + err = buildLinks(v, vnfsPath) if err != nil { fmt.Printf("ERROR: %s\n", err) os.Exit(1) diff --git a/cmd/wwbuild/vnfs-oci.go b/cmd/wwbuild/vnfs-oci.go index 7d15555f..399fbc0c 100644 --- a/cmd/wwbuild/vnfs-oci.go +++ b/cmd/wwbuild/vnfs-oci.go @@ -3,75 +3,90 @@ package main import ( "context" "fmt" + "github.com/hpcng/warewulf/internal/pkg/config" "github.com/hpcng/warewulf/internal/pkg/oci" + "github.com/hpcng/warewulf/internal/pkg/vnfs" "log" "os" "path" "sync" ) +const ( + OciCacheDir = config.LocalStateDir + "/oci" + VnfsHashDir = config.LocalStateDir + "/oci/vnfs/hash/" +) + func vnfsOciBuild(OciPath string, wg *sync.WaitGroup) { - vnfsDestination := fmt.Sprintf("%s/provision/vnfs/%s.img.gz", LocalStateDir, path.Base(OciPath)) + v := vnfs.New(OciPath) + + // vnfsDestination := fmt.Sprintf("%s/provision/vnfs/%s.img.gz", LocalStateDir, path.Base(OciPath)) defer wg.Done() log.Printf("Building OCI Container: %s\n", OciPath) - c, err := oci.NewCache(oci.OptSetCachePath("/var/warewulf/oci")) + + c, err := oci.NewCache(oci.OptSetCachePath(OciCacheDir)) if err != nil { fmt.Printf("ERROR: %s\n", err) os.Exit(1) } + log.Printf("Downloading OCI container layers\n") sourcePath, err := c.Pull(context.Background(), OciPath, nil) if err != nil { fmt.Printf("ERROR: %s\n", err) os.Exit(1) } - ociDestination := fmt.Sprintf("%s/oci/vnfs/hash/%s", LocalStateDir, path.Base(sourcePath)) + hashDestination := VnfsHashDir + path.Base(sourcePath) - name, err := os.Readlink(vnfsDestination) + name, err := os.Readlink(v.Image()) if err == nil { - if name == ociDestination { - log.Printf("Container already built, no changes from upstream\n") + if name == hashDestination { + log.Printf("Container already built, no update available\n") return } } - err = os.MkdirAll(path.Dir(ociDestination), 0755) + err = os.MkdirAll(VnfsHashDir, 0755) if err != nil { fmt.Printf("ERROR: %s\n", err) return } - err = os.MkdirAll(path.Dir(vnfsDestination), 0755) + err = os.MkdirAll(path.Dir(v.Image()), 0755) if err != nil { fmt.Printf("ERROR: %s\n", err) return } - err = os.MkdirAll(LocalStateDir+"/oci/vnfs/name", 0755) + err = os.MkdirAll(path.Dir(v.Root()), 0755) if err != nil { fmt.Printf("ERROR: %s\n", err) return } - err = buildVnfs(sourcePath, ociDestination) + log.Printf("Building bootable VNFS image\n") + + err = buildVnfs(sourcePath, hashDestination) if err != nil { fmt.Printf("ERROR: %s\n", err) os.Exit(1) } - err = os.Symlink(ociDestination, vnfsDestination+"-link") + log.Printf("Finalizing Build\n") + + _ = os.Remove(v.Image() + "-link") + err = os.Symlink(hashDestination, v.Image()+"-link") if err != nil { fmt.Printf("ERROR: %s\n", err) os.Exit(1) } + err = os.Rename(v.Image()+"-link", v.Image()) - err = os.Symlink(sourcePath, LocalStateDir+"/oci/vnfs/name/"+path.Base(OciPath)) + err = buildLinks(v, sourcePath) if err != nil { fmt.Printf("ERROR: %s\n", err) os.Exit(1) } - err = os.Rename(vnfsDestination+"-link", vnfsDestination) - log.Printf("Completed building VNFS: %s\n", path.Base(OciPath)) return diff --git a/cmd/wwbuild/vnfs.go b/cmd/wwbuild/vnfs.go index d113b0d2..f9ab7f67 100644 --- a/cmd/wwbuild/vnfs.go +++ b/cmd/wwbuild/vnfs.go @@ -2,6 +2,8 @@ package main import ( "fmt" + "github.com/hpcng/warewulf/internal/pkg/vnfs" + "os" "os/exec" ) @@ -12,3 +14,23 @@ 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") + + // 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 +} diff --git a/cmd/wwbuild/wwbuild.go b/cmd/wwbuild/wwbuild.go index 533f1db8..8daa7e4f 100644 --- a/cmd/wwbuild/wwbuild.go +++ b/cmd/wwbuild/wwbuild.go @@ -3,6 +3,8 @@ package main import ( "fmt" "github.com/hpcng/warewulf/internal/pkg/assets" + "github.com/hpcng/warewulf/internal/pkg/config" + "github.com/hpcng/warewulf/internal/pkg/vnfs" "os" "os/exec" "path" @@ -11,8 +13,6 @@ import ( "time" ) -const LocalStateDir = "/var/warewulf" - func main() { if len(os.Args) < 2 { @@ -80,8 +80,8 @@ func main() { kernelSource := fmt.Sprintf("/boot/vmlinuz-%s", kernelVers) // TODO: Check time stamps of source and dests to see if we need to rebuild or skip if _, err := os.Stat(kernelSource); err == nil { - kernelDestination := fmt.Sprintf("%s/provision/kernel/vmlinuz-%s", LocalStateDir, kernelVers) - kmodsDestination := fmt.Sprintf("%s/provision/kernel/kmods-%s.img", LocalStateDir, kernelVers) + kernelDestination := fmt.Sprintf("%s/provision/kernel/vmlinuz-%s", config.LocalStateDir, kernelVers) + kmodsDestination := fmt.Sprintf("%s/provision/kernel/kmods-%s.img", config.LocalStateDir, kernelVers) err := os.MkdirAll(path.Dir(kernelDestination), 0755) if err != nil { @@ -123,10 +123,12 @@ func main() { } for _, node := range nodeList { + v := vnfs.New(node.Vnfs) replace := make(map[string]string) replace["HOSTNAME"] = node.HostName replace["FQDN"] = node.Fqdn replace["VNFS"] = node.Vnfs + replace["VNFSDIR"] = v.Root() replace["KERNELVERSION"] = node.KernelVersion replace["GROUPNAME"] = node.GroupName replace["DOMAIN"] = node.DomainName diff --git a/etc/nodes.conf b/etc/nodes.conf index 6affbecc..8ca76f27 100644 --- a/etc/nodes.conf +++ b/etc/nodes.conf @@ -18,7 +18,7 @@ nodegroups: gateway: 192.168.1.1 group_2: comment: This is the group 2 - vnfs: /var/chroots/centos-7 + vnfs: docker://warewulf/centos-7 system overlay: default runtime overlay: default domain suffix: group2 diff --git a/internal/pkg/assets/assets.go b/internal/pkg/assets/assets.go index 190b485a..eb08c4a3 100644 --- a/internal/pkg/assets/assets.go +++ b/internal/pkg/assets/assets.go @@ -64,6 +64,7 @@ type NodeInfo struct { DomainName string Fqdn string Vnfs string + VnfsDir string Ipxe string SystemOverlay string RuntimeOverlay string @@ -139,7 +140,9 @@ func FindAllNodes() ([]NodeInfo, error) { if strings.HasPrefix(n.Vnfs, "docker://") { //TODO: This is a kludge and shouldn't be done here. We need to go back // and do this from a "vnfs" interface or package - n.Vnfs = LocalStateDir + "/oci/vnfs/name/" + path.Base(n.Vnfs) + n.VnfsDir = LocalStateDir + "/oci/vnfs/name/" + path.Base(n.Vnfs) + } else { + n.VnfsDir = n.Vnfs } ret = append(ret, n) diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go index 887d46b3..1717cdd9 100644 --- a/internal/pkg/config/config.go +++ b/internal/pkg/config/config.go @@ -9,19 +9,22 @@ import ( // THIS IS NOT BEING USED YET AND IS THUS A WORK IN PROGRESS -const ConfigFile = "/etc/warewulf/warewulf.conf" +const SysConfDir = "/etc/warewulf/" +const LocalStateDir = "/var/warewulf" type Config struct { - Port int `yaml:"warewulfd port", envconfig:"WAREWULFD_PORT"` - Ipaddr string `yaml:"warewulfd ipaddr", envconfig:"WAREWULFD_IPADDR"` - InsecureRuntime bool `yaml:"insecure runtime"` - Debug bool `yaml:"debug"` + Port int `yaml:"warewulfd port", envconfig:"WAREWULFD_PORT"` + Ipaddr string `yaml:"warewulfd ipaddr", envconfig:"WAREWULFD_IPADDR"` + InsecureRuntime bool `yaml:"insecure runtime"` + Debug bool `yaml:"debug"` + SysConfDir string `yaml:"system config dir"` + LocalStateDir string `yaml:"local state dir"` } func New() (Config, error) { var c Config - fd, err := ioutil.ReadFile(ConfigFile) + fd, err := ioutil.ReadFile(SysConfDir + "warewulf.conf") if err != nil { return c, err } @@ -37,7 +40,14 @@ func New() (Config, error) { } if c.Ipaddr == "" { - fmt.Printf("ERROR: 'warewulf ipaddr' has not been set in %s\n", ConfigFile) + fmt.Printf("ERROR: 'warewulf ipaddr' has not been set in %s\n", SysConfDir+"warewulf.conf") + } + + if c.SysConfDir == "" { + c.SysConfDir = SysConfDir + } + if c.LocalStateDir == "" { + c.LocalStateDir = LocalStateDir } return c, nil diff --git a/internal/pkg/oci/puller.go b/internal/pkg/oci/puller.go index e7e7c4ee..f04704a9 100644 --- a/internal/pkg/oci/puller.go +++ b/internal/pkg/oci/puller.go @@ -126,8 +126,8 @@ func (p *puller) pull(ctx context.Context, uri, dst string) (err error) { // copy to cache location _, err = copy.Image(ctx, policyCtx, cacheRef, srcRef, ©.Options{ - ReportWriter: os.Stdout, - SourceCtx: p.sysCtx, + //ReportWriter: os.Stdout, + SourceCtx: p.sysCtx, }) if err != nil { return err diff --git a/internal/pkg/vnfs/vnfs.go b/internal/pkg/vnfs/vnfs.go new file mode 100644 index 00000000..5d7c01ea --- /dev/null +++ b/internal/pkg/vnfs/vnfs.go @@ -0,0 +1,51 @@ +package vnfs + +import ( + "github.com/hpcng/warewulf/internal/pkg/config" + "path" + "strings" +) + +type VnfsObject struct { + Source string + RootPath string + ImagePath string +} + +func New(s string) VnfsObject { + var ret VnfsObject + + ret.Source = s + + return ret +} + +func (self *VnfsObject) Name() string { + if self.Source == "" { + return "" + } + + if strings.HasPrefix(self.Source, "/") { + return path.Base(self.Source) + } + + uri := strings.Split(self.Source, "://") + + return strings.ReplaceAll(uri[0]+":"+uri[1], "/", "_") +} + +func (self *VnfsObject) Image() string { + if self.Source == "" { + return "" + } + + return config.LocalStateDir + "/provision/vnfs/" + self.Name() + ".img.gz" +} + +func (self *VnfsObject) Root() string { + if self.Source == "" { + return "" + } + + return config.LocalStateDir + "/chroots/" + self.Name() +} diff --git a/overlays/runtime/default/etc/group.in b/overlays/runtime/default/etc/group.in index a16792ab..e1ba0627 100644 --- a/overlays/runtime/default/etc/group.in +++ b/overlays/runtime/default/etc/group.in @@ -1,2 +1,2 @@ -#WWINCLUDE @VNFS@/etc/group -#WWINCLUDE /etc/group \ No newline at end of file +#WWINCLUDE @VNFSDIR@/etc/group +#WWINCLUDE /etc/group diff --git a/overlays/runtime/default/etc/passwd.in b/overlays/runtime/default/etc/passwd.in index 3e298b08..22100da3 100644 --- a/overlays/runtime/default/etc/passwd.in +++ b/overlays/runtime/default/etc/passwd.in @@ -1,3 +1,3 @@ root::0:0:root:/root:/bin/bash -#WWINCLUDE @VNFS@/etc/passwd -#WWINCLUDE /etc/passwd \ No newline at end of file +#WWINCLUDE @VNFSDIR@/etc/passwd +#WWINCLUDE /etc/passwd