Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2025-05-06 23:43:53 +02:00
commit 6b9c5e64b8
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
4 changed files with 65 additions and 8 deletions

View file

@ -1,10 +1,13 @@
#!/bin/bash
[[ -f ./libs/shflags ]] && . ./libs/shflags || eval "$(curl --silent https://git.g3e.fr/H6N/tools/raw/branch/main/libs/shflags)"
. ./lib/vpc.sh
function start_vm {
[[ -f ./libs/shflags ]] && . ./libs/shflags || eval "$(curl --silent https://git.g3e.fr/H6N/tools/raw/branch/main/libs/shflags)"
DRY_RUN="1"
SIMULATION="1"
function start_vm {
DEFINE_string 'interface' 'eno1' 'KVM Interface' 'i'
DEFINE_string 'vxlan_id' '-' 'VXLAN ID' 'v'
DEFINE_string 'gateway_ip' '-' 'Gatewat IP' 'g'
@ -44,7 +47,19 @@ function start_vm {
echo
echo
create_vpc "${FLAGS_vpc_name}"
create_vpc "${FLAGS_dryrun}" "${FLAGS_vpc_name}"
}
function stop_vm {
DEFINE_string 'vm_name' '-' 'VM NAME' 'm'
DEFINE_string 'vpc_name' '-' 'VPC NAME' 'c'
DEFINE_boolean 'dryrun' false 'Enable dry-run mode' 'd'
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"
delete_vpc "${FLAGS_vpc_name}"
}
function main {
@ -55,6 +70,9 @@ function main {
"StartVm")
start_vm "$@"
;;
"StopVm")
stop_vm "$@"
;;
*)
echo "action : ${fonction} not known !"
echo "avalable action :"

5
delete_vpc.sh Normal file
View file

@ -0,0 +1,5 @@
#!/bin/bash
. ./lib/vpc.sh
delete_vpc "${1}"

23
lib/netns.sh Normal file
View file

@ -0,0 +1,23 @@
#!/bin/bash
function create_netns {
netns_name="${1}"
ip netns add "${netns_name}"
}
function check_netns {
netns_name="${1}"
ip netns | grep "${netns_name}" \
&& return 0 \
|| return 1
}
function delete_netns {
netns_name="${1}"
ip netns delete "${netns_name}"
}

View file

@ -1,6 +1,7 @@
#!/bin/bash
. ./lib/db.sh
. ./lib/netns.sh
function check_vpc_exist {
vpc_name=${1}
@ -10,20 +11,30 @@ function check_vpc_exist {
echo " -> check in linux"
check_in_db vpc "${vpc_name}"
[ "$?" -eq "0" ] && return 0 || return 1
[ "$?" -eq "0" ] || return 1
check_netns "${vpc_name}"
[ "$?" -eq "0" ] || return 1
return 0
}
function create_vpc {
vpc_name="${1}"
dryrun="${1}"
vpc_name="${2}"
check_vpc_exist "${vpc_name}"
[ "$?" -eq "0" ] || add_in_db "vpc" "${vpc_name}"
[ "$?" -eq "0" ] || \
{
add_in_db "vpc" "${vpc_name}"
create_netns "${vpc_name}"
}
}
function delete_vpc {
vpc_name="${1}"
dryrun="${1}"
vpc_name="${2}"
delete_in_db "vpc" "${vpc_name}"
delete_netns "${vpc_name}"
}