Last bit of updates for basic overlay support
This commit is contained in:
78
internal/app/wwctl/overlay/chmod/main.go
Normal file
78
internal/app/wwctl/overlay/chmod/main.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package chmod
|
||||
|
||||
import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/assets"
|
||||
"github.com/hpcng/warewulf/internal/pkg/config"
|
||||
"github.com/hpcng/warewulf/internal/pkg/overlay"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
config := config.New()
|
||||
var overlaySourceDir string
|
||||
overlayName := args[0]
|
||||
fileName := args[2]
|
||||
|
||||
permissionMode, err := strconv.ParseInt(args[1], 8, 32)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "Could not convert requested mode: %s\n", err)
|
||||
os.Exit(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)
|
||||
}
|
||||
|
||||
err = os.Chmod(overlayFile, os.FileMode(permissionMode))
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "Could not set permission: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if NoOverlayUpdate == false {
|
||||
nodes, err := assets.FindAllNodes()
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
var updateNodes []assets.NodeInfo
|
||||
|
||||
for _, node := range nodes {
|
||||
if SystemOverlay == true && node.SystemOverlay == overlayName {
|
||||
updateNodes = append(updateNodes, node)
|
||||
} else if node.RuntimeOverlay == overlayName {
|
||||
updateNodes = append(updateNodes, node)
|
||||
}
|
||||
}
|
||||
|
||||
if SystemOverlay == true {
|
||||
wwlog.Printf(wwlog.INFO, "Updating System Overlays...\n")
|
||||
return overlay.SystemBuild(updateNodes, true)
|
||||
} else {
|
||||
wwlog.Printf(wwlog.INFO, "Updating Runtime Overlays...\n")
|
||||
return overlay.RuntimeBuild(updateNodes, true)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
27
internal/app/wwctl/overlay/chmod/root.go
Normal file
27
internal/app/wwctl/overlay/chmod/root.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package chmod
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
var (
|
||||
baseCmd = &cobra.Command{
|
||||
Use: "chmod [overlay name] [numeric mode] [file path]",
|
||||
Short: "Change permissions within an overlay",
|
||||
Long: "Change permissions within an overlay",
|
||||
RunE: CobraRunE,
|
||||
Args: cobra.ExactArgs(3),
|
||||
|
||||
}
|
||||
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")
|
||||
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
}
|
||||
Reference in New Issue
Block a user