-
Notifications
You must be signed in to change notification settings - Fork 19
/
nlb_delete.go
59 lines (47 loc) · 1.38 KB
/
nlb_delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package cmd
import (
"fmt"
apiv2 "github.com/exoscale/egoscale/api/v2"
"github.com/spf13/cobra"
)
var nlbDeleteCmd = &cobra.Command{
Use: "delete <ID>",
Short: "Delete a Network Load Balancer",
Aliases: gRemoveAlias,
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
cmdExitOnUsageError(cmd, "invalid arguments")
}
cmdSetZoneFlagFromDefault(cmd)
return cmdCheckRequiredFlags(cmd, []string{"zone"})
},
RunE: func(cmd *cobra.Command, args []string) error {
var nlbID = args[0]
zone, err := cmd.Flags().GetString("zone")
if err != nil {
return err
}
force, err := cmd.Flags().GetBool("force")
if err != nil {
return err
}
if !force {
if !askQuestion(fmt.Sprintf("Do you really want to delete Network Load Balancer %q?", nlbID)) {
return nil
}
}
ctx := apiv2.WithEndpoint(gContext, apiv2.NewReqEndpoint(gCurrentAccount.Environment, ""))
if err := cs.DeleteNetworkLoadBalancer(ctx, zone, nlbID); err != nil {
return fmt.Errorf("unable to delete Network Load Balancer: %s", err)
}
if !gQuiet {
cmd.Println("Network Load Balancer deleted successfully")
}
return nil
},
}
func init() {
nlbDeleteCmd.Flags().BoolP("force", "f", false, "Attempt to delete without prompting for confirmation")
nlbDeleteCmd.Flags().StringP("zone", "z", "", "Network Load Balancer zone")
nlbCmd.AddCommand(nlbDeleteCmd)
}