refactor to overlay info

This commit is contained in:
Christian Goll
2025-11-12 19:30:24 +01:00
committed by Jonathon Anderson
parent d1d398d2ff
commit 983a359c00
7 changed files with 56 additions and 22 deletions

View File

@@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- `wwclient.aarch64` overlay always provides an aarch64 wwclient executable. - `wwclient.aarch64` overlay always provides an aarch64 wwclient executable.
- `wwclient.x86_64` overlay always provides an x86_64 wwclient executable. - `wwclient.x86_64` overlay always provides an x86_64 wwclient executable.
- systemd-networkd overlay with IPv6 support - systemd-networkd overlay with IPv6 support
- `wwctl overlay info` lists the variables used by an overlay template
### Changed ### Changed
@@ -49,7 +50,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added ### Added
- `wwctl overlay show -l` will now also list the used tags in a template
- Initial support for EL10 using `dnsmasq` in place of `dhcpd-server`. #1974 - Initial support for EL10 using `dnsmasq` in place of `dhcpd-server`. #1974
- `make rpm` for local development rpm builds. #1974 - `make rpm` for local development rpm builds. #1974
- `wwclient --once` prompts wwclient to run once. #1226 - `wwclient --once` prompts wwclient to run once. #1226

View File

@@ -1,4 +1,4 @@
package variables package info
import ( import (
"fmt" "fmt"

View File

@@ -1,4 +1,4 @@
package variables package info
import ( import (
"bytes" "bytes"

View File

@@ -1,4 +1,4 @@
package variables package info
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
@@ -7,10 +7,10 @@ import (
var ( var (
baseCmd = &cobra.Command{ baseCmd = &cobra.Command{
Use: "variables [flags] OVERLAY_NAME FILE_PATH", Use: "info [flags] OVERLAY_NAME FILE_PATH",
Short: "Show variables for a template file in an overlay", Short: "Show variables for a template file in an overlay",
Long: "This command will show the variables for a given template file in a given\n" + "overlay.", Long: "This command will show the variables for a given template file in a given\n" + "overlay.",
Aliases: []string{"vars", "tags"}, Aliases: []string{"vars", "tags", "information"},
Args: cobra.ExactArgs(2), Args: cobra.ExactArgs(2),
RunE: CobraRunE, RunE: CobraRunE,
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {

View File

@@ -1,7 +1,9 @@
package list package list
import ( import (
"os"
"strconv" "strconv"
"syscall"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/warewulf/warewulf/internal/app/wwctl/table" "github.com/warewulf/warewulf/internal/app/wwctl/table"
@@ -30,7 +32,11 @@ func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) error {
if vars.ShowPath { if vars.ShowPath {
locationStr = "PATH" locationStr = "PATH"
} }
t.AddHeader("OVERLAY NAME", "FILES/DIRS", locationStr) if vars.ListLong {
t.AddHeader("PERM MODE", "UID", "GID", "OVERLAY", "FILE PATH", locationStr)
} else {
t.AddHeader("OVERLAY NAME", "FILES/DIRS", locationStr)
}
for _, name := range overlays { for _, name := range overlays {
overlay_, err := overlay.Get(name) overlay_, err := overlay.Get(name)
@@ -43,21 +49,39 @@ func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) error {
files := util.FindFiles(overlay_.Rootfs()) files := util.FindFiles(overlay_.Rootfs())
wwlog.Debug("Iterating overlay rootfs: %s", overlay_.Rootfs()) wwlog.Debug("Iterating overlay rootfs: %s", overlay_.Rootfs())
locLine := strconv.FormatBool(overlay_.IsSiteOverlay()) if vars.ListLong {
if vars.ShowPath {
locLine = overlay_.Path()
}
if vars.ListContents || vars.ListLong {
var fileCount int
for file := range files { for file := range files {
t.AddLine(name, files[file], locLine) s, err := os.Stat(overlay_.File(files[file]))
fileCount++ if err != nil {
} wwlog.Warn("%s: %s: %s", name, files[file], err)
if fileCount == 0 { continue
t.AddLine(name, 0, locLine) }
fileMode := s.Mode()
perms := fileMode & os.ModePerm
sys := s.Sys()
locLine := strconv.FormatBool(overlay_.IsSiteOverlay())
if vars.ShowPath {
locLine = overlay_.Path()
}
t.AddLine(perms, sys.(*syscall.Stat_t).Uid, sys.(*syscall.Stat_t).Gid, name, files[file], locLine)
} }
} else { } else {
t.AddLine(name, len(files), locLine) locLine := strconv.FormatBool(overlay_.IsSiteOverlay())
if vars.ShowPath {
locLine = overlay_.Path()
}
if vars.ListContents {
var fileCount int
for file := range files {
t.AddLine(name, files[file], locLine)
fileCount++
}
if fileCount == 0 {
t.AddLine(name, 0, locLine)
}
} else {
t.AddLine(name, len(files), locLine)
}
} }
} }
t.Print() t.Print()

View File

@@ -9,10 +9,10 @@ import (
"github.com/warewulf/warewulf/internal/app/wwctl/overlay/delete" "github.com/warewulf/warewulf/internal/app/wwctl/overlay/delete"
"github.com/warewulf/warewulf/internal/app/wwctl/overlay/edit" "github.com/warewulf/warewulf/internal/app/wwctl/overlay/edit"
"github.com/warewulf/warewulf/internal/app/wwctl/overlay/imprt" "github.com/warewulf/warewulf/internal/app/wwctl/overlay/imprt"
"github.com/warewulf/warewulf/internal/app/wwctl/overlay/info"
"github.com/warewulf/warewulf/internal/app/wwctl/overlay/list" "github.com/warewulf/warewulf/internal/app/wwctl/overlay/list"
"github.com/warewulf/warewulf/internal/app/wwctl/overlay/mkdir" "github.com/warewulf/warewulf/internal/app/wwctl/overlay/mkdir"
"github.com/warewulf/warewulf/internal/app/wwctl/overlay/show" "github.com/warewulf/warewulf/internal/app/wwctl/overlay/show"
"github.com/warewulf/warewulf/internal/app/wwctl/overlay/variables"
) )
var ( var (
@@ -36,7 +36,7 @@ func init() {
baseCmd.AddCommand(imprt.GetCommand()) baseCmd.AddCommand(imprt.GetCommand())
baseCmd.AddCommand(chmod.GetCommand()) baseCmd.AddCommand(chmod.GetCommand())
baseCmd.AddCommand(chown.GetCommand()) baseCmd.AddCommand(chown.GetCommand())
baseCmd.AddCommand(variables.GetCommand()) baseCmd.AddCommand(info.GetCommand())
} }
// GetRootCommand returns the root cobra.Command for the application. // GetRootCommand returns the root cobra.Command for the application.

View File

@@ -330,7 +330,11 @@ func (overlay Overlay) ParseCommentVars(file string) (retMap map[string]string)
re := regexp.MustCompile(`{{\s*/\*\s*(.*?):\s*(.*?)\s*\*/\s*}}`) re := regexp.MustCompile(`{{\s*/\*\s*(.*?):\s*(.*?)\s*\*/\s*}}`)
matches := re.FindAllStringSubmatch(string(content), -1) matches := re.FindAllStringSubmatch(string(content), -1)
wwlog.Debug("matches: %v len(%d:%d)", matches, len(matches), len(matches[0])) if len(matches) > 0 {
wwlog.Debug("matches: %v len(%d:%d)", matches, len(matches), len(matches[0]))
} else {
wwlog.Debug("matches: [] len(0)")
}
for i := range matches { for i := range matches {
if len(matches[i]) > 2 { if len(matches[i]) > 2 {
retMap[matches[i][1]] = matches[i][2] retMap[matches[i][1]] = matches[i][2]
@@ -361,9 +365,15 @@ func walkParseTree(node parse.Node, vars map[string]bool) {
case *parse.RangeNode: case *parse.RangeNode:
walkParseTree(n.Pipe, vars) walkParseTree(n.Pipe, vars)
walkParseTree(n.List, vars) walkParseTree(n.List, vars)
walkParseTree(n.ElseList, vars)
case *parse.WithNode: case *parse.WithNode:
walkParseTree(n.Pipe, vars) walkParseTree(n.Pipe, vars)
walkParseTree(n.List, vars) walkParseTree(n.List, vars)
walkParseTree(n.ElseList, vars)
case *parse.TemplateNode:
walkParseTree(n.Pipe, vars)
case *parse.BreakNode, *parse.ContinueNode:
// No variables to extract
case *parse.PipeNode: case *parse.PipeNode:
if n != nil { if n != nil {
for _, cmd := range n.Cmds { for _, cmd := range n.Cmds {