This commit is contained in:
GnomeZworc 2025-05-16 14:01:31 +02:00
commit aa12d7336b
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
2 changed files with 77 additions and 74 deletions

77
lib/prime/vm.sh Normal file
View file

@ -0,0 +1,77 @@
#!/bin/bash
# red delete
# orange check-no-delete
# orange check-no-create
# green create
. ./lib/vpc.sh
. ./lib/subnet.sh
. ./lib/colors.sh
. ./lib/qemu.sh
DRY_RUN="1"
SIMULATION="1"
function start_vm {
[[ -f ./libs/shflags ]] && . ./libs/shflags || eval "$(curl --silent https://git.g3e.fr/H6N/tools/raw/branch/main/libs/shflags)"
DEFINE_string 'interface' 'eno1' 'KVM Interface' 'i'
DEFINE_string 'vxlan_id' '-' 'VXLAN ID' 'v'
DEFINE_string 'gateway_ip' '-' 'Gatewat IP' 'g'
DEFINE_string 'network' '-' 'Network IP' 'n'
DEFINE_string 'netmask' '-' 'Network Mask' 'e'
DEFINE_string 'vpc_name' '-' 'VPC NAME' 'c'
DEFINE_string 'subnet_name' '-' 'SUBNET NAME' 's'
DEFINE_string 'vm_name' '-' 'VM NAME' 'm'
DEFINE_string 'vm_ip' '-' 'VM CIDR' 'p'
DEFINE_string 'volume_id' '-' 'Volume backend file' 'o'
DEFINE_string 'ssh_key' '-' 'pub ssh Key' 'k'
DEFINE_boolean 'dryrun' false 'Enable dry-run mode' 'd'
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"
#bash agent.sh StartVm -c vpc-00000 -s subnet-00000 -v 12 -g 240.0.0.1 -n 240.0.0.0 -e 16 -m i-00000 -p 240.0.1.1
local local_ip=$(ip a show dev ${FLAGS_interface} | grep 'inet ' | sed -e 's/ */ /g' |cut -d\ -f 3|cut -d\/ -f1)
local gateway_ip="${FLAGS_gateway_ip}/32"
local subnet="${FLAGS_network}/${FLAGS_netmask}"
local vm_ip="${FLAGS_vm_ip}/${FLAGS_netmask}"
print_in_color "${COLOR_SYAN}" "#############################################"
print_in_color "${COLOR_SYAN}" "Create vm"
print_in_color "${COLOR_SYAN}" "kvm:"
print_in_color "${COLOR_SYAN}" " interface name: ${FLAGS_interface}"
print_in_color "${COLOR_SYAN}" " interface ip: ${local_ip}"
print_in_color "${COLOR_SYAN}" "subnet:"
print_in_color "${COLOR_SYAN}" " vpc: ${FLAGS_vpc_name}"
print_in_color "${COLOR_SYAN}" " vxlan: ${FLAGS_vxlan_id}"
print_in_color "${COLOR_SYAN}" " name: ${FLAGS_subnet_name}"
print_in_color "${COLOR_SYAN}" " gateway: ${gateway_ip}"
print_in_color "${COLOR_SYAN}" " network: ${subnet}"
print_in_color "${COLOR_SYAN}" "vm:"
print_in_color "${COLOR_SYAN}" " name: ${FLAGS_vm_name}"
print_in_color "${COLOR_SYAN}" " ip: ${vm_ip}"
print_in_color "${COLOR_SYAN}" " volume backing file: ${FLAGS_volume_id}"
print_in_color "${COLOR_SYAN}" " sshkey: ${FLAGS_ssh_key}"
print_in_color "${COLOR_SYAN}" "#############################################"
echo
echo
create_vpc "${FLAGS_vpc_name}"
create_subnet "${FLAGS_vpc_name}" "${FLAGS_subnet_name}" "${FLAGS_vxlan_id}" "${local_ip}" "${gateway_ip}" "${subnet}"
qemu_start_vm "${FLAGS_vm_ip}" "${FLAGS_subnet_name}" "${FLAGS_vpc_name}" "${FLAGS_vm_name}" "${FLAGS_volume_id}" "${FLAGS_ssh_key}" "${FLAGS_gateway_ip}"
}
function stop_vm {
[[ -f ./libs/shflags ]] && . ./libs/shflags || eval "$(curl --silent https://git.g3e.fr/H6N/tools/raw/branch/main/libs/shflags)"
DEFINE_string 'vm_name' '-' 'VM NAME' 'm'
DEFINE_boolean 'dryrun' false 'Enable dry-run mode' 'd'
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"
qemu_stop_vm "${FLAGS_vm_name}"
}