UI updates to include "overlay kind"

This commit is contained in:
Gregory Kurtzer
2021-09-13 13:28:44 -07:00
parent 5bff8be72e
commit 3137f477bf
21 changed files with 241 additions and 214 deletions

View File

@@ -9,39 +9,44 @@ import (
"github.com/hpcng/warewulf/internal/pkg/overlay"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
overlayName := args[0]
source := args[1]
var dest string
var overlaySource string
if len(args) == 3 {
dest = args[2]
overlayKind := args[0]
overlayName := args[1]
source := args[2]
if overlayKind != "system" && overlayKind != "runtime" {
return errors.New("overlay kind must be of type 'system' or 'runtime'")
}
if len(args) == 4 {
dest = args[3]
} else {
dest = source
}
if SystemOverlay {
wwlog.Printf(wwlog.VERBOSE, "Importing '%s' into system overlay '%s:%s'\n", source, overlayName, dest)
if overlayKind == "system" {
wwlog.Printf(wwlog.VERBOSE, "Copying '%s' into system overlay '%s:%s'\n", source, overlayName, dest)
overlaySource = config.SystemOverlaySource(overlayName)
} else {
wwlog.Printf(wwlog.VERBOSE, "Importing '%s' into runtime overlay '%s:%s'\n", source, overlayName, dest)
} else if overlayKind == "runtime" {
wwlog.Printf(wwlog.VERBOSE, "Copying '%s' into runtime overlay '%s:%s'\n", source, overlayName, dest)
overlaySource = config.RuntimeOverlaySource(overlayName)
}
if !util.IsDir(overlaySource) {
wwlog.Printf(wwlog.ERROR, "Overlay does not exist: %s\n", overlayName)
wwlog.Printf(wwlog.ERROR, "Overlay does not exist: %s:%s\n", overlayKind, overlayName)
os.Exit(1)
}
err := util.CopyFile(source, path.Join(overlaySource, dest))
if err != nil {
wwlog.Printf(wwlog.ERROR, "Failed copying file into overlay sourcedir:\n")
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
return errors.Wrap(err, "could not copy file into overlay")
}
if !NoOverlayUpdate {
@@ -60,17 +65,17 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
var updateNodes []node.NodeInfo
for _, node := range nodes {
if SystemOverlay && node.SystemOverlay.Get() == overlayName {
if overlayKind == "system" && node.SystemOverlay.Get() == overlayName {
updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay.Get() == overlayName {
} else if overlayKind == "runtime" && node.RuntimeOverlay.Get() == overlayName {
updateNodes = append(updateNodes, node)
}
}
if SystemOverlay {
if overlayKind == "system" {
wwlog.Printf(wwlog.INFO, "Updating System Overlays...\n")
return overlay.BuildSystemOverlay(updateNodes)
} else {
} else if overlayKind == "runtime" {
wwlog.Printf(wwlog.INFO, "Updating Runtime Overlays...\n")
return overlay.BuildRuntimeOverlay(updateNodes)
}

View File

@@ -4,20 +4,18 @@ import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "import [flags] <overlay name> <source file> [dest location]",
Use: "import [flags] <overlay kind> <overlay name> <host source> [overlay target]",
Short: "Import a file into a Warewulf Overlay",
Long: "This command will import a file into a given Warewulf overlay.",
RunE: CobraRunE,
Args: cobra.RangeArgs(2, 3),
Args: cobra.RangeArgs(3, 4),
Aliases: []string{"cp"},
}
SystemOverlay bool
PermMode int32
NoOverlayUpdate bool
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&SystemOverlay, "system", "s", false, "Show system overlays instead of runtime")
baseCmd.PersistentFlags().Int32VarP(&PermMode, "mode", "m", 0755, "Permission mode for directory")
baseCmd.PersistentFlags().BoolVarP(&NoOverlayUpdate, "noupdate", "n", false, "Don't update overlays")
}