two_with_bash/lib/vpc.sh
GnomeZworc a4cd5bce4d
make public ip infra
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2025-05-19 18:47:13 +02:00

57 lines
No EOL
1.4 KiB
Bash

#!/bin/bash
. ./lib/db.sh
. ./lib/netns.sh
. ./lib/colors.sh
function check_vpc_exist {
local vpc_name=${1}
print_in_color "${COLOR_GREY}" "Check in db if ${vpc_name} exist"
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
return 0
}
function create_vpc {
local vpc_name="${1}"
check_vpc_exist "${vpc_name}"
[ "$?" -eq "0" ] && \
{
print_in_color "${COLOR_ORANGE}" "Would have create ${vpc_name}"
} || \
{
add_in_db "vpc" "${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}"
}
}
function delete_vpc {
local vpc_name="${1}"
print_in_color "${COLOR_RED}" "Delete ${vpc_name}"
delete_in_db "vpc" "${vpc_name}"
delete_netns "${vpc_name}"
}