From f87708784d516ef8c26f1d00c29382f59ab3f235 Mon Sep 17 00:00:00 2001 From: Gregory Kurtzer Date: Thu, 19 Nov 2020 16:56:22 -0800 Subject: [PATCH] Minor cleanups and fleshed out the `wwctl overlay show` command --- internal/app/wwctl/build/kernel/kernel.go | 73 --------- .../app/wwctl/build/{build.go => main.go} | 85 ++++++++++- internal/app/wwctl/build/root.go | 1 + .../build/runtime-overlay/runtime-overlay.go | 144 ------------------ .../build/system-overlay/system-overlay.go | 144 ------------------ internal/app/wwctl/build/vnfs/containerdir.go | 65 -------- internal/app/wwctl/build/vnfs/docker.go | 102 ------------- internal/app/wwctl/build/vnfs/util.go | 14 -- internal/app/wwctl/build/vnfs/vnfs.go | 47 ------ internal/app/wwctl/overlay/show/main.go | 47 ++++++ internal/app/wwctl/overlay/show/root.go | 13 +- internal/pkg/overlay/overlay.go | 3 +- 12 files changed, 133 insertions(+), 605 deletions(-) delete mode 100644 internal/app/wwctl/build/kernel/kernel.go rename internal/app/wwctl/build/{build.go => main.go} (53%) delete mode 100644 internal/app/wwctl/build/runtime-overlay/runtime-overlay.go delete mode 100644 internal/app/wwctl/build/system-overlay/system-overlay.go delete mode 100644 internal/app/wwctl/build/vnfs/containerdir.go delete mode 100644 internal/app/wwctl/build/vnfs/docker.go delete mode 100644 internal/app/wwctl/build/vnfs/util.go delete mode 100644 internal/app/wwctl/build/vnfs/vnfs.go create mode 100644 internal/app/wwctl/overlay/show/main.go diff --git a/internal/app/wwctl/build/kernel/kernel.go b/internal/app/wwctl/build/kernel/kernel.go deleted file mode 100644 index 08f3d850..00000000 --- a/internal/app/wwctl/build/kernel/kernel.go +++ /dev/null @@ -1,73 +0,0 @@ -package kernel - -import ( - "fmt" - "github.com/hpcng/warewulf/internal/pkg/assets" - "github.com/hpcng/warewulf/internal/pkg/config" - "github.com/hpcng/warewulf/internal/pkg/util" - "github.com/hpcng/warewulf/internal/pkg/wwlog" - "os" - "os/exec" - "path" -) - -func Build(nodeList []assets.NodeInfo, force bool) error { - config := config.New() - set := make(map[string]int) - - wwlog.Printf(wwlog.INFO, "Importing Kernels:\n") - wwlog.SetIndent(4) - - for _, node := range nodeList { - if node.KernelVersion != "" { - set[node.KernelVersion] ++ - wwlog.Printf(wwlog.DEBUG, "Node '%s' has KernelVersion '%s'\n", node.Fqdn, node.KernelVersion) - } - } - - for kernelVersion := range set { - kernelImage := "/boot/vmlinuz-"+kernelVersion - kernelDrivers := "/lib/modules/"+kernelVersion - 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) - - - if _, err := os.Stat(kernelImage); err == nil { - if util.PathIsNewer(kernelImage, kernelDestination) && force == false { - wwlog.Printf(wwlog.INFO, "%-35s: Skipping, kernel is current\n", "vmlinuz-"+kernelVersion) - - } else { - err := util.CopyFile(kernelImage, kernelDestination) - if err != nil { - wwlog.Printf(wwlog.ERROR, "Failed copying kernel image: %s\n", err) - continue - } - wwlog.Printf(wwlog.INFO, "%-35s: Done\n", "vmlinuz-"+kernelVersion) - - } - } - - if _, err := os.Stat(kernelDrivers); err == nil { - if util.PathIsNewer(kernelDrivers, driversDestination) && force == false { - wwlog.Printf(wwlog.INFO, "%-35s: Skipping, drivers are current\n", "kmods-"+kernelVersion+".img") - - } else { - 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 { - wwlog.Printf(wwlog.ERROR, "Could not generate kernel driver overlay: %s\n", err) - continue - } - wwlog.Printf(wwlog.INFO, "%-35s: Done\n", "kmods-"+kernelVersion+".img") - } - } - } - - wwlog.SetIndent(0) - - return nil -} \ No newline at end of file diff --git a/internal/app/wwctl/build/build.go b/internal/app/wwctl/build/main.go similarity index 53% rename from internal/app/wwctl/build/build.go rename to internal/app/wwctl/build/main.go index 323c6095..7db258ab 100644 --- a/internal/app/wwctl/build/build.go +++ b/internal/app/wwctl/build/main.go @@ -1,11 +1,10 @@ package build import ( - "github.com/hpcng/warewulf/internal/app/wwctl/build/kernel" - runtime_overlay "github.com/hpcng/warewulf/internal/app/wwctl/build/runtime-overlay" - system_overlay "github.com/hpcng/warewulf/internal/app/wwctl/build/system-overlay" - "github.com/hpcng/warewulf/internal/app/wwctl/build/vnfs" "github.com/hpcng/warewulf/internal/pkg/assets" + "github.com/hpcng/warewulf/internal/pkg/kernel" + "github.com/hpcng/warewulf/internal/pkg/overlay" + "github.com/hpcng/warewulf/internal/pkg/vnfs" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/spf13/cobra" "os" @@ -13,6 +12,80 @@ import ( func CobraRunE(cmd *cobra.Command, args []string) error { + var nodes []assets.NodeInfo + showHelp := true + + if len(args) > 0 { + var err error + nodes, err = assets.SearchByName(args[0]) + if err != nil { + wwlog.Printf(wwlog.ERROR, "Could not find nodes for search term: %s\n", args[0]) + os.Exit(1) + } + + } else { + var err error + nodes, err = assets.FindAllNodes() + if err != nil { + wwlog.Printf(wwlog.ERROR, "Could not get list of nodes: %s\n", err) + os.Exit(1) + } + + } + + if buildVnfs == true || buildAll == true { + set := make(map[string]int) + showHelp = false + + wwlog.Printf(wwlog.INFO, "Building VNFS images...\n") + + for _, node := range nodes { + set[node.Vnfs] ++ + } + for e := range set { + vnfs.Build(e, buildForce) + } + } + + if buildKernel == true || buildAll == true { + set := make(map[string]int) + showHelp = false + + wwlog.Printf(wwlog.INFO, "Building Kernel images...\n") + + for _, node := range nodes { + set[node.KernelVersion] ++ + } + for e := range set { + kernel.Build(e) + } + } + + if buildSystemOverlay == true || buildAll == true { + wwlog.Printf(wwlog.INFO, "Building System Overlays...\n") + showHelp = false + + overlay.SystemBuild(nodes, buildForce) + } + + if buildRuntimeOverlay == true || buildAll == true { + wwlog.Printf(wwlog.INFO, "Building Runtime Overlays...n") + showHelp = false + + overlay.RuntimeBuild(nodes, buildForce) + } + + if showHelp == true { + cmd.Usage() + os.Exit(1) + } + + return nil +} + + +/* +func CobraRunEA(cmd *cobra.Command, args []string) error { var nodeList []assets.NodeInfo if buildAll == true { @@ -76,4 +149,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error { return nil -} \ No newline at end of file +} + + */ \ No newline at end of file diff --git a/internal/app/wwctl/build/root.go b/internal/app/wwctl/build/root.go index 494aef6d..32329651 100644 --- a/internal/app/wwctl/build/root.go +++ b/internal/app/wwctl/build/root.go @@ -13,6 +13,7 @@ var ( "that seems to be needed.", RunE: CobraRunE, } + buildVnfs bool buildKernel bool buildRuntimeOverlay bool diff --git a/internal/app/wwctl/build/runtime-overlay/runtime-overlay.go b/internal/app/wwctl/build/runtime-overlay/runtime-overlay.go deleted file mode 100644 index b1168aa1..00000000 --- a/internal/app/wwctl/build/runtime-overlay/runtime-overlay.go +++ /dev/null @@ -1,144 +0,0 @@ -package runtime_overlay - -import ( - "fmt" - "github.com/hpcng/warewulf/internal/pkg/assets" - "github.com/hpcng/warewulf/internal/pkg/config" - "github.com/hpcng/warewulf/internal/pkg/util" - "github.com/hpcng/warewulf/internal/pkg/wwlog" - "io/ioutil" - "os" - "os/exec" - "path" - "path/filepath" - "regexp" - "strings" - "text/template" -) - -func fileInclude(path string) string { - wwlog.Printf(wwlog.DEBUG, "Including file into template: %s\n", path) - content, err := ioutil.ReadFile(path) - if err != nil { - wwlog.Printf(wwlog.ERROR, "Template include: %s\n", err) - } - return strings.TrimSuffix(string(content), "\n") -} - -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 := config.RuntimeOverlaySource(node.RuntimeOverlay) - OverlayFile := config.RuntimeOverlayImage(node.Fqdn) - - wwlog.Printf(wwlog.VERBOSE, "Building Runtime Overlay for: %s\n", node.Fqdn) - - tmpDir, err := ioutil.TempDir(os.TempDir(), ".wwctl-runtime-overlay-") - if err != nil { - return err - } - - if _, err := os.Stat(OverlayDir); err != nil { - return err - } - - err = os.MkdirAll(path.Dir(OverlayFile), 0755) - if err != nil { - return err - } - - if force == false { - wwlog.Printf(wwlog.DEBUG, "Checking if overlay is required\n") - } - if util.PathIsNewer(OverlayDir, OverlayFile) { - if force == false { - wwlog.Printf(wwlog.INFO, "%-35s: Skipping, overlay is current\n", node.Fqdn) - continue - } - } - - wwlog.Printf(wwlog.DEBUG, "Changing directory to OverlayDir: %s\n", OverlayDir) - err = os.Chdir(OverlayDir) - if err != nil { - wwlog.Printf(wwlog.ERROR, "Could not chdir() to OverlayDir: %s\n", OverlayDir) - continue - } - - wwlog.Printf(wwlog.DEBUG, "Walking the file system: %s\n", OverlayDir) - err = filepath.Walk(".", func(location string, info os.FileInfo, err error) error { - if err != nil { - return err - } - - if info.IsDir() { - wwlog.Printf(wwlog.DEBUG, "Found directory: %s\n", location) - - err := os.MkdirAll(path.Join(tmpDir, location), info.Mode()) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - return err - } - - } else if filepath.Ext(location) == ".ww" { - wwlog.Printf(wwlog.DEBUG, "Found template file: %s\n", location) - - destFile := strings.TrimSuffix(location, ".ww") - - tmpl, err := template.New(path.Base(location)).Funcs(template.FuncMap{"Include": fileInclude}).ParseGlob(path.Join(OverlayDir, destFile + ".ww*")) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - return err - } - - w, err := os.OpenFile(path.Join(tmpDir, destFile), os.O_RDWR|os.O_CREATE, info.Mode()) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - return err - } - defer w.Close() - - err = tmpl.Execute(w, node) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - return err - } - - } else if b, _ := regexp.MatchString(`\.ww[a-zA-Z0-9\-\._]*$`, location); b == true { - wwlog.Printf(wwlog.DEBUG, "Ignoring WW template file: %s\n", location) - } else { - wwlog.Printf(wwlog.DEBUG, "Found file: %s\n", location) - - err := util.CopyFile(path.Join(OverlayDir, location), path.Join(tmpDir, location)) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - return err - } - - } - - return nil - }) - wwlog.Printf(wwlog.VERBOSE, "Finished generating overlay directory for: %s\n", node.Fqdn) - - cmd := fmt.Sprintf("cd \"%s\"; find . | cpio --quiet -o -H newc -F \"%s\"", tmpDir, OverlayFile) - wwlog.Printf(wwlog.DEBUG, "RUNNING: %s\n", cmd) - err = exec.Command("/bin/sh", "-c", cmd).Run() - if err != nil { - wwlog.Printf(wwlog.ERROR, "Could not generate runtime image overlay: %s\n", err) - continue - } - wwlog.Printf(wwlog.INFO, "%-35s: Done\n", node.Fqdn) - - wwlog.Printf(wwlog.DEBUG, "Removing temporary directory: %s\n", tmpDir) - os.RemoveAll(tmpDir) - } - } - - wwlog.SetIndent(0) - return nil -} diff --git a/internal/app/wwctl/build/system-overlay/system-overlay.go b/internal/app/wwctl/build/system-overlay/system-overlay.go deleted file mode 100644 index 2e1dee02..00000000 --- a/internal/app/wwctl/build/system-overlay/system-overlay.go +++ /dev/null @@ -1,144 +0,0 @@ -package system_overlay - -import ( - "fmt" - "github.com/hpcng/warewulf/internal/pkg/assets" - "github.com/hpcng/warewulf/internal/pkg/config" - "github.com/hpcng/warewulf/internal/pkg/util" - "github.com/hpcng/warewulf/internal/pkg/wwlog" - "io/ioutil" - "os" - "os/exec" - "path" - "path/filepath" - "regexp" - "strings" - "text/template" -) - -func fileInclude(path string) string { - wwlog.Printf(wwlog.DEBUG, "Including file into template: %s\n", path) - content, err := ioutil.ReadFile(path) - if err != nil { - wwlog.Printf(wwlog.ERROR, "Template include: %s\n", err) - } - return strings.TrimSuffix(string(content), "\n") -} - -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 := config.SystemOverlaySource(node.SystemOverlay) - OverlayFile := config.SystemOverlayImage(node.Fqdn) - - wwlog.Printf(wwlog.VERBOSE, "Building System Overlay for: %s\n", node.Fqdn) - - tmpDir, err := ioutil.TempDir(os.TempDir(), ".wwctl-system-overlay-") - if err != nil { - return err - } - - if _, err := os.Stat(OverlayDir); err != nil { - return err - } - - err = os.MkdirAll(path.Dir(OverlayFile), 0755) - if err != nil { - return err - } - - if force == false { - wwlog.Printf(wwlog.DEBUG, "Checking if overlay is required\n") - } - if util.PathIsNewer(OverlayDir, OverlayFile) { - if force == false { - wwlog.Printf(wwlog.INFO, "%-35s: Skipping, overlay is current\n", node.Fqdn) - continue - } - } - - wwlog.Printf(wwlog.DEBUG, "Changing directory to OverlayDir: %s\n", OverlayDir) - err = os.Chdir(OverlayDir) - if err != nil { - wwlog.Printf(wwlog.ERROR, "Could not chdir() to OverlayDir: %s\n", OverlayDir) - continue - } - - wwlog.Printf(wwlog.DEBUG, "Walking the file system: %s\n", OverlayDir) - err = filepath.Walk(".", func(location string, info os.FileInfo, err error) error { - if err != nil { - return err - } - - if info.IsDir() { - wwlog.Printf(wwlog.DEBUG, "Found directory: %s\n", location) - - err := os.MkdirAll(path.Join(tmpDir, location), info.Mode()) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - return err - } - - } else if filepath.Ext(location) == ".ww" { - wwlog.Printf(wwlog.DEBUG, "Found template file: %s\n", location) - - destFile := strings.TrimSuffix(location, ".ww") - - tmpl, err := template.New(path.Base(location)).Funcs(template.FuncMap{"Include": fileInclude}).ParseGlob(path.Join(OverlayDir, destFile + ".ww*")) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - return err - } - - w, err := os.OpenFile(path.Join(tmpDir, destFile), os.O_RDWR|os.O_CREATE, info.Mode()) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - return err - } - defer w.Close() - - err = tmpl.Execute(w, node) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - return err - } - - } else if b, _ := regexp.MatchString(`\.ww[a-zA-Z0-9\-\._]*$`, location); b == true { - wwlog.Printf(wwlog.DEBUG, "Ignoring WW template file: %s\n", location) - } else { - wwlog.Printf(wwlog.DEBUG, "Found file: %s\n", location) - - err := util.CopyFile(path.Join(OverlayDir, location), path.Join(tmpDir, location)) - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - return err - } - - } - - return nil - }) - wwlog.Printf(wwlog.VERBOSE, "Finished generating overlay directory for: %s\n", node.Fqdn) - - cmd := fmt.Sprintf("cd \"%s\"; find . | cpio --quiet -o -H newc -F \"%s\"", tmpDir, OverlayFile) - wwlog.Printf(wwlog.DEBUG, "RUNNING: %s\n", cmd) - err = exec.Command("/bin/sh", "-c", cmd).Run() - if err != nil { - wwlog.Printf(wwlog.ERROR, "Could not generate system image overlay: %s\n", err) - continue - } - wwlog.Printf(wwlog.INFO, "%-35s: Done\n", node.Fqdn) - - wwlog.Printf(wwlog.DEBUG, "Removing temporary directory: %s\n", tmpDir) - os.RemoveAll(tmpDir) - } - } - - wwlog.SetIndent(0) - return nil -} diff --git a/internal/app/wwctl/build/vnfs/containerdir.go b/internal/app/wwctl/build/vnfs/containerdir.go deleted file mode 100644 index 92d433a6..00000000 --- a/internal/app/wwctl/build/vnfs/containerdir.go +++ /dev/null @@ -1,65 +0,0 @@ -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" - "os" - "path" -) - -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()) - return - } - - wwlog.Printf(wwlog.DEBUG, "Checking if there have been any updates to the VNFS directory\n") - 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(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, "Making the directory: %s\n", path.Dir(config.VnfsChroot(v.NameClean()))) - err = os.MkdirAll(path.Dir(config.VnfsChroot(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(), config.VnfsImage(v.NameClean())) - err = buildVnfs(v.Source(), config.VnfsImage(v.NameClean())) - if err != nil { - fmt.Printf("ERROR: %s\n", err) - os.Exit(1) - } - - // 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 { - wwlog.Printf(wwlog.ERROR, "Could not create symlink for Chroot: %s\n", err) - os.Exit(1) - } - err = os.Rename(config.VnfsChroot(v.NameClean())+"-link", config.VnfsChroot(v.NameClean())) - if err != nil { - wwlog.Printf(wwlog.ERROR, "Could not rename link: %s\n", err) - os.Exit(1) - } - - wwlog.Printf(wwlog.INFO, "%-35s: Done\n", v.Name()) - -} diff --git a/internal/app/wwctl/build/vnfs/docker.go b/internal/app/wwctl/build/vnfs/docker.go deleted file mode 100644 index 84ba9150..00000000 --- a/internal/app/wwctl/build/vnfs/docker.go +++ /dev/null @@ -1,102 +0,0 @@ -package vnfs - -import ( - "context" - "fmt" - "github.com/hpcng/warewulf/internal/pkg/config" - "github.com/hpcng/warewulf/internal/pkg/oci" - "github.com/hpcng/warewulf/internal/pkg/vnfs" - "github.com/hpcng/warewulf/internal/pkg/wwlog" - "os" - "path" -) - - -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 { - fmt.Printf("ERROR: %s\n", err) - os.Exit(1) - } - - wwlog.Printf(wwlog.VERBOSE, "Downloading OCI container layers\n") - sourcePath, err := c.Pull(context.Background(), v.Source(), nil) - if err != nil { - fmt.Printf("ERROR: %s\n", err) - os.Exit(1) - } - - hashDestination := VnfsHashDir + path.Base(sourcePath) - - 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()) - return - } - } - - err = os.MkdirAll(VnfsHashDir, 0755) - if err != nil { - fmt.Printf("ERROR: %s\n", err) - return - } - 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(config.VnfsChroot(v.NameClean())), 0755) - if err != nil { - fmt.Printf("ERROR: %s\n", err) - return - } - - wwlog.Printf(wwlog.VERBOSE, "Building bootable VNFS image\n") - - err = buildVnfs(sourcePath, hashDestination) - if err != nil { - fmt.Printf("ERROR: %s\n", err) - os.Exit(1) - } - - wwlog.Printf(wwlog.VERBOSE, "Finalizing Build\n") - - // 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, "Could not create symlink for Image: %s\n", err) - os.Exit(1) - } - err = os.Rename(config.VnfsImage(v.NameClean())+"-link", config.VnfsImage(v.NameClean())) - if err != nil { - wwlog.Printf(wwlog.ERROR, "Could not rename link: %s\n", err) - os.Exit(1) - } - - // 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, "Could not create symlink for Chroot: %s\n", err) - os.Exit(1) - } - err = os.Rename(config.VnfsChroot(v.NameClean())+"-link", config.VnfsChroot(v.NameClean())) - if err != nil { - wwlog.Printf(wwlog.ERROR, "Could not rename link: %s\n", err) - os.Exit(1) - } - - - wwlog.Printf(wwlog.INFO, "%-35s: Done\n", v.Name()) - - return -} - diff --git a/internal/app/wwctl/build/vnfs/util.go b/internal/app/wwctl/build/vnfs/util.go deleted file mode 100644 index 91d26a39..00000000 --- a/internal/app/wwctl/build/vnfs/util.go +++ /dev/null @@ -1,14 +0,0 @@ -package vnfs - -import ( - "fmt" - "os/exec" -) - -func buildVnfs(source string, dest string) error { - cmd := fmt.Sprintf("cd %s; find . | cpio --quiet -o -H newc | gzip -c > \"%s\"", source, dest) - - err := exec.Command("/bin/sh", "-c", cmd).Run() - - return err -} diff --git a/internal/app/wwctl/build/vnfs/vnfs.go b/internal/app/wwctl/build/vnfs/vnfs.go deleted file mode 100644 index e3f2dc4d..00000000 --- a/internal/app/wwctl/build/vnfs/vnfs.go +++ /dev/null @@ -1,47 +0,0 @@ -package vnfs - -import ( - "strings" - - "github.com/hpcng/warewulf/internal/pkg/assets" - "github.com/hpcng/warewulf/internal/pkg/vnfs" - "github.com/hpcng/warewulf/internal/pkg/wwlog" -) - -var buildForce bool - -func Build(nodeList []assets.NodeInfo, force bool) error { - set := make(map[string]int) - - wwlog.Printf(wwlog.INFO, "Building and Importing VNFS Images:\n") - wwlog.SetIndent(4) - - buildForce = force - - for _, node := range nodeList { - if node.Vnfs != "" { - set[node.Vnfs]++ - wwlog.Printf(wwlog.DEBUG, "Node '%s' has VNFS '%s'\n", node.Fqdn, node.Vnfs) - } - } - - for uri := range set { - v := vnfs.New(uri) - wwlog.Printf(wwlog.VERBOSE, "VNFS found: %s (nodes: %d)\n", uri, set[uri]) - if strings.HasPrefix(uri, "/") { - if strings.HasSuffix(uri, "tar.gz") { - //wwlog.Printf(wwlog.WARN, "Building VNFS from local tarball: %s\n", uri) - wwlog.Printf(wwlog.WARN, "Building VNFS from local tarball is not supported yet: %s\n", uri) - - } else { - BuildContainerdir(v) - } - } else { - BuildDocker(v) - } - } - - wwlog.SetIndent(0) - - return nil -} diff --git a/internal/app/wwctl/overlay/show/main.go b/internal/app/wwctl/overlay/show/main.go new file mode 100644 index 00000000..d75485e1 --- /dev/null +++ b/internal/app/wwctl/overlay/show/main.go @@ -0,0 +1,47 @@ +package show + +import ( + "fmt" + "github.com/hpcng/warewulf/internal/pkg/config" + "github.com/hpcng/warewulf/internal/pkg/util" + "github.com/hpcng/warewulf/internal/pkg/wwlog" + "github.com/spf13/cobra" + "io/ioutil" + "os" + "path" +) + +func CobraRunE(cmd *cobra.Command, args []string) error { + config := config.New() + var overlaySourceDir string + overlayName := args[0] + fileName := args[1] + + if SystemOverlay == true { + overlaySourceDir = config.SystemOverlaySource(overlayName) + } else { + overlaySourceDir = config.RuntimeOverlaySource(overlayName) + } + + if util.IsDir(overlaySourceDir) == false { + wwlog.Printf(wwlog.ERROR, "Overlay does not exist: %s\n", overlayName) + os.Exit(1) + } + + overlayFile := path.Join(overlaySourceDir, fileName) + + if util.IsFile(overlayFile) == false { + wwlog.Printf(wwlog.ERROR, "File does not exist within overlay: %s:%s\n", overlayName, fileName) + os.Exit(1) + } + + f, err := ioutil.ReadFile(overlayFile) + if err != nil { + wwlog.Printf(wwlog.ERROR, "Could not read file: %s\n", err) + os.Exit(1) + } + + fmt.Print(string(f)) + + return nil +} \ No newline at end of file diff --git a/internal/app/wwctl/overlay/show/root.go b/internal/app/wwctl/overlay/show/root.go index edf55abd..ab13c82e 100644 --- a/internal/app/wwctl/overlay/show/root.go +++ b/internal/app/wwctl/overlay/show/root.go @@ -1,7 +1,6 @@ package show import ( - "fmt" "github.com/spf13/cobra" ) @@ -11,21 +10,17 @@ var ( Short: "Show Warewulf Overlay objects", Long: "Warewulf show overlay objects", RunE: CobraRunE, + Aliases: []string{"cat"}, + Args: cobra.ExactArgs(2), } - + SystemOverlay bool ) func init() { - + baseCmd.PersistentFlags().BoolVarP(&SystemOverlay, "system", "s", false, "Show System Overlays as well") } // GetRootCommand returns the root cobra.Command for the application. func GetCommand() *cobra.Command { return baseCmd -} - - -func CobraRunE(cmd *cobra.Command, args []string) error { - fmt.Printf("Show: Hello World\n") - return nil } \ No newline at end of file diff --git a/internal/pkg/overlay/overlay.go b/internal/pkg/overlay/overlay.go index 409842c5..3e5a9721 100644 --- a/internal/pkg/overlay/overlay.go +++ b/internal/pkg/overlay/overlay.go @@ -3,14 +3,13 @@ package overlay import ( "github.com/hpcng/warewulf/internal/pkg/config" "github.com/hpcng/warewulf/internal/pkg/util" - "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/hpcng/warewulf/internal/pkg/vnfs" + "github.com/hpcng/warewulf/internal/pkg/wwlog" "io/ioutil" "path" "strings" ) - func templateFileInclude(path string) string { wwlog.Printf(wwlog.DEBUG, "Including file into template: %s\n", path) content, err := ioutil.ReadFile(path)