diff --git a/internal/app/wwctl/container/delete/main.go b/internal/app/wwctl/container/delete/main.go new file mode 100644 index 00000000..dfd9d8b5 --- /dev/null +++ b/internal/app/wwctl/container/delete/main.go @@ -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 +} diff --git a/internal/app/wwctl/container/delete/root.go b/internal/app/wwctl/container/delete/root.go new file mode 100644 index 00000000..2171df6a --- /dev/null +++ b/internal/app/wwctl/container/delete/root.go @@ -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 +} diff --git a/internal/app/wwctl/container/root.go b/internal/app/wwctl/container/root.go index 9bda463a..00739fd7 100644 --- a/internal/app/wwctl/container/root.go +++ b/internal/app/wwctl/container/root.go @@ -2,6 +2,7 @@ package container import ( "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/list" "github.com/hpcng/warewulf/internal/app/wwctl/container/pull" @@ -22,7 +23,7 @@ func init() { baseCmd.AddCommand(list.GetCommand()) baseCmd.AddCommand(pull.GetCommand()) baseCmd.AddCommand(exec.GetCommand()) - + baseCmd.AddCommand(delete.GetCommand()) } // GetRootCommand returns the root cobra.Command for the application.