diff --git a/lib/qemu.sh b/lib/qemu.sh index cec61db..8f0d1f6 100644 --- a/lib/qemu.sh +++ b/lib/qemu.sh @@ -35,24 +35,31 @@ function qemu_start_vm { 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}" - add_in_db "vm" "${vm_name}" "${subnet_name}" "${tap_id}" - create_tap "${tap_id}" "br-${subnet_id}" "${vpc_name}" + check_qemu_exist "${vm_name}" + [ "$?" -eq "0" ] && \ + { + print_in_color "${COLOR_ORANGE}" "Would have create ${vm_name}" + } || \ + { + print_in_color "${COLOR_GREEN}" "Create tap tap${tap_id}" + add_in_db "vm" "${vm_name}" "${subnet_name}" "${tap_id}" + create_tap "${tap_id}" "br-${subnet_id}" "${vpc_name}" - print_in_color "${COLOR_GREEN}" "Start vm ${vm_name}" - ip netns exec "${vpc_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" \ - -qmp "unix:/tmp/${vm_name}.qmp-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 + print_in_color "${COLOR_GREEN}" "Start vm ${vm_name}" + ip netns exec "${vpc_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" \ + -qmp "unix:/tmp/${vm_name}.qmp-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 + } } function qemu_stop_vm {