two_with_bash/lib/subnet.sh
GnomeZworc 18db138f8f
subnet
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2026-04-16 22:36:11 +02:00

54 lines
1.9 KiB
Bash

#!/bin/bash
. ./lib/db.sh
. ./lib/colors.sh
. ./lib/vpc.sh
. ./lib/dhcp.sh
function check_subnet_exist {
local vpc_name="${1}"
local subnet_name="${2}"
local vxlan_id="${3}"
local subnet_id="${4}"
print_in_color "${COLOR_GREY}" "Check in db if ${subnet_name} exist"
check_in_db subnet "${subnet_name};${vpc_name}"
[ "$?" -eq "0" ] || return 1
print_in_color "${COLOR_GREY}" "Check in linux if ${subnet_name} exist"
ip link show | grep -E '^[0-9]*:'|sed -e 's/ //g' | cut -d: -f 2 | grep "br-${subnet_id}" > /dev/null || return 1
ip -n "${vpc_name}" link show | grep -E '^[0-9]*:'|sed -e 's/ //g' | cut -d: -f 2 | grep "br-${subnet_id}" > /dev/null || return 1
ip link show | grep -E '^[0-9]*:'|sed -e 's/ //g' | cut -d: -f 2 | grep "v-${subnet_id}-e" > /dev/null || return 1
ip -n "${vpc_name}" link show | grep -E '^[0-9]*:'|sed -e 's/ //g' | cut -d: -f 2 | grep "v-${subnet_id}-i" > /dev/null || return 1
ip link show | grep -E '^[0-9]*:'|sed -e 's/ //g' | cut -d: -f 2 | grep "vxlan-${vxlan_id}" > /dev/null || return 1
return 0
}
function create_subnet {
local vpc_name="${1}"
local subnet_name="${2}"
local vxlan_id="${3}"
local local_ip="${4}"
local gateway_ip="${5}"
local subnet="${6}"
local subnet_id="$(echo "${subnet_name}" | cut -d\- -f2)"
/opt/two/bin/subnet -action create \
-cidr "${subnet}" \
-gateway-ip "${gateway_ip}" \
-local-ip "${local_ip}" \
-name "${subnet_name}" \
-vpc "${vpc_name}" \
-vxlan-id "${vxlan_id}"
return 0
}
function delete_subnet {
local subnet_name="${1}"
/opt/two/bin/subnet -action delete -name "${subnet_name}"
print_in_color "${COLOR_GREY}" "Try to delete ${vpc_name}"
count_in_db "subnet" "${vpc_name}"
[ "$?" -eq "0" ] && delete_vpc "${vpc_name}"
}