add metadata files
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
b108d836ff
commit
bf00263bc5
9 changed files with 206 additions and 5 deletions
14
lib/qemu.sh
14
lib/qemu.sh
|
|
@ -3,6 +3,7 @@
|
|||
. ./lib/numbers.sh
|
||||
. ./lib/colors.sh
|
||||
. ./lib/db.sh
|
||||
. ./lib/metadata.sh
|
||||
|
||||
function check_qemu_exist {
|
||||
local vm_name="${1}"
|
||||
|
|
@ -31,7 +32,10 @@ function qemu_start_vm {
|
|||
local vpc_name="${3}"
|
||||
local vm_name="${4}"
|
||||
local volume_path="${5}"
|
||||
local tap_id="$(generate_random_number 10)"
|
||||
local ssh_key="${6}"
|
||||
local gateway_ip="${7}"
|
||||
local tap_id="$(generate_random_id 10)"
|
||||
local metadata_port="$(generate_random_number)"
|
||||
local subnet_id="$(echo "${subnet_name}" | cut -d\- -f2)"
|
||||
local mac="$(find_mac "${vpc_name}_br-${subnet_id}" "${ip}")"
|
||||
|
||||
|
|
@ -42,8 +46,10 @@ function qemu_start_vm {
|
|||
} || \
|
||||
{
|
||||
print_in_color "${COLOR_GREEN}" "Create tap tap${tap_id}"
|
||||
add_in_db "vm" "${vm_name}" "${subnet_name}" "${tap_id}"
|
||||
add_in_db "vm" "${vm_name}" "${subnet_name}" "${tap_id}" "${metadata_port}" "${ip}"
|
||||
create_tap "${tap_id}" "br-${subnet_id}" "${vpc_name}"
|
||||
metadata_start "${vpc_name}" "${gateway_ip}" "${metadata_port}" "${vm_name}" "${ssh_key}"
|
||||
ip netnes exec "${vpc_name}" iptable -t nat -A PREROUTING -s "${ip}/32" -d "169.254.169.254/32" -p tcp -m tcp --dport 80 -j DNAT --to-destination "${gateway_ip}:8080"
|
||||
|
||||
print_in_color "${COLOR_GREEN}" "Start vm ${vm_name}"
|
||||
ip netns exec "${vpc_name}" qemu-system-x86_64 \
|
||||
|
|
@ -67,6 +73,8 @@ function qemu_stop_vm {
|
|||
local vm_def=$(get_from_db "vm" "${vm_name}")
|
||||
local subnet_name="$(echo "${vm_def}" | cut -d\; -f 2)"
|
||||
local tap_id="$(echo "${vm_def}" | cut -d\; -f 3)"
|
||||
local metadata_port="$(echo "${vm_def}" | cut -d\; -f 4)"
|
||||
local ip="$(echo "${vm_def}" | cut -d\; -f 5)"
|
||||
local subnet_def=$(get_from_db "subnet" "${subnet_name}")
|
||||
local vpc_name="$(echo "${subnet_def}" | cut -d\; -f 2)"
|
||||
|
||||
|
|
@ -79,6 +87,8 @@ function qemu_stop_vm {
|
|||
|
||||
print_in_color "${COLOR_RED}" "Delete tap${tap_id}"
|
||||
ip -n "${vpc_name}" link del dev "tap${tap_id}"
|
||||
|
||||
metadata_stop "${vpc_name}" "${ip}" "${metadata_port}"
|
||||
delete_in_db "vm" "${vm_name}"
|
||||
|
||||
print_in_color "${COLOR_GREY}" "Try to delete ${subnet_name}"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue