Rename "container" to "image"
- Updated `wwctl upgrade` to handle updates - Maintained `.Container` and `.ContainerName` in tstruct - Added `ContainerName()` methods to node and profile objects - Added `--container`, `-C` aliases to wwctl commands (`<node|profile> <add|set>`) - Added `wwctl container` alias - Added support for `container_exit.sh` if `image_exit.sh` is not found Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
60
internal/app/wwctl/image/kernels/main.go
Normal file
60
internal/app/wwctl/image/kernels/main.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package kernels
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/warewulf/warewulf/internal/app/wwctl/table"
|
||||
"github.com/warewulf/warewulf/internal/pkg/image"
|
||||
"github.com/warewulf/warewulf/internal/pkg/kernel"
|
||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||
)
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
nodesYaml, err := node.New()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
nodes, err := nodesYaml.FindAllNodes()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
kernelNodes := make(map[kernel.Kernel]int)
|
||||
for _, node := range nodes {
|
||||
kernel_ := kernel.FromNode(&node)
|
||||
if kernel_ != nil {
|
||||
kernelNodes[*kernel_]++
|
||||
}
|
||||
}
|
||||
|
||||
var sources []string
|
||||
if len(args) == 0 {
|
||||
if sources_, err := image.ListSources(); err == nil {
|
||||
sources = sources_
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
sources = args
|
||||
}
|
||||
|
||||
t := table.New(cmd.OutOrStdout())
|
||||
t.AddHeader("Image", "Kernel", "Version", "Default", "Nodes")
|
||||
for _, source := range sources {
|
||||
imageKernels := kernel.FindKernels(source)
|
||||
defaultKernel := imageKernels.Default()
|
||||
for _, kernel_ := range imageKernels {
|
||||
isDefault := defaultKernel != nil && defaultKernel == kernel_
|
||||
defaultStr := strconv.FormatBool(isDefault)
|
||||
nodeCount := kernelNodes[*kernel_]
|
||||
if isDefault {
|
||||
nodeCount = nodeCount + kernelNodes[kernel.Kernel{ImageName: source, Path: ""}]
|
||||
}
|
||||
t.AddLine(table.Prep([]string{source, kernel_.Path, kernel_.Version(), defaultStr, strconv.Itoa(nodeCount)})...)
|
||||
}
|
||||
}
|
||||
t.Print()
|
||||
|
||||
return nil
|
||||
}
|
||||
106
internal/app/wwctl/image/kernels/main_test.go
Normal file
106
internal/app/wwctl/image/kernels/main_test.go
Normal file
@@ -0,0 +1,106 @@
|
||||
package kernels
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/warewulf/warewulf/internal/pkg/testenv"
|
||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||
)
|
||||
|
||||
func Test_List(t *testing.T) {
|
||||
tests := map[string]struct {
|
||||
files map[string][]string
|
||||
args []string
|
||||
stdout string
|
||||
}{
|
||||
"default": {
|
||||
files: map[string][]string{},
|
||||
args: []string{},
|
||||
stdout: `
|
||||
Image Kernel Version Default Nodes
|
||||
----- ------ ------- ------- -----
|
||||
`,
|
||||
},
|
||||
"list": {
|
||||
files: map[string][]string{
|
||||
"image1": []string{
|
||||
"/boot/vmlinuz-5.14.0-427.18.1.el9_4.x86_64",
|
||||
"/boot/vmlinuz-5.14.0-427.24.1.el9_4.x86_64",
|
||||
"/boot/vmlinuz-4.14.0-427.18.1.el8_4.x86_64",
|
||||
},
|
||||
"image2": []string{
|
||||
"/boot/vmlinuz-0-rescue-eb46964329b146e39518c625feab3ea0",
|
||||
"/boot/vmlinuz-5.14.0-362.24.1.el9_3.aarch64",
|
||||
"/boot/vmlinuz-5.14.0-427.31.1.el9_4.aarch64+debug",
|
||||
"/boot/vmlinuz-5.14.0-284.30.1.el9_2.aarch64",
|
||||
"/boot/vmlinuz-5.14.0-427.31.1.el9_4.aarch64",
|
||||
},
|
||||
},
|
||||
args: []string{},
|
||||
stdout: `
|
||||
Image Kernel Version Default Nodes
|
||||
----- ------ ------- ------- -----
|
||||
image1 /boot/vmlinuz-4.14.0-427.18.1.el8_4.x86_64 4.14.0-427.18.1 false 0
|
||||
image1 /boot/vmlinuz-5.14.0-427.18.1.el9_4.x86_64 5.14.0-427.18.1 false 0
|
||||
image1 /boot/vmlinuz-5.14.0-427.24.1.el9_4.x86_64 5.14.0-427.24.1 true 0
|
||||
image2 /boot/vmlinuz-0-rescue-eb46964329b146e39518c625feab3ea0 -- false 0
|
||||
image2 /boot/vmlinuz-5.14.0-284.30.1.el9_2.aarch64 5.14.0-284.30.1 false 0
|
||||
image2 /boot/vmlinuz-5.14.0-362.24.1.el9_3.aarch64 5.14.0-362.24.1 false 0
|
||||
image2 /boot/vmlinuz-5.14.0-427.31.1.el9_4.aarch64 5.14.0-427.31.1 true 0
|
||||
image2 /boot/vmlinuz-5.14.0-427.31.1.el9_4.aarch64+debug 5.14.0-427.31.1 false 0
|
||||
`,
|
||||
},
|
||||
"single image": {
|
||||
files: map[string][]string{
|
||||
"image1": []string{
|
||||
"/boot/vmlinuz-5.14.0-427.18.1.el9_4.x86_64",
|
||||
"/boot/vmlinuz-5.14.0-427.24.1.el9_4.x86_64",
|
||||
"/boot/vmlinuz-4.14.0-427.18.1.el8_4.x86_64",
|
||||
},
|
||||
"image2": []string{
|
||||
"/boot/vmlinuz-0-rescue-eb46964329b146e39518c625feab3ea0",
|
||||
"/boot/vmlinuz-5.14.0-362.24.1.el9_3.aarch64",
|
||||
"/boot/vmlinuz-5.14.0-427.31.1.el9_4.aarch64+debug",
|
||||
"/boot/vmlinuz-5.14.0-284.30.1.el9_2.aarch64",
|
||||
"/boot/vmlinuz-5.14.0-427.31.1.el9_4.aarch64",
|
||||
},
|
||||
},
|
||||
args: []string{"image2"},
|
||||
stdout: `
|
||||
Image Kernel Version Default Nodes
|
||||
----- ------ ------- ------- -----
|
||||
image2 /boot/vmlinuz-0-rescue-eb46964329b146e39518c625feab3ea0 -- false 0
|
||||
image2 /boot/vmlinuz-5.14.0-284.30.1.el9_2.aarch64 5.14.0-284.30.1 false 0
|
||||
image2 /boot/vmlinuz-5.14.0-362.24.1.el9_3.aarch64 5.14.0-362.24.1 false 0
|
||||
image2 /boot/vmlinuz-5.14.0-427.31.1.el9_4.aarch64 5.14.0-427.31.1 true 0
|
||||
image2 /boot/vmlinuz-5.14.0-427.31.1.el9_4.aarch64+debug 5.14.0-427.31.1 false 0
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tt := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
env := testenv.New(t)
|
||||
defer env.RemoveAll()
|
||||
for image, files := range tt.files {
|
||||
rootfs := filepath.Join(filepath.Join("/var/lib/warewulf/chroots", image), "rootfs")
|
||||
for _, file := range files {
|
||||
env.CreateFile(filepath.Join(rootfs, file))
|
||||
}
|
||||
}
|
||||
buf := new(bytes.Buffer)
|
||||
baseCmd := GetCommand()
|
||||
baseCmd.SetArgs(tt.args)
|
||||
baseCmd.SetOut(buf)
|
||||
baseCmd.SetErr(buf)
|
||||
wwlog.SetLogWriter(buf)
|
||||
err := baseCmd.Execute()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, strings.TrimSpace(tt.stdout), strings.TrimSpace(buf.String()))
|
||||
})
|
||||
}
|
||||
}
|
||||
24
internal/app/wwctl/image/kernels/root.go
Normal file
24
internal/app/wwctl/image/kernels/root.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package kernels
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/warewulf/warewulf/internal/app/wwctl/completions"
|
||||
)
|
||||
|
||||
var (
|
||||
baseCmd = &cobra.Command{
|
||||
DisableFlagsInUseLine: true,
|
||||
Use: "kernels [OPTIONS]",
|
||||
Short: "List available image kernels",
|
||||
Long: "This command lists the kernels that are available in the imported images.",
|
||||
RunE: CobraRunE,
|
||||
Aliases: []string{"kernel"},
|
||||
ValidArgsFunction: completions.Images,
|
||||
}
|
||||
)
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
}
|
||||
Reference in New Issue
Block a user