add qemu start gestion
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
11eef332b7
commit
1cdb89b0e6
2 changed files with 43 additions and 2 deletions
41
lib/qemu.sh
Normal file
41
lib/qemu.sh
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#!/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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue