-
Notifications
You must be signed in to change notification settings - Fork 19
/
privnet_delete.go
54 lines (46 loc) · 1.14 KB
/
privnet_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
package cmd
import (
"fmt"
"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)
// deleteCmd represents the delete command
var privnetDeleteCmd = &cobra.Command{
Use: "delete <name | id>",
Short: "Delete private network",
Aliases: gDeleteAlias,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return cmd.Usage()
}
force, err := cmd.Flags().GetBool("force")
if err != nil {
return err
}
if !force {
if !askQuestion(fmt.Sprintf("sure you want to delete %q private network", args[0])) {
return nil
}
}
return deletePrivnet(args[0], force)
},
}
func deletePrivnet(name string, force bool) error {
addrReq := &egoscale.DeleteNetwork{}
var err error
network, err := getNetworkByName(name)
if err != nil {
return err
}
addrReq.ID = network.ID
addrReq.Forced = &force
if err := cs.BooleanRequestWithContext(gContext, addrReq); err != nil {
return err
}
fmt.Println(addrReq.ID.String())
return nil
}
func init() {
privnetDeleteCmd.Flags().BoolP("force", "f", false, "Attempt to remove private network without prompting for confirmation")
privnetCmd.AddCommand(privnetDeleteCmd)
}