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
4
agent.sh
4
agent.sh
|
|
@ -10,6 +10,7 @@
|
||||||
. ./lib/vpc.sh
|
. ./lib/vpc.sh
|
||||||
. ./lib/subnet.sh
|
. ./lib/subnet.sh
|
||||||
. ./lib/colors.sh
|
. ./lib/colors.sh
|
||||||
|
. ./lib/qemu.sh
|
||||||
|
|
||||||
DRY_RUN="1"
|
DRY_RUN="1"
|
||||||
SIMULATION="1"
|
SIMULATION="1"
|
||||||
|
|
@ -58,8 +59,7 @@ function start_vm {
|
||||||
|
|
||||||
create_vpc "${FLAGS_vpc_name}"
|
create_vpc "${FLAGS_vpc_name}"
|
||||||
create_subnet "${FLAGS_vpc_name}" "${FLAGS_subnet_name}" "${FLAGS_vxlan_id}" "${local_ip}" "${gateway_ip}" "${subnet}"
|
create_subnet "${FLAGS_vpc_name}" "${FLAGS_subnet_name}" "${FLAGS_vxlan_id}" "${local_ip}" "${gateway_ip}" "${subnet}"
|
||||||
# create volume
|
qemu_start_vm "${FLAGS_vm_ip}" "${FLAGS_subnet_name}" "${FLAGS_vpc_name}" "${FLAGS_vm_name}" "${FLAGS_volume_id}"
|
||||||
# create qemu
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function stop_vm {
|
function stop_vm {
|
||||||
|
|
|
||||||
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