subnet
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
9b060eaf34
commit
18db138f8f
1 changed files with 9 additions and 70 deletions
|
|
@ -33,81 +33,20 @@ function create_subnet {
|
||||||
local subnet="${6}"
|
local subnet="${6}"
|
||||||
local subnet_id="$(echo "${subnet_name}" | cut -d\- -f2)"
|
local subnet_id="$(echo "${subnet_name}" | cut -d\- -f2)"
|
||||||
|
|
||||||
check_subnet_exist "${vpc_name}" "${subnet_name}" "${vxlan_id}" "${subnet_id}"
|
/opt/two/bin/subnet -action create \
|
||||||
[ "$?" -eq "0" ] && \
|
-cidr "${subnet}" \
|
||||||
{
|
-gateway-ip "${gateway_ip}" \
|
||||||
print_in_color "${COLOR_ORANGE}" "Would have create ${subnet_name}"
|
-local-ip "${local_ip}" \
|
||||||
} || \
|
-name "${subnet_name}" \
|
||||||
{
|
-vpc "${vpc_name}" \
|
||||||
print_in_color "${COLOR_GREEN}" "Create ${subnet_name}"
|
-vxlan-id "${vxlan_id}"
|
||||||
|
|
||||||
print_in_color "${COLOR_GREEN}" " - add ${subnet_name} in db"
|
|
||||||
add_in_db "subnet" "${subnet_name}" "${vpc_name}" "${vxlan_id}" "${local_ip}" "${gateway_ip}" "${subnet}"
|
|
||||||
|
|
||||||
print_in_color "${COLOR_GREEN}" " - create veth"
|
|
||||||
ip link add "v-${subnet_id}-e" type veth peer name "v-${subnet_id}-i" netns "${vpc_name}"
|
|
||||||
|
|
||||||
print_in_color "${COLOR_GREEN}" " - add bridges"
|
|
||||||
brctl addbr "br-${subnet_id}"
|
|
||||||
brctl stp "br-${subnet_id}" off
|
|
||||||
ip netns exec "${vpc_name}" brctl addbr "br-${subnet_id}"
|
|
||||||
ip netns exec "${vpc_name}" brctl stp "br-${subnet_id}" off
|
|
||||||
|
|
||||||
print_in_color "${COLOR_GREEN}" " - add vxlan"
|
|
||||||
ip link add "vxlan-${vxlan_id}" type vxlan \
|
|
||||||
id "${vxlan_id}" \
|
|
||||||
dstport 4789 \
|
|
||||||
local "${local_ip}" \
|
|
||||||
nolearning
|
|
||||||
|
|
||||||
print_in_color "${COLOR_GREEN}" " - add interface in bridge"
|
|
||||||
brctl addif "br-${subnet_id}" "v-${subnet_id}-e"
|
|
||||||
ip netns exec "${vpc_name}" brctl addif "br-${subnet_id}" "v-${subnet_id}-i"
|
|
||||||
brctl addif "br-${subnet_id}" "vxlan-${vxlan_id}"
|
|
||||||
|
|
||||||
|
|
||||||
print_in_color "${COLOR_GREEN}" " - up interface"
|
|
||||||
ip link set up dev "v-${subnet_id}-e"
|
|
||||||
ip link set up dev "vxlan-${vxlan_id}"
|
|
||||||
ip link set up dev "br-${subnet_id}"
|
|
||||||
ip -n "${vpc_name}" link set up dev "v-${subnet_id}-i"
|
|
||||||
ip -n "${vpc_name}" link set up dev "br-${subnet_id}"
|
|
||||||
|
|
||||||
|
|
||||||
print_in_color "${COLOR_GREEN}" " - add subnet ip"
|
|
||||||
ip -n "${vpc_name}" a add "${gateway_ip}/32" dev "br-${subnet_id}"
|
|
||||||
print_in_color "${COLOR_GREEN}" " - add subnet route"
|
|
||||||
ip -n "${vpc_name}" r add "${subnet}" dev "br-${subnet_id}" scope link
|
|
||||||
print_in_color "${COLOR_GREEN}" " - add subnet firewall"
|
|
||||||
ebtables -A FORWARD --out-interface "br-${subnet_id}" -p arp --arp-op Request --arp-ip-dst "${gateway_ip}" -j DROP
|
|
||||||
ebtables -A FORWARD --out-interface "br-${subnet_id}" -p IPv4 --ip-protocol udp --ip-source-port 67:68 --ip-destination-port 67:68 -j DROP
|
|
||||||
|
|
||||||
/opt/two/bin/dhcp -name "${vpc_name}_br-${subnet_id}" -subnet "${subnet}" -gateway "${gateway_ip}"
|
|
||||||
}
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete_subnet {
|
function delete_subnet {
|
||||||
local subnet_name="${1}"
|
local subnet_name="${1}"
|
||||||
local subnet_id="$(echo "${subnet_name}" | cut -d\- -f2)"
|
|
||||||
|
|
||||||
subnet_def=$(get_from_db "subnet" "${subnet_name}")
|
/opt/two/bin/subnet -action delete -name "${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}"
|
|
||||||
systemctl stop "dnsmasq@${vpc_name}_br-${subnet_id}.service"
|
|
||||||
rm /etc/dnsmasq.d/${vpc_name}_br-${subnet_id}.conf
|
|
||||||
ebtables -D FORWARD -p arp --arp-op Request --arp-ip-dst "${gateway_ip}" --out-interface "br-${subnet_id}" -j DROP
|
|
||||||
ebtables -D FORWARD --out-interface "br-${subnet_id}" -p IPv4 --ip-protocol udp --ip-source-port 67:68 --ip-destination-port 67:68 -j DROP
|
|
||||||
ip link del dev "br-${subnet_id}"
|
|
||||||
ip -n "${vpc_name}" link del dev "br-${subnet_id}"
|
|
||||||
ip link del dev "v-${subnet_id}-e"
|
|
||||||
|
|
||||||
print_in_color "${COLOR_GREY}" "Try to delete ${vpc_name}"
|
print_in_color "${COLOR_GREY}" "Try to delete ${vpc_name}"
|
||||||
count_in_db "subnet" "${vpc_name}"
|
count_in_db "subnet" "${vpc_name}"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue