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

@@ -6,12 +6,20 @@ import (
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/overlay"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
var updateNodes []node.NodeInfo
overlayKind := args[0]
overlayName := args[1]
if overlayKind != "system" && overlayKind != "runtime" {
return errors.New("overlay kind must be of type 'system' or 'runtime'")
}
n, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err)
@@ -26,9 +34,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
for _, node := range nodes {
if SystemOverlay && node.SystemOverlay.Get() == args[0] {
if overlayKind == "system" && node.SystemOverlay.Get() == overlayName {
updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay.Get() == args[0] {
} else if overlayKind == "runtime" && node.RuntimeOverlay.Get() == overlayName {
updateNodes = append(updateNodes, node)
}
}
@@ -42,7 +50,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
wwlog.Printf(wwlog.DEBUG, "Checking on system overlay update\n")
if SystemOverlay || BuildAll {
if overlayKind == "system" || BuildAll {
wwlog.Printf(wwlog.INFO, "Updating System Overlays...\n")
err := overlay.BuildSystemOverlay(updateNodes)
if err != nil {
@@ -50,8 +58,8 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
}
wwlog.Printf(wwlog.DEBUG, "Checking on system overlay update\n")
if !SystemOverlay || BuildAll {
wwlog.Printf(wwlog.DEBUG, "Checking on runtime overlay update\n")
if overlayKind == "runtime" || BuildAll {
wwlog.Printf(wwlog.INFO, "Updating Runtime Overlays...\n")
err := overlay.BuildRuntimeOverlay(updateNodes)
if err != nil {

View File

@@ -4,19 +4,17 @@ import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "build [flags] <overlay name>",
Use: "build [flags] <overlay kind> <overlay name>",
Short: "(Re)build an overlay",
Long: "This command will build a system or runtime overlay.",
RunE: CobraRunE,
Args: cobra.ExactArgs(2),
}
SystemOverlay bool
BuildAll bool
BuildAll bool
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&SystemOverlay, "system", "s", false, "Show System Overlays as well")
baseCmd.PersistentFlags().BoolVarP(&BuildAll, "all", "a", false, "Build all overlays (runtime and system)")
}
// GetRootCommand returns the root cobra.Command for the application.

View File

@@ -10,23 +10,30 @@ 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 {
var overlaySourceDir string
overlayName := args[0]
fileName := args[1]
permissionMode, err := strconv.ParseInt(args[2], 8, 32)
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'")
}
permissionMode, err := strconv.ParseInt(args[3], 8, 32)
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not convert requested mode: %s\n", err)
os.Exit(1)
}
if SystemOverlay {
if overlayKind == "system" {
overlaySourceDir = config.SystemOverlaySource(overlayName)
} else {
} else if overlayKind == "runtime" {
overlaySourceDir = config.RuntimeOverlaySource(overlayName)
}
@@ -64,17 +71,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: "chmod [flags] <overlay> <path> <mode>",
Use: "chmod [flags] <overlay kind> <overlay name> <path> <mode>",
Short: "Change file permissions within an overlay",
Long: "This command will allow you to change the permissions of a file within an\n" +
"overlay.",
RunE: CobraRunE,
Args: cobra.ExactArgs(3),
Args: cobra.ExactArgs(4),
}
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")
}

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")
}

View File

@@ -6,30 +6,33 @@ import (
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/overlay"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
//nolint:errcheck
cmd.Help()
os.Exit(1)
overlayKind := args[0]
overlayName := args[1]
if overlayKind != "system" && overlayKind != "runtime" {
return errors.New("overlay kind must be of type 'system' or 'runtime'")
}
if SystemOverlay {
err := overlay.SystemOverlayInit(args[0])
if overlayKind == "system" {
err := overlay.SystemOverlayInit(overlayName)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
wwlog.Printf(wwlog.INFO, "Created new system overlay: %s\n", args[0])
wwlog.Printf(wwlog.INFO, "Created new system overlay: %s\n", overlayName)
} else {
err := overlay.RuntimeOverlayInit(args[0])
err := overlay.RuntimeOverlayInit(overlayName)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
wwlog.Printf(wwlog.INFO, "Created new runtime overlay: %s\n", args[0])
wwlog.Printf(wwlog.INFO, "Created new runtime overlay: %s\n", overlayName)
}
if !NoOverlayUpdate {
@@ -48,17 +51,17 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
var updateNodes []node.NodeInfo
for _, node := range nodes {
if SystemOverlay && node.SystemOverlay.Get() == args[0] {
if overlayKind == "system" && node.SystemOverlay.Get() == overlayName {
updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay.Get() == args[0] {
} 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

@@ -6,18 +6,16 @@ import (
var (
baseCmd = &cobra.Command{
Use: "create [flags] <overlay name>",
Use: "create [flags] <overlay kind> <overlay name>",
Short: "Initialize a new Overlay",
Long: "This command will create a new empty overlay.",
RunE: CobraRunE,
Args: cobra.ExactArgs(1),
Args: cobra.ExactArgs(2),
}
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")
}

View File

@@ -10,88 +10,94 @@ 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 {
var overlayPath string
var fileName string
if SystemOverlay {
overlayPath = config.SystemOverlaySource(args[0])
} else {
overlayPath = config.RuntimeOverlaySource(args[0])
overlayKind := args[0]
overlayName := args[1]
if len(args) == 3 {
fileName = args[2]
}
if overlayKind != "system" && overlayKind != "runtime" {
return errors.New("overlay kind must be of type 'system' or 'runtime'")
}
if overlayKind == "system" {
overlayPath = config.SystemOverlaySource(overlayName)
} else if overlayKind == "runtime" {
overlayPath = config.RuntimeOverlaySource(overlayName)
}
if overlayPath == "" {
wwlog.Printf(wwlog.ERROR, "Overlay name did not render: '%s'\n", args[0])
wwlog.Printf(wwlog.ERROR, "Overlay name did not resolve: '%s'\n", overlayName)
os.Exit(1)
}
if !util.IsDir(overlayPath) {
wwlog.Printf(wwlog.ERROR, "Overlay name does not exist: '%s'\n", args[0])
wwlog.Printf(wwlog.ERROR, "Overlay does not exist: '%s:%s'\n", overlayKind, overlayName)
os.Exit(1)
}
if len(args) == 1 {
if fileName == "" {
if Force {
err := os.RemoveAll(overlayPath)
if err != nil {
wwlog.Printf(wwlog.ERROR, "Failed deleting overlay: %s\n", args[0])
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
return errors.Wrap(err, "failed deleting overlay")
}
} else {
err := os.Remove(overlayPath)
if err != nil {
wwlog.Printf(wwlog.ERROR, "Failed deleting overlay: %s\n", args[0])
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
return errors.Wrap(err, "failed deleting overlay")
}
}
fmt.Printf("Deleted overlay: %s\n", args[0])
} else if len(args) > 1 {
for i := 1; i < len(args); i++ {
removePath := path.Join(overlayPath, args[i])
} else {
removePath := path.Join(overlayPath, overlayPath)
if !util.IsDir(removePath) && !util.IsFile(removePath) {
wwlog.Printf(wwlog.ERROR, "Path to remove doesn't exist in overlay: %s\n", removePath)
if !util.IsDir(removePath) && !util.IsFile(removePath) {
wwlog.Printf(wwlog.ERROR, "Path to remove doesn't exist in overlay: %s\n", removePath)
os.Exit(1)
}
if Force {
err := os.RemoveAll(removePath)
if err != nil {
wwlog.Printf(wwlog.ERROR, "Failed deleting file from overlay: %s:%s:%s\n", overlayKind, overlayName, overlayPath)
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
if Force {
err := os.RemoveAll(removePath)
if err != nil {
wwlog.Printf(wwlog.ERROR, "Failed deleting file from overlay: %s:%s\n", args[0], args[i])
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
} else {
err := os.Remove(removePath)
if err != nil {
wwlog.Printf(wwlog.ERROR, "Failed deleting overlay: %s:%s\n", args[0], args[i])
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if Parents {
// Cleanup any empty directories left behind...
i := path.Dir(removePath)
for i != overlayPath {
wwlog.Printf(wwlog.DEBUG, "Evaluating directory to remove: %s\n", i)
err := os.Remove(i)
if err != nil {
break
}
wwlog.Printf(wwlog.VERBOSE, "Removed empty directory: %s\n", i)
i = path.Dir(i)
}
} else {
err := os.Remove(removePath)
if err != nil {
wwlog.Printf(wwlog.ERROR, "Failed deleting overlay: %s:%s:%s\n", overlayKind, overlayName, overlayPath)
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
fmt.Printf("Deleted from overlay: %s:%s\n", args[0], args[1])
if Parents {
// Cleanup any empty directories left behind...
i := path.Dir(removePath)
for i != overlayPath {
wwlog.Printf(wwlog.DEBUG, "Evaluating directory to remove: %s\n", i)
err := os.Remove(i)
if err != nil {
break
}
wwlog.Printf(wwlog.VERBOSE, "Removed empty directory: %s\n", i)
i = path.Dir(i)
}
}
fmt.Printf("Deleted from overlay: %s:%s:%s\n", overlayKind, overlayName, overlayPath)
}
if !NoOverlayUpdate {
@@ -110,17 +116,17 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
var updateNodes []node.NodeInfo
for _, node := range nodes {
if SystemOverlay && node.SystemOverlay.Get() == args[0] {
if overlayKind == "system" && node.SystemOverlay.Get() == overlayName {
updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay.Get() == args[0] {
} 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

@@ -6,22 +6,20 @@ import (
var (
baseCmd = &cobra.Command{
Use: "delete [flags] <overlay name> [overlay file]",
Use: "delete [flags] <overlay kind> <overlay name> [overlay file]",
Short: "Delete Warewulf Overlay or files",
Long: "This command will delete files within an overlay or an entire overlay if no\n" +
"files are given to remove (use with caution).",
RunE: CobraRunE,
Args: cobra.MinimumNArgs(1),
Args: cobra.RangeArgs(2, 3),
Aliases: []string{"rm", "del"},
}
SystemOverlay bool
Force bool
Parents bool
NoOverlayUpdate bool
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&SystemOverlay, "system", "s", false, "Show system overlays instead of runtime")
baseCmd.PersistentFlags().BoolVarP(&Force, "force", "f", false, "Force deletion of a non-empty overlay")
baseCmd.PersistentFlags().BoolVarP(&Parents, "parents", "p", false, "Remove empty parent directories")
baseCmd.PersistentFlags().BoolVarP(&NoOverlayUpdate, "noupdate", "n", false, "Don't update overlays")

View File

@@ -11,6 +11,7 @@ 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"
)
@@ -18,22 +19,30 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
editor := os.Getenv("EDITOR")
var overlaySourceDir string
if editor == "" {
editor = "vi"
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'")
}
if SystemOverlay {
overlaySourceDir = config.SystemOverlaySource(args[0])
} else {
overlaySourceDir = config.RuntimeOverlaySource(args[0])
if editor == "" {
editor = "/bin/vi"
}
if overlayKind == "system" {
overlaySourceDir = config.SystemOverlaySource(overlayName)
} else if overlayKind == "runtime" {
overlaySourceDir = config.RuntimeOverlaySource(overlayName)
}
if !util.IsDir(overlaySourceDir) {
wwlog.Printf(wwlog.ERROR, "Overlay does not exist: %s\n", args[0])
wwlog.Printf(wwlog.ERROR, "Overlay does not exist: %s:%s\n", overlayKind, overlayName)
os.Exit(1)
}
overlayFile := path.Join(overlaySourceDir, args[1])
overlayFile := path.Join(overlaySourceDir, fileName)
wwlog.Printf(wwlog.DEBUG, "Will edit overlay file: %s\n", overlayFile)
@@ -83,7 +92,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Printf(wwlog.ERROR, "Editor process existed with non-zero\n")
os.Exit(1)
}
wwlog.Printf(wwlog.INFO, "Updated: %s %s\n", args[0], args[1])
wwlog.Printf(wwlog.INFO, "Updated: %s:%s:%s\n", overlayKind, overlayName, fileName)
shasum2, err := util.ShaSumFile(overlayFile)
if err != nil {
@@ -111,17 +120,17 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
var updateNodes []node.NodeInfo
for _, node := range nodes {
if SystemOverlay && node.SystemOverlay.Get() == args[0] {
if overlayKind == "system" && node.SystemOverlay.Get() == overlayName {
updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay.Get() == args[0] {
} 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

@@ -6,15 +6,14 @@ import (
var (
baseCmd = &cobra.Command{
Use: "edit [flags] <overlay name> <file path>",
Use: "edit [flags] <overlay kind> <overlay name> <file path>",
Short: "Edit/Create a file within a Warewulf Overlay",
Long: "This command will allow you to edit or create a new file within a given\n" +
"overlay. Note: when creating files ending in a '.ww' suffix this will always be\n" +
"parsed as a Warewulf template file, and the suffix will be removed automatically.",
RunE: CobraRunE,
Args: cobra.ExactArgs(2),
Args: cobra.ExactArgs(3),
}
SystemOverlay bool
ListFiles bool
CreateDirs bool
PermMode int32
@@ -22,7 +21,6 @@ var (
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&SystemOverlay, "system", "s", false, "Show system overlays instead of runtime")
baseCmd.PersistentFlags().BoolVarP(&ListFiles, "files", "f", false, "List files contained within a given overlay")
baseCmd.PersistentFlags().BoolVarP(&CreateDirs, "parents", "p", false, "Create any necessary parent directories")
baseCmd.PersistentFlags().Int32VarP(&PermMode, "mode", "m", 0755, "Permission mode for directory")

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")
}

View File

@@ -10,6 +10,7 @@ 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"
)
@@ -18,6 +19,17 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
var o []string
var err error
var nodeList []node.NodeInfo
var overlayName string
overlayKind := args[0]
if len(args) > 1 {
overlayName = args[1]
}
if overlayKind != "system" && overlayKind != "runtime" {
return errors.New("overlay kind must be of type 'system' or 'runtime'")
}
n, err := node.New()
if err != nil {
@@ -25,14 +37,14 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
os.Exit(1)
}
if SystemOverlay {
if overlayKind == "system" {
if !ListLong {
fmt.Printf("%-30s %-12s %-12s\n", "SYSTEM OVERLAY NAME", "NODES", "FILES/DIRS")
} else {
fmt.Printf("%-10s %5s %-5s %-18s %s\n", "PERM MODE", "UID", "GID", "SYSTEM-OVERLAY", "FILE PATH")
}
o, err = overlay.FindSystemOverlays()
} else {
} else if overlayKind == "runtime" {
if !ListLong {
fmt.Printf("%-30s %-12s %-12s\n", "RUNTIME OVERLAY NAME", "NODES", "FILES/DIRS")
} else {
@@ -52,11 +64,11 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
for _, node := range nodeList {
if SystemOverlay {
if overlayKind == "system" {
if node.SystemOverlay.Get() != "" {
set[node.SystemOverlay.Get()]++
}
} else {
} else if overlayKind == "runtime" {
if node.RuntimeOverlay.Get() != "" {
set[node.RuntimeOverlay.Get()]++
}
@@ -67,15 +79,13 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
var path string
name := o[overlay]
if len(args) > 0 {
if args[0] != name {
continue
}
if overlayName != "" && overlayName != name {
continue
}
if SystemOverlay {
if overlayKind == "system" {
path = config.SystemOverlaySource(o[overlay])
} else {
} else if overlayKind == "runtime" {
path = config.RuntimeOverlaySource(o[overlay])
}
@@ -116,29 +126,5 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
}
var unconfigured bool
for overlay := range set {
var overlayPath string
if SystemOverlay {
overlayPath = config.SystemOverlaySource(overlay)
} else {
overlayPath = config.SystemOverlaySource(overlay)
}
if !util.IsDir(overlayPath) {
fmt.Printf("%-30s %-12d 0\n", "("+overlay+")", set[overlay])
unconfigured = true
}
}
if unconfigured {
fmt.Printf("\n")
wwlog.Printf(wwlog.WARN, "There are unconfigured overlays present, run the following command to\n")
wwlog.Printf(wwlog.WARN, "create a new overlay:\n")
wwlog.Printf(wwlog.WARN, "\n")
wwlog.Printf(wwlog.WARN, " $ sudo wwctl overlay create ...\n")
}
return nil
}

View File

@@ -6,20 +6,18 @@ import (
var (
baseCmd = &cobra.Command{
Use: "list [flags] [overlay name]",
Use: "list [flags] <overlay kind> <overlay name>",
Short: "List Warewulf Overlays and files",
Long: "This command will show you information about Warewulf overlays and the\n" +
"files contained within.",
RunE: CobraRunE,
Aliases: []string{"ls"},
}
SystemOverlay bool
ListContents bool
ListLong bool
ListContents bool
ListLong bool
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&SystemOverlay, "system", "s", false, "Show system overlays instead of runtime")
baseCmd.PersistentFlags().BoolVarP(&ListContents, "all", "a", false, "List the contents of overlays")
baseCmd.PersistentFlags().BoolVarP(&ListLong, "long", "l", false, "List 'long' of all overlay contents")

View File

@@ -10,26 +10,35 @@ 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 {
var overlaySourceDir string
if SystemOverlay {
overlaySourceDir = config.SystemOverlaySource(args[0])
} else {
overlaySourceDir = config.RuntimeOverlaySource(args[0])
overlayKind := args[0]
overlayName := args[1]
dirName := args[2]
if overlayKind != "system" && overlayKind != "runtime" {
return errors.New("overlay kind must be of type 'system' or 'runtime'")
}
if overlayKind == "system" {
overlaySourceDir = config.SystemOverlaySource(overlayName)
} else if overlayKind == "runtime" {
overlaySourceDir = config.RuntimeOverlaySource(overlayName)
}
if !util.IsDir(overlaySourceDir) {
wwlog.Printf(wwlog.ERROR, "Overlay does not exist: %s\n", args[0])
wwlog.Printf(wwlog.ERROR, "Overlay does not exist: %s:%s\n", overlayKind, overlayName)
os.Exit(1)
}
overlayDir := path.Join(overlaySourceDir, args[1])
overlayDir := path.Join(overlaySourceDir, dirName)
wwlog.Printf(wwlog.DEBUG, "Will create directory in overlay: %s:%s\n", args[0], overlayDir)
wwlog.Printf(wwlog.DEBUG, "Will create directory in overlay: %s:%s:%s\n", overlayKind, overlayName, dirName)
err := os.MkdirAll(overlayDir, os.FileMode(PermMode))
if err != nil {
@@ -37,7 +46,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
os.Exit(1)
}
fmt.Printf("Created directory within overlay: %s:%s\n", args[0], args[1])
fmt.Printf("Created directory within overlay: %s:%s:%s\n", overlayKind, overlayName, overlayDir)
if !NoOverlayUpdate {
n, err := node.New()
@@ -55,17 +64,17 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
var updateNodes []node.NodeInfo
for _, node := range nodes {
if SystemOverlay && node.SystemOverlay.Get() == args[0] {
if overlayKind == "system" && node.SystemOverlay.Get() == overlayName {
updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay.Get() == args[0] {
} 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

@@ -6,19 +6,17 @@ import (
var (
baseCmd = &cobra.Command{
Use: "mkdir [flags] <overlay name> <directory path>",
Use: "mkdir [flags] <overlay kind> <overlay name> <directory path>",
Short: "Create a new directory within an Overlay",
Long: "This command will allow you to create a new file within a given Warewulf overlay.",
RunE: CobraRunE,
Args: cobra.MinimumNArgs(2),
Args: cobra.MinimumNArgs(3),
}
SystemOverlay bool
PermMode int32
NoOverlayUpdate bool
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&SystemOverlay, "system", "s", false, "Show System Overlays as well")
baseCmd.PersistentFlags().Int32VarP(&PermMode, "mode", "m", 0755, "Permission mode for directory")
baseCmd.PersistentFlags().BoolVarP(&NoOverlayUpdate, "noupdate", "n", false, "Don't update overlays")
}

View File

@@ -9,17 +9,24 @@ import (
"github.com/hpcng/warewulf/internal/pkg/config"
"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]
if SystemOverlay {
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'")
}
if overlayKind == "system" {
overlaySourceDir = config.SystemOverlaySource(overlayName)
} else {
} else if overlayKind == "runtime" {
overlaySourceDir = config.RuntimeOverlaySource(overlayName)
}

View File

@@ -6,19 +6,17 @@ import (
var (
baseCmd = &cobra.Command{
Use: "show [flags] <overlay name> <overlay file>",
Use: "show [flags] <overlay kind> <overlay name> <overlay file>",
Short: "Show (cat) a file within a Warewulf Overlay",
Long: "This command will output the contents of a file within a given\n" +
"Warewulf overlay.",
RunE: CobraRunE,
Aliases: []string{"cat"},
Args: cobra.ExactArgs(2),
Args: cobra.ExactArgs(3),
}
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.

View File

@@ -298,7 +298,7 @@ func buildOverlay(nodeList []node.NodeInfo, overlayType string) error {
wwlog.Printf(wwlog.VERBOSE, "Could not locate PIGZ, using GZIP\n")
compressor = "gzip"
} else {
wwlog.Printf(wwlog.VERBOSE, "Using PIGZ to compress the container: %s\n", compressor)
wwlog.Printf(wwlog.VERBOSE, "Using PIGZ to compress the overlay: %s\n", compressor)
}
cmd := fmt.Sprintf("cd \"%s\"; find . | cpio --quiet -o -H newc | %s -c > \"%s\"", tmpDir, compressor, OverlayFile)