add delete subnet
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
5a263464e3
commit
1f28301a94
3 changed files with 46 additions and 10 deletions
25
lib/db.sh
25
lib/db.sh
|
|
@ -11,8 +11,8 @@ DB_PATH="./data/"
|
|||
# 0 entry exist
|
||||
function check_in_db {
|
||||
|
||||
db_name="${1}"
|
||||
search_id="${2}"
|
||||
local db_name="${1}"
|
||||
local search_id="${2}"
|
||||
|
||||
[ -f "${DB_PATH}${db_name}.db" ] || return 1
|
||||
cat "${DB_PATH}${db_name}.db" | \
|
||||
|
|
@ -22,7 +22,7 @@ function check_in_db {
|
|||
|
||||
function add_in_db {
|
||||
|
||||
db_name="${1}"
|
||||
local db_name="${1}"
|
||||
shift 1
|
||||
|
||||
local IFS=";"
|
||||
|
|
@ -33,8 +33,8 @@ function add_in_db {
|
|||
|
||||
function delete_in_db {
|
||||
|
||||
db_name="${1}"
|
||||
id="${2}"
|
||||
local db_name="${1}"
|
||||
local id="${2}"
|
||||
|
||||
[ "$(uname)" == "Darwin" ] \
|
||||
&& sed "/^${id}/d" "${DB_PATH}${db_name}.db" -i '' \
|
||||
|
|
@ -51,12 +51,23 @@ function delete_in_db {
|
|||
# [1-500] entry count
|
||||
function count_in_db {
|
||||
|
||||
db_name="${1}"
|
||||
id="${2}"
|
||||
local db_name="${1}"
|
||||
local id="${2}"
|
||||
|
||||
[ -f "${DB_PATH}${db_name}.db" ] || return 0
|
||||
count=$(cat "${DB_PATH}${db_name}.db" | grep "${id}" | wc -l | sed -e 's/ //g')
|
||||
|
||||
return "${count}"
|
||||
|
||||
}
|
||||
|
||||
function get_from_db {
|
||||
local db_name="${1}"
|
||||
local id="${2}"
|
||||
|
||||
[ -f "${DB_PATH}${db_name}.db" ] || return 0
|
||||
|
||||
cat "${DB_PATH}${db_name}.db" | grep "${id}"
|
||||
return "$?"
|
||||
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
. ./lib/db.sh
|
||||
. ./lib/colors.sh
|
||||
. ./lib/vpc.sh
|
||||
|
||||
function check_subnet_exist {
|
||||
local vpc_name="${1}"
|
||||
|
|
@ -81,4 +82,28 @@ function create_subnet {
|
|||
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
function delete_subnet {
|
||||
local subnet_name="${1}"
|
||||
local subnet_id="$(echo "${subnet_name}" | cut -d\- -f2)"
|
||||
|
||||
subnet_def=$(get_from_db "subnet" "${subnet_name}")
|
||||
local vpc_name="$(echo "${subnet_def}" | cut -d\; -f 2)"
|
||||
local vxlan_id="$(echo "${subnet_def}" | cut -d\; -f 3)"
|
||||
local gateway_ip="$(echo "${subnet_def}" | cut -d\; -f 5)"
|
||||
local subnet="$(echo "${subnet_def}" | cut -d\; -f 6)"
|
||||
|
||||
print_in_color "${COLOR_RED}" "Delete ${subnet_name}"
|
||||
delete_in_db "subnet" "${subnet_name}"
|
||||
ip -n "${vpc_name}" route del "${subnet}" dev "br-${subnet_id}"
|
||||
ip link del dev "vxlan-${vxlan_id}"
|
||||
ebtables -D FORWARD -p arp --arp-op Request --arp-ip-dst "${gateway_ip}" --out-interface "br-${subnet_id}" -j DROP
|
||||
ip link del dev "br-${subnet_id}"
|
||||
ip -n "${vpc_name}" link del dev "br-${subnet_id}"
|
||||
ip link del dev "veth-${subnet_id}-ext"
|
||||
|
||||
print_in_color "${COLOR_GREY}" "Try to delete ${vpc_name}"
|
||||
count_in_db "subnet" "${vpc_name}"
|
||||
[ "$?" -eq "0" ] && delete_vpc "${vpc_name}"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue