2023-03-11 13:49:35 +01:00
|
|
|
/*
|
|
|
|
Copyright © 2023 Laura Kalb <dev@lauka.net>
|
|
|
|
*/
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-03-14 17:21:49 +01:00
|
|
|
"net/netip"
|
2023-03-11 13:49:35 +01:00
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
// deleteCmd represents the delete command
|
|
|
|
var subnetdeleteCmd = &cobra.Command{
|
2023-03-12 13:18:54 +01:00
|
|
|
Use: "delete",
|
|
|
|
Short: "delete subnet",
|
2023-03-12 16:58:30 +01:00
|
|
|
Long: `Delete a subnet from the ipam.`,
|
2023-03-12 13:18:54 +01:00
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
Aliases: []string{"d"},
|
2023-03-14 17:21:49 +01:00
|
|
|
Example: "ipam subnet delete 192.168.0.0/24",
|
2023-03-11 13:49:35 +01:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2023-03-14 17:21:49 +01:00
|
|
|
subnet, parseerr := netip.ParsePrefix(args[0])
|
|
|
|
if parseerr != nil {
|
|
|
|
fmt.Println("[ERROR]", parseerr)
|
2023-03-11 13:49:35 +01:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2023-03-14 17:21:49 +01:00
|
|
|
var confirmation string
|
|
|
|
fmt.Printf("[WARNING] Do you really want to delete subnet %v? [y/N] ", subnet.String())
|
|
|
|
fmt.Scan(&confirmation)
|
|
|
|
|
|
|
|
if (confirmation == "y") || (confirmation == "Y") {
|
|
|
|
deleteerr := DeleteSubnet(subnet)
|
|
|
|
if deleteerr != nil {
|
|
|
|
fmt.Println("[ERROR]", deleteerr)
|
|
|
|
os.Exit(1)
|
|
|
|
} else {
|
|
|
|
fmt.Printf("deleted subnet %v\n", subnet.String())
|
|
|
|
}
|
|
|
|
}
|
2023-03-11 13:49:35 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
subnetCmd.AddCommand(subnetdeleteCmd)
|
|
|
|
|
|
|
|
// Here you will define your flags and configuration settings.
|
|
|
|
|
|
|
|
// Cobra supports Persistent Flags which will work for this command
|
|
|
|
// and all subcommands, e.g.:
|
|
|
|
// deleteCmd.PersistentFlags().String("foo", "", "A help for foo")
|
|
|
|
|
|
|
|
// Cobra supports local flags which will only run when this command
|
|
|
|
// is called directly, e.g.:
|
|
|
|
// deleteCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
|
|
|
}
|