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

@@ -11,36 +11,43 @@ import (
"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 {
var overlaySourceDir string
overlayName := args[0]
fileName := args[1]
var uid int
var gid int
var err error
uid, err = strconv.Atoi(args[2])
overlayKind := args[0]
overlayName := args[1]
fileName := args[2]
if overlayKind != "system" && overlayKind != "runtime" {
return errors.New("overlay kind must be of type 'system' or 'runtime'")
}
uid, err = strconv.Atoi(args[3])
if err != nil {
wwlog.Printf(wwlog.ERROR, "UID is not an integer: %s\n", args[2])
wwlog.Printf(wwlog.ERROR, "UID is not an integer: %s\n", args[3])
os.Exit(1)
}
if len(args) > 3 {
gid, err = strconv.Atoi(args[3])
gid, err = strconv.Atoi(args[4])
if err != nil {
wwlog.Printf(wwlog.ERROR, "GID is not an integer: %s\n", args[3])
wwlog.Printf(wwlog.ERROR, "GID is not an integer: %s\n", args[4])
os.Exit(1)
}
} else {
gid = 0
}
if SystemOverlay {
if overlayKind == "system" {
overlaySourceDir = config.SystemOverlaySource(overlayName)
} else {
} else if overlayKind == "runtime" {
overlaySourceDir = config.RuntimeOverlaySource(overlayName)
}
@@ -78,17 +85,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,19 +4,17 @@ import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "chown [flags] <overlay> <path> <UID> [<GID>]",
Use: "chown [flags] <overlay kind> <overlay name> <path> <UID> [<GID>]",
Short: "Change file ownership within an overlay",
Long: "This command will allow you to change the ownership of a file within an\n" +
"overlay.",
RunE: CobraRunE,
Args: cobra.RangeArgs(3, 4),
Args: cobra.RangeArgs(4, 5),
}
SystemOverlay bool
NoOverlayUpdate bool
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&SystemOverlay, "system", "s", false, "Show System Overlays as well")
baseCmd.PersistentFlags().BoolVarP(&NoOverlayUpdate, "noupdate", "n", false, "Don't update overlays")
}