remove vpc
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
2fb4af691d
commit
a8ec7910cd
3 changed files with 15 additions and 50 deletions
|
|
@ -33,4 +33,4 @@ function count_in_db {
|
||||||
function get_from_db {
|
function get_from_db {
|
||||||
use_db "get_from_db" "$@"
|
use_db "get_from_db" "$@"
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
|
||||||
23
lib/netns.sh
23
lib/netns.sh
|
|
@ -1,23 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
function create_netns {
|
|
||||||
netns_name="${1}"
|
|
||||||
|
|
||||||
ip netns add "${netns_name}"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function check_netns {
|
|
||||||
netns_name="${1}"
|
|
||||||
|
|
||||||
ip netns | grep "${netns_name}" > /dev/null \
|
|
||||||
&& return 0 \
|
|
||||||
|| return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
function delete_netns {
|
|
||||||
netns_name="${1}"
|
|
||||||
|
|
||||||
ip netns delete "${netns_name}"
|
|
||||||
|
|
||||||
}
|
|
||||||
40
lib/vpc.sh
40
lib/vpc.sh
|
|
@ -1,17 +1,22 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. ./lib/db.sh
|
. ./lib/db.sh
|
||||||
. ./lib/netns.sh
|
|
||||||
. ./lib/colors.sh
|
. ./lib/colors.sh
|
||||||
|
|
||||||
|
BINARY="/opt/two/bin/vpc"
|
||||||
|
|
||||||
|
function use_vpc {
|
||||||
|
db_use="${1}"
|
||||||
|
shift 1
|
||||||
|
|
||||||
|
${BINARY} "${db_use}" "$@"
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
function check_vpc_exist {
|
function check_vpc_exist {
|
||||||
local vpc_name=${1}
|
local vpc_name=${1}
|
||||||
|
|
||||||
print_in_color "${COLOR_GREY}" "Check in db if ${vpc_name} exist"
|
use_vpc -action "check" -name "${vpc_name}"
|
||||||
check_in_db vpc "${vpc_name}"
|
|
||||||
[ "$?" -eq "0" ] || return 1
|
|
||||||
print_in_color "${COLOR_GREY}" "Check in linux if ${vpc_name} exist"
|
|
||||||
check_netns "${vpc_name}"
|
|
||||||
[ "$?" -eq "0" ] || return 1
|
[ "$?" -eq "0" ] || return 1
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
@ -25,22 +30,7 @@ function create_vpc {
|
||||||
print_in_color "${COLOR_ORANGE}" "Would have create ${vpc_name}"
|
print_in_color "${COLOR_ORANGE}" "Would have create ${vpc_name}"
|
||||||
} || \
|
} || \
|
||||||
{
|
{
|
||||||
add_in_db "vpc" "${vpc_name}"
|
use_vpc -action "create" -name "${vpc_name}"
|
||||||
create_netns "${vpc_name}"
|
|
||||||
|
|
||||||
ip link add "${vpc_name}-ext" type veth peer name "veth-public-int" netns "${vpc_name}"
|
|
||||||
ip netns exec "${vpc_name}" brctl addbr "br-public"
|
|
||||||
ip netns exec "${vpc_name}" brctl stp "br-public" off
|
|
||||||
|
|
||||||
|
|
||||||
brctl addif "br-public" "${vpc_name}-ext"
|
|
||||||
ip netns exec "${vpc_name}" brctl addif "br-public" "veth-public-int"
|
|
||||||
|
|
||||||
|
|
||||||
ip link set up dev "${vpc_name}-ext"
|
|
||||||
ip -n "${vpc_name}" link set up dev "veth-public-int"
|
|
||||||
ip -n "${vpc_name}" link set up dev "br-public"
|
|
||||||
|
|
||||||
print_in_color "${COLOR_GREEN}" "Create ${vpc_name}"
|
print_in_color "${COLOR_GREEN}" "Create ${vpc_name}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -51,7 +41,5 @@ function delete_vpc {
|
||||||
|
|
||||||
|
|
||||||
print_in_color "${COLOR_RED}" "Delete ${vpc_name}"
|
print_in_color "${COLOR_RED}" "Delete ${vpc_name}"
|
||||||
delete_in_db "vpc" "${vpc_name}"
|
use_vpc -action "delete" -name "${vpc_name}"
|
||||||
delete_netns "${vpc_name}"
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue