default profile needs to have a container

Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
Christian Goll
2023-07-19 11:28:49 +02:00
committed by Jonathon Anderson
parent a36cb23319
commit 2fe98e5f55
9 changed files with 125 additions and 7 deletions

View File

@@ -2,10 +2,15 @@ package delete
import (
"fmt"
"os"
"github.com/hpcng/warewulf/internal/pkg/api/container"
"github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1"
"github.com/hpcng/warewulf/internal/pkg/api/util"
apiutil "github.com/hpcng/warewulf/internal/pkg/api/util"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
)
@@ -13,8 +18,23 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
cdp := &wwapiv1.ContainerDeleteParameter{
ContainerNames: args,
}
nodeDB, err := node.New()
if err != nil {
wwlog.Error("Failed to open node database: %s", err)
os.Exit(1)
}
profiles, err := nodeDB.MapAllProfiles()
if err != nil {
wwlog.Error("Could not load all profiles: %s", err)
os.Exit(1)
}
if util.InSlice(args, profiles["default"].ContainerName.Get()) {
return fmt.Errorf("can't delete container which is in the default profile")
}
if !SetYes {
yes := util.ConfirmationPrompt(fmt.Sprintf("Are you sure you want to delete container %s", args))
yes := apiutil.ConfirmationPrompt(fmt.Sprintf("Are you sure you want to delete container %s", args))
if !yes {
return
}