mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 09:25:46 +03:00
node pools: implement CLI (#17388)
This commit is contained in:
86
command/node_pool_delete.go
Normal file
86
command/node_pool_delete.go
Normal file
@@ -0,0 +1,86 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/go-set"
|
||||
"github.com/hashicorp/nomad/api"
|
||||
"github.com/posener/complete"
|
||||
)
|
||||
|
||||
type NodePoolDeleteCommand struct {
|
||||
Meta
|
||||
}
|
||||
|
||||
func (c *NodePoolDeleteCommand) Name() string {
|
||||
return "node pool delete"
|
||||
}
|
||||
|
||||
func (c *NodePoolDeleteCommand) Synopsis() string {
|
||||
return "Delete a node pool"
|
||||
}
|
||||
|
||||
func (c *NodePoolDeleteCommand) Help() string {
|
||||
helpText := `
|
||||
Usage: nomad node pool delete [options] <node-pool>
|
||||
|
||||
Delete is used to remove a node pool.
|
||||
|
||||
If ACLs are enabled, this command requires a token with the 'delete'
|
||||
capability in a 'node_pool' policy that matches the node pool being targeted.
|
||||
|
||||
General Options:
|
||||
|
||||
` + generalOptionsUsage(usageOptsDefault)
|
||||
|
||||
return strings.TrimSpace(helpText)
|
||||
}
|
||||
|
||||
func (c *NodePoolDeleteCommand) AutocompleteFlags() complete.Flags {
|
||||
return c.Meta.AutocompleteFlags(FlagSetClient)
|
||||
}
|
||||
|
||||
func (c *NodePoolDeleteCommand) AutocompleteArgs() complete.Predictor {
|
||||
return nodePoolPredictor(c.Client, set.From([]string{
|
||||
api.NodePoolAll,
|
||||
api.NodePoolDefault,
|
||||
}))
|
||||
}
|
||||
|
||||
func (c *NodePoolDeleteCommand) Run(args []string) int {
|
||||
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
|
||||
flags.Usage = func() { c.Ui.Output(c.Help()) }
|
||||
|
||||
if err := flags.Parse(args); err != nil {
|
||||
return 1
|
||||
}
|
||||
|
||||
// Check that we only have one argument.
|
||||
args = flags.Args()
|
||||
if len(args) != 1 {
|
||||
c.Ui.Error("This command takes one argument: <node-pool>")
|
||||
c.Ui.Error(commandErrorText(c))
|
||||
return 1
|
||||
}
|
||||
pool := args[0]
|
||||
|
||||
// Make API equest.
|
||||
client, err := c.Meta.Client()
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err))
|
||||
return 1
|
||||
}
|
||||
|
||||
_, err = client.NodePools().Delete(pool, nil)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error deleting node pool: %s", err))
|
||||
return 1
|
||||
}
|
||||
|
||||
c.Ui.Output(fmt.Sprintf("Successfully deleted node pool %q!", pool))
|
||||
return 0
|
||||
}
|
||||
Reference in New Issue
Block a user