github.com/hernad/nomad@v1.6.112/command/node_pool_delete.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package command 5 6 import ( 7 "fmt" 8 "strings" 9 10 "github.com/hashicorp/go-set" 11 "github.com/hernad/nomad/api" 12 "github.com/posener/complete" 13 ) 14 15 type NodePoolDeleteCommand struct { 16 Meta 17 } 18 19 func (c *NodePoolDeleteCommand) Name() string { 20 return "node pool delete" 21 } 22 23 func (c *NodePoolDeleteCommand) Synopsis() string { 24 return "Delete a node pool" 25 } 26 27 func (c *NodePoolDeleteCommand) Help() string { 28 helpText := ` 29 Usage: nomad node pool delete [options] <node-pool> 30 31 Delete is used to remove a node pool. 32 33 If ACLs are enabled, this command requires a token with the 'delete' 34 capability in a 'node_pool' policy that matches the node pool being targeted. 35 36 You cannot delete a node pool that has nodes or non-terminal jobs. In 37 federated clusters, you cannot delete a node pool that has nodes or 38 non-terminal jobs in any of the federated regions. 39 40 General Options: 41 42 ` + generalOptionsUsage(usageOptsDefault) 43 44 return strings.TrimSpace(helpText) 45 } 46 47 func (c *NodePoolDeleteCommand) AutocompleteFlags() complete.Flags { 48 return c.Meta.AutocompleteFlags(FlagSetClient) 49 } 50 51 func (c *NodePoolDeleteCommand) AutocompleteArgs() complete.Predictor { 52 return nodePoolPredictor(c.Client, set.From([]string{ 53 api.NodePoolAll, 54 api.NodePoolDefault, 55 })) 56 } 57 58 func (c *NodePoolDeleteCommand) Run(args []string) int { 59 flags := c.Meta.FlagSet(c.Name(), FlagSetClient) 60 flags.Usage = func() { c.Ui.Output(c.Help()) } 61 62 if err := flags.Parse(args); err != nil { 63 return 1 64 } 65 66 // Check that we only have one argument. 67 args = flags.Args() 68 if len(args) != 1 { 69 c.Ui.Error("This command takes one argument: <node-pool>") 70 c.Ui.Error(commandErrorText(c)) 71 return 1 72 } 73 pool := args[0] 74 75 // Make API equest. 76 client, err := c.Meta.Client() 77 if err != nil { 78 c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err)) 79 return 1 80 } 81 82 _, err = client.NodePools().Delete(pool, nil) 83 if err != nil { 84 c.Ui.Error(fmt.Sprintf("Error deleting node pool: %s", err)) 85 return 1 86 } 87 88 c.Ui.Output(fmt.Sprintf("Successfully deleted node pool %q!", pool)) 89 return 0 90 }