Added container delete command

This commit is contained in:
Gregory Kurtzer
2020-12-07 19:42:14 -08:00
parent 94f6154f68
commit f9ebd8cf4b
3 changed files with 71 additions and 1 deletions

View File

@@ -0,0 +1,44 @@
package delete
import (
"fmt"
"github.com/hpcng/warewulf/internal/pkg/container"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
"os"
)
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.ContainerName.Get() == arg {
wwlog.Printf(wwlog.ERROR, "Container is configured for nodes, skipping: %s\n", arg)
continue ARG_LOOP
}
}
if container.ValidSource(arg) == false {
wwlog.Printf(wwlog.ERROR, "Container name is not a valid source: %s\n", arg)
continue
}
err := container.DeleteSource(arg)
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not remove source: %s\n", arg)
} else {
fmt.Printf("Container has been deleted: %s\n", arg)
}
}
return nil
}

View File

@@ -0,0 +1,25 @@
package delete
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "delete",
Short: "Delete Source OCI VNFS images",
Long: "Delete Source OCI VNFS images ",
RunE: CobraRunE,
Args: cobra.MinimumNArgs(1),
}
SetForce bool
SetUpdate bool
SetBuild bool
)
func init() {
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -2,6 +2,7 @@ package container
import ( import (
"github.com/hpcng/warewulf/internal/app/wwctl/container/build" "github.com/hpcng/warewulf/internal/app/wwctl/container/build"
"github.com/hpcng/warewulf/internal/app/wwctl/container/delete"
"github.com/hpcng/warewulf/internal/app/wwctl/container/exec" "github.com/hpcng/warewulf/internal/app/wwctl/container/exec"
"github.com/hpcng/warewulf/internal/app/wwctl/container/list" "github.com/hpcng/warewulf/internal/app/wwctl/container/list"
"github.com/hpcng/warewulf/internal/app/wwctl/container/pull" "github.com/hpcng/warewulf/internal/app/wwctl/container/pull"
@@ -22,7 +23,7 @@ func init() {
baseCmd.AddCommand(list.GetCommand()) baseCmd.AddCommand(list.GetCommand())
baseCmd.AddCommand(pull.GetCommand()) baseCmd.AddCommand(pull.GetCommand())
baseCmd.AddCommand(exec.GetCommand()) baseCmd.AddCommand(exec.GetCommand())
baseCmd.AddCommand(delete.GetCommand())
} }
// GetRootCommand returns the root cobra.Command for the application. // GetRootCommand returns the root cobra.Command for the application.