Restored deleted kernel components for overrides
This commit is contained in:
41
internal/app/wwctl/kernel/delete/main.go
Normal file
41
internal/app/wwctl/kernel/delete/main.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package delete
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/kernel"
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
|
||||
nodeDB, err := node.New()
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "Could not open nodeDB: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
nodes, _ := nodeDB.FindAllNodes()
|
||||
|
||||
ARG_LOOP:
|
||||
for _, arg := range args {
|
||||
for _, n := range nodes {
|
||||
if n.KernelVersion.Get() == arg {
|
||||
wwlog.Printf(wwlog.ERROR, "Kernel is configured for nodes, skipping: %s\n", arg)
|
||||
continue ARG_LOOP
|
||||
}
|
||||
}
|
||||
|
||||
err := kernel.DeleteKernel(arg)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "Could not delete kernel: %s\n", arg)
|
||||
} else {
|
||||
fmt.Printf("Kernel has been deleted: %s\n", arg)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
33
internal/app/wwctl/kernel/delete/root.go
Normal file
33
internal/app/wwctl/kernel/delete/root.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package delete
|
||||
|
||||
import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/kernel"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
baseCmd = &cobra.Command{
|
||||
DisableFlagsInUseLine: true,
|
||||
Use: "delete [OPTIONS] KERNEL [...]",
|
||||
Short: "Delete imported kernels",
|
||||
Long: "This command will delete KERNEL versions that have been imported into Warewulf.",
|
||||
RunE: CobraRunE,
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
if len(args) != 0 {
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
list, _ := kernel.ListKernels()
|
||||
return list, cobra.ShellCompDirectiveNoFileComp
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
}
|
||||
92
internal/app/wwctl/kernel/imprt/main.go
Normal file
92
internal/app/wwctl/kernel/imprt/main.go
Normal file
@@ -0,0 +1,92 @@
|
||||
package imprt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/container"
|
||||
"github.com/hpcng/warewulf/internal/pkg/kernel"
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"github.com/hpcng/warewulf/internal/pkg/warewulfd"
|
||||
"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) == 0 && !OptDetect {
|
||||
wwlog.Printf(wwlog.ERROR, "the '--detect' flag is needed, if no kernel version is suppiled")
|
||||
os.Exit(1)
|
||||
}
|
||||
if OptDetect && (OptRoot == "" || OptContainer == "") {
|
||||
wwlog.Printf(wwlog.ERROR, "the '--detect flag needs the '--container' or '--root' flag")
|
||||
os.Exit(1)
|
||||
}
|
||||
// Checking if container flag was set, then overwriting OptRoot
|
||||
if OptContainer != "" {
|
||||
if container.ValidSource(OptContainer) {
|
||||
OptRoot = container.RootFsDir(OptContainer)
|
||||
} else {
|
||||
wwlog.Printf(wwlog.ERROR, " %s is not a valid container", OptContainer)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
var kernelVersion string
|
||||
var err error
|
||||
if len(args) > 0 {
|
||||
kernelVersion = args[0]
|
||||
} else {
|
||||
kernelVersion, err = kernel.FindKernelVersion(OptRoot)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "could not detect kernel under %s\n", OptRoot)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
kernelName := kernelVersion
|
||||
if len(args) > 1 {
|
||||
kernelName = args[1]
|
||||
} else if OptDetect && (OptContainer != "") {
|
||||
kernelName = OptContainer
|
||||
}
|
||||
output, err := kernel.Build(kernelVersion, kernelName, OptRoot)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "Failed building kernel: %s\n", err)
|
||||
os.Exit(1)
|
||||
} else {
|
||||
fmt.Printf("%s: %s\n", kernelName, output)
|
||||
}
|
||||
|
||||
if SetDefault {
|
||||
|
||||
nodeDB, err := node.New()
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
//TODO: Don't loop through profiles, instead have a nodeDB function that goes directly to the map
|
||||
profiles, _ := nodeDB.FindAllProfiles()
|
||||
for _, profile := range profiles {
|
||||
wwlog.Printf(wwlog.DEBUG, "Looking for profile default: %s\n", profile.Id.Get())
|
||||
if profile.Id.Get() == "default" {
|
||||
wwlog.Printf(wwlog.DEBUG, "Found profile default, setting kernel version to: %s\n", args[0])
|
||||
profile.KernelVersion.Set(args[0])
|
||||
err := nodeDB.ProfileUpdate(profile)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to update node profile")
|
||||
}
|
||||
}
|
||||
}
|
||||
err = nodeDB.Persist()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to persist nodedb")
|
||||
}
|
||||
fmt.Printf("Set default kernel version to: %s\n", args[0])
|
||||
err = warewulfd.DaemonReload()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to reload warewulf daemon")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
46
internal/app/wwctl/kernel/imprt/root.go
Normal file
46
internal/app/wwctl/kernel/imprt/root.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package imprt
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/container"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
baseCmd = &cobra.Command{
|
||||
DisableFlagsInUseLine: true,
|
||||
Use: "import [OPTIONS] KERNEL",
|
||||
Short: "Import Kernel version into Warewulf",
|
||||
Long: "This will import a boot KERNEL version from the control node into Warewulf",
|
||||
RunE: CobraRunE,
|
||||
Args: cobra.MinimumNArgs(0),
|
||||
}
|
||||
BuildAll bool
|
||||
ByNode bool
|
||||
SetDefault bool
|
||||
OptRoot string
|
||||
OptContainer string
|
||||
OptDetect bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
baseCmd.PersistentFlags().BoolVarP(&BuildAll, "all", "a", false, "Build all overlays (runtime and system)")
|
||||
baseCmd.PersistentFlags().BoolVarP(&ByNode, "node", "n", false, "Build overlay for a particular node(s)")
|
||||
baseCmd.PersistentFlags().BoolVar(&SetDefault, "setdefault", false, "Set this kernel for the default profile")
|
||||
baseCmd.PersistentFlags().StringVarP(&OptRoot, "root", "r", "/", "Import kernel from root (chroot) directory")
|
||||
baseCmd.PersistentFlags().StringVarP(&OptContainer, "container", "C", "", "Import kernel from container")
|
||||
err := baseCmd.RegisterFlagCompletionFunc("container", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
list, _ := container.ListSources()
|
||||
return list, cobra.ShellCompDirectiveNoFileComp
|
||||
})
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
baseCmd.PersistentFlags().BoolVarP(&OptDetect, "detect", "D", false, "Try to detect the kernel version in an automated way, needs the -C or -r option")
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
}
|
||||
35
internal/app/wwctl/kernel/list/main.go
Normal file
35
internal/app/wwctl/kernel/list/main.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package list
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/kernel"
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
|
||||
kernels, err := kernel.ListKernels()
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
nconfig, _ := node.New()
|
||||
nodes, _ := nconfig.FindAllNodes()
|
||||
nodemap := make(map[string]int)
|
||||
|
||||
for _, n := range nodes {
|
||||
nodemap[n.KernelVersion.Get()]++
|
||||
}
|
||||
|
||||
fmt.Printf("%-35s %-25s %-6s\n", "KERNEL NAME", "KERNEL VERSION", "NODES")
|
||||
for _, k := range kernels {
|
||||
fmt.Printf("%-35s %-25s %6d\n", k, kernel.GetKernelVersion(k), nodemap[k])
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
23
internal/app/wwctl/kernel/list/root.go
Normal file
23
internal/app/wwctl/kernel/list/root.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package list
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
var (
|
||||
baseCmd = &cobra.Command{
|
||||
DisableFlagsInUseLine: true,
|
||||
Use: "list [OPTIONS]",
|
||||
Short: "List imported Kernel images",
|
||||
Long: "This command will list the kernels that have been imported into Warewulf.",
|
||||
RunE: CobraRunE,
|
||||
Args: cobra.ExactArgs(0),
|
||||
Aliases: []string{"ls"},
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
}
|
||||
28
internal/app/wwctl/kernel/root.go
Normal file
28
internal/app/wwctl/kernel/root.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package kernel
|
||||
|
||||
import (
|
||||
"github.com/hpcng/warewulf/internal/app/wwctl/kernel/delete"
|
||||
"github.com/hpcng/warewulf/internal/app/wwctl/kernel/imprt"
|
||||
"github.com/hpcng/warewulf/internal/app/wwctl/kernel/list"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
baseCmd = &cobra.Command{
|
||||
DisableFlagsInUseLine: true,
|
||||
Use: "kernel COMMAND [OPTIONS]",
|
||||
Short: "Kernel Image Management",
|
||||
Long: "This command manages Warewulf Kernels used for bootstrapping nodes",
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
baseCmd.AddCommand(imprt.GetCommand())
|
||||
baseCmd.AddCommand(list.GetCommand())
|
||||
baseCmd.AddCommand(delete.GetCommand())
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
}
|
||||
Reference in New Issue
Block a user