41 lines
No EOL
1.2 KiB
Bash
41 lines
No EOL
1.2 KiB
Bash
#!/bin/bash
|
|
|
|
. ./lib/numbers.sh
|
|
. ./lib/colors.sh
|
|
|
|
function create_tap {
|
|
tap_id="${1}"
|
|
bridge_name="${2}"
|
|
|
|
ip tuntap add dev "tap${tap_id}" mode tap
|
|
brctl addif "${bridge_name}" "tap${tap_id}"
|
|
ip link set up dev "tap${tap_id}"
|
|
}
|
|
|
|
function qemu_start_vm {
|
|
local ip="${1}"
|
|
local subnet_name="${2}"
|
|
local vpc_name="${3}"
|
|
local vm_name="${4}"
|
|
local volume_path="${5}"
|
|
local tap_id="$(generate_random_number 10)"
|
|
local subnet_id="$(echo "${subnet_name}" | cut -d\- -f2)"
|
|
local mac="$(find_mac "${vpc_name}_br-${subnet_id}" "${ip}")"
|
|
|
|
print_in_color "${COLOR_GREEN}" "Create tap tap${tap_id}"
|
|
create_tap "${tap_id}" "br-${subnet_id}"
|
|
|
|
print_in_color "${COLOR_GREEN}" "Start vm ${vm_name}"
|
|
qemu-system-x86_64 \
|
|
-enable-kvm \
|
|
-cpu host \
|
|
-m 512 \
|
|
-smp 1 \
|
|
-serial "unix:/tmp/${vm_name}.sock,server,nowait" \
|
|
-monitor "unix:/tmp/${vm_name}.mon-sock,server,nowait" \
|
|
-display "none" \
|
|
-drive "file=${volume_path},if=virtio" \
|
|
-netdev "tap,id=net0,ifname=tap${tap_id},script=no,downscript=no" \
|
|
-device "virtio-net-pci,netdev=net0,mac=${mac}" \
|
|
-daemonize
|
|
} |