Optimized sorting methods across nodes and profiles
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
var count int
|
||||
var nodeList []node.NodeInfo
|
||||
|
||||
nodeDB, err := node.New()
|
||||
if err != nil {
|
||||
@@ -19,7 +20,30 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
nodeList, err := nodeDB.SearchByNameList(args)
|
||||
nodes, err := nodeDB.FindAllNodes()
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
for _, r := range args {
|
||||
var match bool
|
||||
for _, n := range nodes {
|
||||
if n.Id.Get() == r {
|
||||
nodeList = append(nodeList, n)
|
||||
match = true
|
||||
}
|
||||
}
|
||||
|
||||
if !match {
|
||||
fmt.Fprintf(os.Stderr, "ERROR: No match for node: %s\n", r)
|
||||
}
|
||||
}
|
||||
|
||||
if len(nodeList) == 0 {
|
||||
fmt.Printf("No nodes found\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
for _, n := range nodeList {
|
||||
err := nodeDB.DelNode(n.Id.Get())
|
||||
@@ -27,28 +51,25 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
} else {
|
||||
count++
|
||||
fmt.Printf("Deleting node: %s\n", n.Id.Print())
|
||||
}
|
||||
}
|
||||
|
||||
if count > 0 {
|
||||
if SetYes == true {
|
||||
nodeDB.Persist()
|
||||
} else {
|
||||
q := fmt.Sprintf("Are you sure you want to delete %d nodes(s)", count)
|
||||
|
||||
prompt := promptui.Prompt{
|
||||
Label: q,
|
||||
IsConfirm: true,
|
||||
}
|
||||
|
||||
result, _ := prompt.Run()
|
||||
|
||||
if result == "y" || result == "yes" {
|
||||
nodeDB.Persist()
|
||||
}
|
||||
}
|
||||
if SetYes {
|
||||
nodeDB.Persist()
|
||||
} else {
|
||||
fmt.Printf("No nodes found\n")
|
||||
q := fmt.Sprintf("Are you sure you want to delete %d nodes(s)", count)
|
||||
|
||||
prompt := promptui.Prompt{
|
||||
Label: q,
|
||||
IsConfirm: true,
|
||||
}
|
||||
|
||||
result, _ := prompt.Run()
|
||||
|
||||
if result == "y" || result == "yes" {
|
||||
nodeDB.Persist()
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -4,7 +4,7 @@ import "github.com/spf13/cobra"
|
||||
|
||||
var (
|
||||
baseCmd = &cobra.Command{
|
||||
Use: "delete [flags] [node pattern]...",
|
||||
Use: "delete [flags] [exact node name]...",
|
||||
Short: "Delete a node from Warewulf",
|
||||
Long: "This command will remove a node from the Warewulf node configuration.",
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
|
||||
Reference in New Issue
Block a user