Added container delete command
This commit is contained in:
44
internal/app/wwctl/container/delete/main.go
Normal file
44
internal/app/wwctl/container/delete/main.go
Normal 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
|
||||||
|
}
|
||||||
25
internal/app/wwctl/container/delete/root.go
Normal file
25
internal/app/wwctl/container/delete/root.go
Normal 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
|
||||||
|
}
|
||||||
@@ -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.
|
||||||
|
|||||||
Reference in New Issue
Block a user