Added "kernel delete" command.
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
|
||||
}
|
||||
22
internal/app/wwctl/kernel/delete/root.go
Normal file
22
internal/app/wwctl/kernel/delete/root.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package delete
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
var (
|
||||
baseCmd = &cobra.Command{
|
||||
Use: "delete [flags] [kernel version]...",
|
||||
Short: "Delete an imported kernel",
|
||||
Long: "This command will delete a kernel that has been imported into Warewulf.",
|
||||
RunE: CobraRunE,
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
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"
|
||||
@@ -18,6 +19,7 @@ var (
|
||||
func init() {
|
||||
baseCmd.AddCommand(imprt.GetCommand())
|
||||
baseCmd.AddCommand(list.GetCommand())
|
||||
baseCmd.AddCommand(delete.GetCommand())
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
|
||||
Reference in New Issue
Block a user