From eaeb75d858f45447c4b3d17f33b6183f95b98466 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Tue, 2 Feb 2021 10:42:07 +0100 Subject: [qemu] Rename 'qemukvm' core module to 'qemu' --- core/modules/qemu/data/addon-init | 8 ++ core/modules/qemu/data/etc/qemu/bridge.conf | 6 ++ .../system/graphical.target.wants/qemukvm.service | 1 + .../qemu/data/etc/systemd/system/qemukvm.service | 9 +++ .../data/opt/openslx/scripts/systemd-qemukvm_env | 28 +++++++ .../opt/openslx/vmchooser/plugins/qemukvm/README | 1 + .../includes/determine_hardware_limitations.inc | 89 ++++++++++++++++++++++ .../qemukvm/includes/finalize_start_command.inc | 49 ++++++++++++ .../plugins/qemukvm/includes/init_core.inc | 54 +++++++++++++ .../qemukvm/includes/log_config_summary.inc | 35 +++++++++ .../plugins/qemukvm/includes/setup_network.inc | 56 ++++++++++++++ .../plugins/qemukvm/includes/setup_rw_layer.inc | 25 ++++++ .../vmchooser/plugins/qemukvm/run-virt.include | 44 +++++++++++ core/modules/qemu/module.build | 18 +++++ core/modules/qemu/module.conf | 5 ++ core/modules/qemu/module.conf.debian | 15 ++++ core/modules/qemu/module.conf.ubuntu | 15 ++++ core/modules/qemukvm/data/addon-init | 8 -- core/modules/qemukvm/data/etc/qemu/bridge.conf | 6 -- .../system/graphical.target.wants/qemukvm.service | 1 - .../data/etc/systemd/system/qemukvm.service | 9 --- .../data/opt/openslx/scripts/systemd-qemukvm_env | 28 ------- .../opt/openslx/vmchooser/plugins/qemukvm/README | 1 - .../includes/determine_hardware_limitations.inc | 89 ---------------------- .../qemukvm/includes/finalize_start_command.inc | 49 ------------ .../plugins/qemukvm/includes/init_core.inc | 54 ------------- .../qemukvm/includes/log_config_summary.inc | 35 --------- .../plugins/qemukvm/includes/setup_network.inc | 56 -------------- .../plugins/qemukvm/includes/setup_rw_layer.inc | 25 ------ .../vmchooser/plugins/qemukvm/run-virt.include | 44 ----------- core/modules/qemukvm/module.build | 18 ----- core/modules/qemukvm/module.conf | 5 -- core/modules/qemukvm/module.conf.debian | 15 ---- core/modules/qemukvm/module.conf.ubuntu | 15 ---- 34 files changed, 458 insertions(+), 458 deletions(-) create mode 100755 core/modules/qemu/data/addon-init create mode 100644 core/modules/qemu/data/etc/qemu/bridge.conf create mode 120000 core/modules/qemu/data/etc/systemd/system/graphical.target.wants/qemukvm.service create mode 100644 core/modules/qemu/data/etc/systemd/system/qemukvm.service create mode 100755 core/modules/qemu/data/opt/openslx/scripts/systemd-qemukvm_env create mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/README create mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/determine_hardware_limitations.inc create mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/finalize_start_command.inc create mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/init_core.inc create mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/log_config_summary.inc create mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_network.inc create mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_rw_layer.inc create mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include create mode 100644 core/modules/qemu/module.build create mode 100644 core/modules/qemu/module.conf create mode 100644 core/modules/qemu/module.conf.debian create mode 100644 core/modules/qemu/module.conf.ubuntu delete mode 100755 core/modules/qemukvm/data/addon-init delete mode 100644 core/modules/qemukvm/data/etc/qemu/bridge.conf delete mode 120000 core/modules/qemukvm/data/etc/systemd/system/graphical.target.wants/qemukvm.service delete mode 100644 core/modules/qemukvm/data/etc/systemd/system/qemukvm.service delete mode 100755 core/modules/qemukvm/data/opt/openslx/scripts/systemd-qemukvm_env delete mode 100644 core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/README delete mode 100644 core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/includes/determine_hardware_limitations.inc delete mode 100644 core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/includes/finalize_start_command.inc delete mode 100644 core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/includes/init_core.inc delete mode 100644 core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/includes/log_config_summary.inc delete mode 100644 core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_network.inc delete mode 100644 core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_rw_layer.inc delete mode 100644 core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include delete mode 100644 core/modules/qemukvm/module.build delete mode 100644 core/modules/qemukvm/module.conf delete mode 100644 core/modules/qemukvm/module.conf.debian delete mode 100644 core/modules/qemukvm/module.conf.ubuntu diff --git a/core/modules/qemu/data/addon-init b/core/modules/qemu/data/addon-init new file mode 100755 index 00000000..cccc1e8a --- /dev/null +++ b/core/modules/qemu/data/addon-init @@ -0,0 +1,8 @@ +#!/bin/ash + +systemctl daemon-reload +systemctl start qemukvm.service + +# this seems to be necessary due to the misbehaviour of udevd +# in view of the undetected ENV dev_type +systemctl restart systemd-udevd diff --git a/core/modules/qemu/data/etc/qemu/bridge.conf b/core/modules/qemu/data/etc/qemu/bridge.conf new file mode 100644 index 00000000..b8478434 --- /dev/null +++ b/core/modules/qemu/data/etc/qemu/bridge.conf @@ -0,0 +1,6 @@ +# These needs to be compatible with the +# bridge's names generated by +# /opt/openslx/scripts/systemd-run_virt_env +allow br0 +allow nat1 +allow vsw2 diff --git a/core/modules/qemu/data/etc/systemd/system/graphical.target.wants/qemukvm.service b/core/modules/qemu/data/etc/systemd/system/graphical.target.wants/qemukvm.service new file mode 120000 index 00000000..89d8afbf --- /dev/null +++ b/core/modules/qemu/data/etc/systemd/system/graphical.target.wants/qemukvm.service @@ -0,0 +1 @@ +../qemukvm.service \ No newline at end of file diff --git a/core/modules/qemu/data/etc/systemd/system/qemukvm.service b/core/modules/qemu/data/etc/systemd/system/qemukvm.service new file mode 100644 index 00000000..f1f3dec6 --- /dev/null +++ b/core/modules/qemu/data/etc/systemd/system/qemukvm.service @@ -0,0 +1,9 @@ +[Unit] +Description=Sets up the virtual box environment +Requires=run-virt-env.service +After=run-virt-env.service + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/opt/openslx/scripts/systemd-qemukvm_env start diff --git a/core/modules/qemu/data/opt/openslx/scripts/systemd-qemukvm_env b/core/modules/qemu/data/opt/openslx/scripts/systemd-qemukvm_env new file mode 100755 index 00000000..631c159f --- /dev/null +++ b/core/modules/qemu/data/opt/openslx/scripts/systemd-qemukvm_env @@ -0,0 +1,28 @@ +#!/bin/ash +# ----------------------------------------------------------------------------- +# +# Copyright (c) 2017..2018 bwLehrpool-Projektteam +# +# This program/file is free software distributed under the GPL version 2. +# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html +# +# If you have any feedback please consult https://bwlehrpool.de and +# send your feedback to bwlehrpool@hs-offenburg.de. +# +# General information about bwLehrpool can be found at https://bwlehrpool.de +# +# ----------------------------------------------------------------------------- +# systemd-qemukvm_env +# - This is the preparation script for the configuration of Linux Qemu/KVM. +################################################################################ + +# lazy load all kvm related modules +modprobe kvm +modprobe kvm_amd +modprobe kvm_intel + +if [ ! -e /dev/kvm ]; then + slxlog "qemukvm-modules" "/dev/kvm not found! Missing kvm kernel module(s)?" + exit 1 +fi + diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/README b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/README new file mode 100644 index 00000000..549d0037 --- /dev/null +++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/README @@ -0,0 +1 @@ +Not tested since refactoring! (January 2017) diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/determine_hardware_limitations.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/determine_hardware_limitations.inc new file mode 100644 index 00000000..dd83b587 --- /dev/null +++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/determine_hardware_limitations.inc @@ -0,0 +1,89 @@ +################################################################## +# qemu/kvm include: determine virtual hardware based on guest OS # +################################################################## + +set_vm_hw_limits() { + # FIXME when we have better metadata for qemu + if isempty VM_OS_TYPE; then + writelog "VM_OS_TYPE is empty! This should have been parsed from the XML file" + EXIT_TYPE="user" EXIT_REASON="Konnte Gastbetriebsystems der virtuellen Maschine nicht ermitteln!" cleanexit 1 + fi + + # define global hardware-related variables + declare -g MAXMEM="9999999" + declare -g MAXCORES="4" + declare -g SOUND_DEV="es1370" + + # determine if we need a 32bit or 64bit machine + # FIXME depending on the guest OS for now + # (sadly does not support all the exotic OSs the + # the world has even seen like vmware plugin :<) + local bits=64 + case "${VM_OS_TYPE}" in + beos*) + bits=32 + SOUND_DEV="sb16" + ;; + win3*|win*3*|Win*3*) + bits=32 + SOUND_DEV="sb16" + MAXMEM=32 + ;; + win95*|Win*95) + bits=32 + MAXMEM=96 + ;; + win98) + bits=32 + MAXMEM=256 + ;; + winme*|windowsme*) + bits=32 + SOUND_DEV="ac97" + MAXMEM=384 + ;; + winxp*64|windowsxp*64) + SOUND_DEV="ac97" + ;; + windows7|windows8|windows9) + SOUND_DEV="ac97" + MAXMEM="8000" + MAXCORES="4" + ;; + windows7-64|windows8-64|windows9-64) + SOUND_DEV="ac97" + MAXMEM="32000" + MAXCORES="8" + ;; + *64) + MAXMEM="16000" + MAXCORES="4" + ;; + *) + bits=32 + MAXMEM="8000" + MAXCORES="1" + ;; + esac + declare -g VIRTCMD + if [ "$bits" = 32 ]; then + declare -rg VIRTCMD="qemu-system-i386" + VIRTCMDOPTS+=( "-machine" "accel=tcg" ) # TODO: 32bit VMs can't use kvm!? + else # 64 bit + declare -rg VIRTCMD="qemu-system-x86_64" + VIRTCMDOPTS+=( "-machine" "accel=kvm" ) + fi + + + # check for allocated cores + declare -g CPU_CORES="${HW_THREADS:-1}" + declare -rg HOST_CORE_COUNT="${CPU_CORES}" + [ "${CPU_CORES}" -gt "${MAXCORES}" ] && CPU_CORES="${MAXCORES}" + + # check if memory set by the generic run-virt is above the threshold + [ "${VM_MEM}" -gt "${MAXMEM}" ] && VM_MEM="${MAXMEM}" + return 0 +} + +## MAIN ## +call_post_source set_vm_hw_limits diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/finalize_start_command.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/finalize_start_command.inc new file mode 100644 index 00000000..6d9df363 --- /dev/null +++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/finalize_start_command.inc @@ -0,0 +1,49 @@ +# ----------------------------------------------------------------------------- +# +# Copyright (c) 2009..2018 bwLehrpool-Projektteam +# +# This program/file is free software distributed under the GPL version 2. +# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html +# +# If you have any feedback please consult https://bwlehrpool.de and +# send your feedback to bwlehrpool@hs-offenburg.de. +# +# General information about bwLehrpool can be found at https://bwlehrpool.de +# +# ----------------------------------------------------------------------------- +# run-virt.include +# - Include script for running the QEMU/Linux KVM virtual machine on an +# OpenSLX client via the run-virt.sh or run-vmgrid.sh +################################################################################ + +# set options that depend on previous includes +# and build the final start command +finalize_start_command() { + + # set cpu type + VIRTCMDOPTS+=( "-cpu" "host" ) + # set cpu cores + VIRTCMDOPTS+=( "-smp" "${CPU_CORES}" ) + + # set RAM + VIRTCMDOPTS+=( "-m" "${VM_MEM}" ) + + # special feature for real and virtual floppy disks + isset FLOPPY_0 && VIRTCMDOPTS+=( "-fda" "${FLOPPY_0}" ) + isset SLX_FLOPPY_IMG && VIRTCMDOPTS+=( "-fdb" "${SLX_FLOPPY_IMG}" ) + + # add optical drive if available + isset CDROM_0 && VIRTCMDOPTS+=( "-cdrom" "${CDROM_0}" ) + + # audio + isset SOUND_DEV && VIRTCMDOPTS+=( "-soundhw" "${SOUND_DEV}" ) + + # serial devices TODO test + if isset SERIAL_PORTS; then + for DEV in $SERIAL_PORTS; do + : # buggeh: VIRTCMDOPTS+=( "-serial" "${DEV}" ) + done + fi +} + +call_post_source finalize_start_command diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/init_core.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/init_core.inc new file mode 100644 index 00000000..fee2cd1c --- /dev/null +++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/init_core.inc @@ -0,0 +1,54 @@ +# ----------------------------------------------------------------------------- +# +# Copyright (c) 2009..2018 bwLehrpool-Projektteam +# +# This program/file is free software distributed under the GPL version 2. +# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html +# +# If you have any feedback please consult https://bwlehrpool.de and +# send your feedback to bwlehrpool@hs-offenburg.de. +# +# General information about bwLehrpool can be found at https://bwlehrpool.de +# +# ----------------------------------------------------------------------------- +# run-virt.include +# - Include script for running the QEMU/Linux KVM virtual machine on an +# OpenSLX client via the run-virt.sh or run-vmgrid.sh +################################################################################ + +# check if kvm kernel module are available +if [ ! -c /dev/kvm ]; then + writelog "KVM kernel modules not loaded!" + EXIT_TYPE="internal" EXIT_REASON="QEMU/KVM Virtualisierer nicht initialisiert!" cleanexit 1 +fi + +# check if qemu binaries are available +if ! check_dep qemu-system-{i386,x86_64}; then + writelog "QEMU binaries not available!" + EXIT_TYPE="internal" EXIT_REASON="QEMU/KVM Virtualisierer nicht initialisiert!" cleanexit 1 +fi + +# set general purpose options here, mostly evaluates information +# contained in /opt/openslx/vmchooser/config/virtualization.conf + +# TODO some options should come from the server, in particular +# - disk controller type (virtio, scsi, ide...) +# - arch to emulate (x86_64, i386, ...) +# - graphics mode? +# - sound dev? +# - tbd + +# display name, remove blanks because of cmdline problems +declare -rg CMD_DISPLAYNAME=$(echo ${VM_DISPLAYNAME} | sed -e "s, ,-,g;s,(,[,g;s,),],g") +VIRTCMDOPTS+=( "-name" "${CMD_DISPLAYNAME}" ) + +# graphical start: vga, vmware, qxl, spice? +VIRTCMDOPTS+=( "-vga" "std" "-full-screen" ) + +# hot keys ALT+CTRL+SHIFT (does not work properly!?) +VIRTCMDOPTS+=( "-alt-grab" ) + +# TODO support other types of boot? any usecase for network boot? +# for now just boot from disk +VIRTCMDOPTS+=( "-boot" "c" ) + diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/log_config_summary.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/log_config_summary.inc new file mode 100644 index 00000000..6b4b279f --- /dev/null +++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/log_config_summary.inc @@ -0,0 +1,35 @@ +################################################## +# Include: Print vm config summary into log file # +################################################## + +log_config_summary() { + writelog "Directories:" + writelog "\tTMPDIR:\t\t\t$TMPDIR" + writelog "Disk image:" + writelog "\tSource disk:\t\t$VM_DISKFILE_RO" + if [ -e "${VM_DISKFILE_RW}" ]; then + writelog "\tDisk mode:\t\twritable" + writelog "\tRW-Layer:\t\t$VM_DISKFILE_RW" + else + writelog "\tDisk mode:\t\tread-only" + fi + + writelog "Virtual Hardware:" + writelog "\tvCPU cores:\t\t${CPU_CORES}" + writelog "\tGuest RAM:\t\t${VM_MEM} MB" + + # echo nur wenn HOST_MEM_REMAINING gesetzt + if isset HOST_MEM_REMAINING; then + writelog "\tHost RAM:\t\t${HOST_MEM_REMAINING} MB" + fi + writelog "\tMAC address:\t\t${VM_MAC_ADDR}" + writelog "\tNetwork card:\t\t${NIC_MODEL}" + writelog "\tNetwork kind:\t\t${NETWORK_MODE}" + writelog "\tCD-ROM1:\t${CDROM_0}" + writelog "\tCD-ROM2:\t${CDROM_1}" + writelog "\tFloppy_A:\t${FLOPPY_0}" + writelog "\tFloppy_B:\t${SLX_FLOPPY_IMG}" + #writelog "\tShared Folders 'home':\t/home/${USER}" +} + +call_post_source log_config_summary diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_network.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_network.inc new file mode 100644 index 00000000..73fb2518 --- /dev/null +++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_network.inc @@ -0,0 +1,56 @@ +################################### +# qemu/kvm include: Network setup # +################################### +# This now makes use of the qemu's bridge helper +# which creates a tap device and adds it to the +# bridge corresponding to the network type +# TODO configurable network type +setup_network() { + # list available models with: + # qemu-system-x86_64 -net nic,model=? + # e.g. as of 2.0.0: + # ne2k_pci,i82551,i82557b,i82559er,rtl8139,e1000,pcnet,virtio + declare -rg NIC_MODEL="e1000" + + # add MAC address and network card model + VIRTCMDOPTS+=( "-device" "${NIC_MODEL},mac=${VM_MAC_ADDR},netdev=guestnet0" ) + + # TODO support different network kinds for lectures in bwlehrpool-suite, just NAT for now + declare -g NETWORK_MODE="nat" + + # detect if qemu's bridge helper binary is available + declare -g QEMU_BRIDGE_HELPER= + for HELPER_PATH in /usr/lib/qemu-bridge-helper /usr/local/libexec/qemu-bridge-helper; do + if [ -x "${HELPER_PATH}" ] && [ -u "${HELPER_PATH}" ]; then + QEMU_BRIDGE_HELPER="${HELPER_PATH}" + readonly QEMU_BRIDGE_HELPER + break + fi + done + if isempty QEMU_BRIDGE_HELPER; then + writelog "Could not find qemu-bridge-helper on this machine. Setting network mode to user." + # Even though falling back to creating tap devices ourselves, we should instead + # garantee the existance of qemu's helper on minilinux build time. + # qemu's user network mode allows tcp/udp connections in a nat-fashion and + # it allows access to the web which seems suffisant for a fallback. + NETWORK_MODE="user" + fi + + case "${NETWORK_MODE}" in + nat*) + VIRTCMDOPTS+=( "-netdev" "bridge,br=nat1,id=guestnet0,helper=${QEMU_BRIDGE_HELPER}" ) + ;; + bridge*) + VIRTCMDOPTS+=( "-netdev" "bridge,br=br0,id=guestnet0,helper=${QEMU_BRIDGE_HELPER}" ) + ;; + host*) + VIRTCMDOPTS+=( "-netdev" "bridge,br=vsw2,id=guestnet0,helper=${QEMU_BRIDGE_HELPER}" ) + ;; + user*|*) + VIRTCMDOPTS+=( "-netdev" "user,id=guestnet0" ) + ;; + esac +} + +## MAIN ## +call_post_source setup_network diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_rw_layer.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_rw_layer.inc new file mode 100644 index 00000000..32637e5d --- /dev/null +++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_rw_layer.inc @@ -0,0 +1,25 @@ + +setup_rw_layer() { + if isempty VM_DISKFILE_RO; then + writelog "No source diskfile found! This should be specified in the given XML file. Is it valid?" + EXIT_TYPE="user" EXIT_REASON="Keine virtuelle Festplatte zu dieser Veranstaltung angegeben!" cleanexit 1 + fi + + # setup qcow2 backing file for that disk file + writelog "Creating backing file for '${VM_DISKFILE_RO}'..." + # TODO: WTF? This is fucked up, VM_DISKFILE_RW is set if we want to run in persistent mode, + # this plugin shouldn't mess around with it.... + declare -rg VM_DISKFILE_RW="${TMPDIR}/$(basename ${VM_DISKFILE_RO}).qcow2" + if qemu-img create -f qcow2 -b "${VM_DISKFILE_RO}" "${VM_DISKFILE_RW}"; then + # all good, use it as main disk drive + # TODO: determine the proper type of controller to use, ideally virtio? + VIRTCMDOPTS+=("-drive" "if=virtio,format=qcow2,file=${VM_DISKFILE_RW}" ) + else + writelog "Error creating backing file for '${VM_DISKFILE_RO}'" + # TODO use -snapshot as fallback, test it! + # How is this supposed to even work without a disk? + VIRTCMDOPTS+=( "-snapshot" ) + fi +} + +call_post_source setup_rw_layer diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include new file mode 100644 index 00000000..7d1149b0 --- /dev/null +++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include @@ -0,0 +1,44 @@ +# ----------------------------------------------------------------------------- +# +# Copyright (c) 2009..2018 bwLehrpool-Projektteam +# +# This program/file is free software distributed under the GPL version 2. +# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html +# +# If you have any feedback please consult https://bwlehrpool.de and +# send your feedback to bwlehrpool@hs-offenburg.de. +# +# General information about bwLehrpool can be found at https://bwlehrpool.de +# +# ----------------------------------------------------------------------------- +# run-virt.include +# - qemu/kvm plugin for vmchooser run-virt +################################################################################ + +# BASH_SOURCE[0] contains the file being sourced, namely this one +declare -rg QEMUKVM_PLUGIN_DIR="$(dirname "${BASH_SOURCE[0]}")" +declare -rg QEMUKVM_INCLUDE_DIR="${QEMUKVM_PLUGIN_DIR}/includes" + +# TODO make this part of the metadata coming from the server +# TBD: "firewall printer usb slxfloppy sound netshares" +declare -rg PLUGIN_FEATURES="slxfloppy" + +run_plugin() { + # declaration of default functions and variables for vmware + $(safesource --exit "${QEMUKVM_INCLUDE_DIR}/init_core.inc") + + # determine limitations wrt RAM and CPU count of VM + $(safesource "${QEMUKVM_INCLUDE_DIR}/determine_hardware_limitations.inc") + + # setup networking + $(safesource "${QEMUKVM_INCLUDE_DIR}/setup_network.inc") + + # setup rw layer for ro image + $(safesource "${QEMUKVM_INCLUDE_DIR}/setup_rw_layer.inc") + + # build the final start command + $(safesource "${QEMUKVM_INCLUDE_DIR}/finalize_start_command.inc") + + # print summary - needs writelog() from vmchooser-run_virt + $(safesource "${QEMUKVM_INCLUDE_DIR}/log_config_summary.inc") +} diff --git a/core/modules/qemu/module.build b/core/modules/qemu/module.build new file mode 100644 index 00000000..f2a0df9e --- /dev/null +++ b/core/modules/qemu/module.build @@ -0,0 +1,18 @@ +#!/bin/bash +fetch_source() { + : +} + +build() { + COPYLIST="list_dpkg_output" + [ -e "$COPYLIST" ] && rm "$COPYLIST" + list_packet_files >> "$COPYLIST" + + + tarcopy "$(cat "${COPYLIST}" | sort -u)" "${MODULE_BUILD_DIR}" +} + +post_copy() { + # qemu-bridge-helper needs suid to be called within run-virt + find ${TARGET_BUILD_DIR} -type f -executable -name "*qemu-bridge-helper*" -exec chmod u+s {} \; +} diff --git a/core/modules/qemu/module.conf b/core/modules/qemu/module.conf new file mode 100644 index 00000000..0cf394cf --- /dev/null +++ b/core/modules/qemu/module.conf @@ -0,0 +1,5 @@ +#!/bin/bash +REQUIRED_MODULES="" +REQUIRED_DIRECTORIES=" + / +" diff --git a/core/modules/qemu/module.conf.debian b/core/modules/qemu/module.conf.debian new file mode 100644 index 00000000..4773a871 --- /dev/null +++ b/core/modules/qemu/module.conf.debian @@ -0,0 +1,15 @@ +#!/bin/bash +REQUIRED_INSTALLED_PACKAGES=" + qemu + qemu-kvm +" + +REQUIRED_CONTENT_PACKAGES=" + qemu + qemu-kvm + qemu-system-common + qemu-system-x86 + qemu-user + qemu-utils + seabios +" diff --git a/core/modules/qemu/module.conf.ubuntu b/core/modules/qemu/module.conf.ubuntu new file mode 100644 index 00000000..4773a871 --- /dev/null +++ b/core/modules/qemu/module.conf.ubuntu @@ -0,0 +1,15 @@ +#!/bin/bash +REQUIRED_INSTALLED_PACKAGES=" + qemu + qemu-kvm +" + +REQUIRED_CONTENT_PACKAGES=" + qemu + qemu-kvm + qemu-system-common + qemu-system-x86 + qemu-user + qemu-utils + seabios +" diff --git a/core/modules/qemukvm/data/addon-init b/core/modules/qemukvm/data/addon-init deleted file mode 100755 index cccc1e8a..00000000 --- a/core/modules/qemukvm/data/addon-init +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/ash - -systemctl daemon-reload -systemctl start qemukvm.service - -# this seems to be necessary due to the misbehaviour of udevd -# in view of the undetected ENV dev_type -systemctl restart systemd-udevd diff --git a/core/modules/qemukvm/data/etc/qemu/bridge.conf b/core/modules/qemukvm/data/etc/qemu/bridge.conf deleted file mode 100644 index b8478434..00000000 --- a/core/modules/qemukvm/data/etc/qemu/bridge.conf +++ /dev/null @@ -1,6 +0,0 @@ -# These needs to be compatible with the -# bridge's names generated by -# /opt/openslx/scripts/systemd-run_virt_env -allow br0 -allow nat1 -allow vsw2 diff --git a/core/modules/qemukvm/data/etc/systemd/system/graphical.target.wants/qemukvm.service b/core/modules/qemukvm/data/etc/systemd/system/graphical.target.wants/qemukvm.service deleted file mode 120000 index 89d8afbf..00000000 --- a/core/modules/qemukvm/data/etc/systemd/system/graphical.target.wants/qemukvm.service +++ /dev/null @@ -1 +0,0 @@ -../qemukvm.service \ No newline at end of file diff --git a/core/modules/qemukvm/data/etc/systemd/system/qemukvm.service b/core/modules/qemukvm/data/etc/systemd/system/qemukvm.service deleted file mode 100644 index f1f3dec6..00000000 --- a/core/modules/qemukvm/data/etc/systemd/system/qemukvm.service +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=Sets up the virtual box environment -Requires=run-virt-env.service -After=run-virt-env.service - -[Service] -Type=oneshot -RemainAfterExit=yes -ExecStart=/opt/openslx/scripts/systemd-qemukvm_env start diff --git a/core/modules/qemukvm/data/opt/openslx/scripts/systemd-qemukvm_env b/core/modules/qemukvm/data/opt/openslx/scripts/systemd-qemukvm_env deleted file mode 100755 index 631c159f..00000000 --- a/core/modules/qemukvm/data/opt/openslx/scripts/systemd-qemukvm_env +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/ash -# ----------------------------------------------------------------------------- -# -# Copyright (c) 2017..2018 bwLehrpool-Projektteam -# -# This program/file is free software distributed under the GPL version 2. -# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html -# -# If you have any feedback please consult https://bwlehrpool.de and -# send your feedback to bwlehrpool@hs-offenburg.de. -# -# General information about bwLehrpool can be found at https://bwlehrpool.de -# -# ----------------------------------------------------------------------------- -# systemd-qemukvm_env -# - This is the preparation script for the configuration of Linux Qemu/KVM. -################################################################################ - -# lazy load all kvm related modules -modprobe kvm -modprobe kvm_amd -modprobe kvm_intel - -if [ ! -e /dev/kvm ]; then - slxlog "qemukvm-modules" "/dev/kvm not found! Missing kvm kernel module(s)?" - exit 1 -fi - diff --git a/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/README b/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/README deleted file mode 100644 index 549d0037..00000000 --- a/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/README +++ /dev/null @@ -1 +0,0 @@ -Not tested since refactoring! (January 2017) diff --git a/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/includes/determine_hardware_limitations.inc b/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/includes/determine_hardware_limitations.inc deleted file mode 100644 index dd83b587..00000000 --- a/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/includes/determine_hardware_limitations.inc +++ /dev/null @@ -1,89 +0,0 @@ -################################################################## -# qemu/kvm include: determine virtual hardware based on guest OS # -################################################################## - -set_vm_hw_limits() { - # FIXME when we have better metadata for qemu - if isempty VM_OS_TYPE; then - writelog "VM_OS_TYPE is empty! This should have been parsed from the XML file" - EXIT_TYPE="user" EXIT_REASON="Konnte Gastbetriebsystems der virtuellen Maschine nicht ermitteln!" cleanexit 1 - fi - - # define global hardware-related variables - declare -g MAXMEM="9999999" - declare -g MAXCORES="4" - declare -g SOUND_DEV="es1370" - - # determine if we need a 32bit or 64bit machine - # FIXME depending on the guest OS for now - # (sadly does not support all the exotic OSs the - # the world has even seen like vmware plugin :<) - local bits=64 - case "${VM_OS_TYPE}" in - beos*) - bits=32 - SOUND_DEV="sb16" - ;; - win3*|win*3*|Win*3*) - bits=32 - SOUND_DEV="sb16" - MAXMEM=32 - ;; - win95*|Win*95) - bits=32 - MAXMEM=96 - ;; - win98) - bits=32 - MAXMEM=256 - ;; - winme*|windowsme*) - bits=32 - SOUND_DEV="ac97" - MAXMEM=384 - ;; - winxp*64|windowsxp*64) - SOUND_DEV="ac97" - ;; - windows7|windows8|windows9) - SOUND_DEV="ac97" - MAXMEM="8000" - MAXCORES="4" - ;; - windows7-64|windows8-64|windows9-64) - SOUND_DEV="ac97" - MAXMEM="32000" - MAXCORES="8" - ;; - *64) - MAXMEM="16000" - MAXCORES="4" - ;; - *) - bits=32 - MAXMEM="8000" - MAXCORES="1" - ;; - esac - declare -g VIRTCMD - if [ "$bits" = 32 ]; then - declare -rg VIRTCMD="qemu-system-i386" - VIRTCMDOPTS+=( "-machine" "accel=tcg" ) # TODO: 32bit VMs can't use kvm!? - else # 64 bit - declare -rg VIRTCMD="qemu-system-x86_64" - VIRTCMDOPTS+=( "-machine" "accel=kvm" ) - fi - - - # check for allocated cores - declare -g CPU_CORES="${HW_THREADS:-1}" - declare -rg HOST_CORE_COUNT="${CPU_CORES}" - [ "${CPU_CORES}" -gt "${MAXCORES}" ] && CPU_CORES="${MAXCORES}" - - # check if memory set by the generic run-virt is above the threshold - [ "${VM_MEM}" -gt "${MAXMEM}" ] && VM_MEM="${MAXMEM}" - return 0 -} - -## MAIN ## -call_post_source set_vm_hw_limits diff --git a/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/includes/finalize_start_command.inc b/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/includes/finalize_start_command.inc deleted file mode 100644 index 6d9df363..00000000 --- a/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/includes/finalize_start_command.inc +++ /dev/null @@ -1,49 +0,0 @@ -# ----------------------------------------------------------------------------- -# -# Copyright (c) 2009..2018 bwLehrpool-Projektteam -# -# This program/file is free software distributed under the GPL version 2. -# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html -# -# If you have any feedback please consult https://bwlehrpool.de and -# send your feedback to bwlehrpool@hs-offenburg.de. -# -# General information about bwLehrpool can be found at https://bwlehrpool.de -# -# ----------------------------------------------------------------------------- -# run-virt.include -# - Include script for running the QEMU/Linux KVM virtual machine on an -# OpenSLX client via the run-virt.sh or run-vmgrid.sh -################################################################################ - -# set options that depend on previous includes -# and build the final start command -finalize_start_command() { - - # set cpu type - VIRTCMDOPTS+=( "-cpu" "host" ) - # set cpu cores - VIRTCMDOPTS+=( "-smp" "${CPU_CORES}" ) - - # set RAM - VIRTCMDOPTS+=( "-m" "${VM_MEM}" ) - - # special feature for real and virtual floppy disks - isset FLOPPY_0 && VIRTCMDOPTS+=( "-fda" "${FLOPPY_0}" ) - isset SLX_FLOPPY_IMG && VIRTCMDOPTS+=( "-fdb" "${SLX_FLOPPY_IMG}" ) - - # add optical drive if available - isset CDROM_0 && VIRTCMDOPTS+=( "-cdrom" "${CDROM_0}" ) - - # audio - isset SOUND_DEV && VIRTCMDOPTS+=( "-soundhw" "${SOUND_DEV}" ) - - # serial devices TODO test - if isset SERIAL_PORTS; then - for DEV in $SERIAL_PORTS; do - : # buggeh: VIRTCMDOPTS+=( "-serial" "${DEV}" ) - done - fi -} - -call_post_source finalize_start_command diff --git a/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/includes/init_core.inc b/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/includes/init_core.inc deleted file mode 100644 index fee2cd1c..00000000 --- a/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/includes/init_core.inc +++ /dev/null @@ -1,54 +0,0 @@ -# ----------------------------------------------------------------------------- -# -# Copyright (c) 2009..2018 bwLehrpool-Projektteam -# -# This program/file is free software distributed under the GPL version 2. -# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html -# -# If you have any feedback please consult https://bwlehrpool.de and -# send your feedback to bwlehrpool@hs-offenburg.de. -# -# General information about bwLehrpool can be found at https://bwlehrpool.de -# -# ----------------------------------------------------------------------------- -# run-virt.include -# - Include script for running the QEMU/Linux KVM virtual machine on an -# OpenSLX client via the run-virt.sh or run-vmgrid.sh -################################################################################ - -# check if kvm kernel module are available -if [ ! -c /dev/kvm ]; then - writelog "KVM kernel modules not loaded!" - EXIT_TYPE="internal" EXIT_REASON="QEMU/KVM Virtualisierer nicht initialisiert!" cleanexit 1 -fi - -# check if qemu binaries are available -if ! check_dep qemu-system-{i386,x86_64}; then - writelog "QEMU binaries not available!" - EXIT_TYPE="internal" EXIT_REASON="QEMU/KVM Virtualisierer nicht initialisiert!" cleanexit 1 -fi - -# set general purpose options here, mostly evaluates information -# contained in /opt/openslx/vmchooser/config/virtualization.conf - -# TODO some options should come from the server, in particular -# - disk controller type (virtio, scsi, ide...) -# - arch to emulate (x86_64, i386, ...) -# - graphics mode? -# - sound dev? -# - tbd - -# display name, remove blanks because of cmdline problems -declare -rg CMD_DISPLAYNAME=$(echo ${VM_DISPLAYNAME} | sed -e "s, ,-,g;s,(,[,g;s,),],g") -VIRTCMDOPTS+=( "-name" "${CMD_DISPLAYNAME}" ) - -# graphical start: vga, vmware, qxl, spice? -VIRTCMDOPTS+=( "-vga" "std" "-full-screen" ) - -# hot keys ALT+CTRL+SHIFT (does not work properly!?) -VIRTCMDOPTS+=( "-alt-grab" ) - -# TODO support other types of boot? any usecase for network boot? -# for now just boot from disk -VIRTCMDOPTS+=( "-boot" "c" ) - diff --git a/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/includes/log_config_summary.inc b/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/includes/log_config_summary.inc deleted file mode 100644 index 6b4b279f..00000000 --- a/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/includes/log_config_summary.inc +++ /dev/null @@ -1,35 +0,0 @@ -################################################## -# Include: Print vm config summary into log file # -################################################## - -log_config_summary() { - writelog "Directories:" - writelog "\tTMPDIR:\t\t\t$TMPDIR" - writelog "Disk image:" - writelog "\tSource disk:\t\t$VM_DISKFILE_RO" - if [ -e "${VM_DISKFILE_RW}" ]; then - writelog "\tDisk mode:\t\twritable" - writelog "\tRW-Layer:\t\t$VM_DISKFILE_RW" - else - writelog "\tDisk mode:\t\tread-only" - fi - - writelog "Virtual Hardware:" - writelog "\tvCPU cores:\t\t${CPU_CORES}" - writelog "\tGuest RAM:\t\t${VM_MEM} MB" - - # echo nur wenn HOST_MEM_REMAINING gesetzt - if isset HOST_MEM_REMAINING; then - writelog "\tHost RAM:\t\t${HOST_MEM_REMAINING} MB" - fi - writelog "\tMAC address:\t\t${VM_MAC_ADDR}" - writelog "\tNetwork card:\t\t${NIC_MODEL}" - writelog "\tNetwork kind:\t\t${NETWORK_MODE}" - writelog "\tCD-ROM1:\t${CDROM_0}" - writelog "\tCD-ROM2:\t${CDROM_1}" - writelog "\tFloppy_A:\t${FLOPPY_0}" - writelog "\tFloppy_B:\t${SLX_FLOPPY_IMG}" - #writelog "\tShared Folders 'home':\t/home/${USER}" -} - -call_post_source log_config_summary diff --git a/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_network.inc b/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_network.inc deleted file mode 100644 index 73fb2518..00000000 --- a/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_network.inc +++ /dev/null @@ -1,56 +0,0 @@ -################################### -# qemu/kvm include: Network setup # -################################### -# This now makes use of the qemu's bridge helper -# which creates a tap device and adds it to the -# bridge corresponding to the network type -# TODO configurable network type -setup_network() { - # list available models with: - # qemu-system-x86_64 -net nic,model=? - # e.g. as of 2.0.0: - # ne2k_pci,i82551,i82557b,i82559er,rtl8139,e1000,pcnet,virtio - declare -rg NIC_MODEL="e1000" - - # add MAC address and network card model - VIRTCMDOPTS+=( "-device" "${NIC_MODEL},mac=${VM_MAC_ADDR},netdev=guestnet0" ) - - # TODO support different network kinds for lectures in bwlehrpool-suite, just NAT for now - declare -g NETWORK_MODE="nat" - - # detect if qemu's bridge helper binary is available - declare -g QEMU_BRIDGE_HELPER= - for HELPER_PATH in /usr/lib/qemu-bridge-helper /usr/local/libexec/qemu-bridge-helper; do - if [ -x "${HELPER_PATH}" ] && [ -u "${HELPER_PATH}" ]; then - QEMU_BRIDGE_HELPER="${HELPER_PATH}" - readonly QEMU_BRIDGE_HELPER - break - fi - done - if isempty QEMU_BRIDGE_HELPER; then - writelog "Could not find qemu-bridge-helper on this machine. Setting network mode to user." - # Even though falling back to creating tap devices ourselves, we should instead - # garantee the existance of qemu's helper on minilinux build time. - # qemu's user network mode allows tcp/udp connections in a nat-fashion and - # it allows access to the web which seems suffisant for a fallback. - NETWORK_MODE="user" - fi - - case "${NETWORK_MODE}" in - nat*) - VIRTCMDOPTS+=( "-netdev" "bridge,br=nat1,id=guestnet0,helper=${QEMU_BRIDGE_HELPER}" ) - ;; - bridge*) - VIRTCMDOPTS+=( "-netdev" "bridge,br=br0,id=guestnet0,helper=${QEMU_BRIDGE_HELPER}" ) - ;; - host*) - VIRTCMDOPTS+=( "-netdev" "bridge,br=vsw2,id=guestnet0,helper=${QEMU_BRIDGE_HELPER}" ) - ;; - user*|*) - VIRTCMDOPTS+=( "-netdev" "user,id=guestnet0" ) - ;; - esac -} - -## MAIN ## -call_post_source setup_network diff --git a/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_rw_layer.inc b/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_rw_layer.inc deleted file mode 100644 index 32637e5d..00000000 --- a/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_rw_layer.inc +++ /dev/null @@ -1,25 +0,0 @@ - -setup_rw_layer() { - if isempty VM_DISKFILE_RO; then - writelog "No source diskfile found! This should be specified in the given XML file. Is it valid?" - EXIT_TYPE="user" EXIT_REASON="Keine virtuelle Festplatte zu dieser Veranstaltung angegeben!" cleanexit 1 - fi - - # setup qcow2 backing file for that disk file - writelog "Creating backing file for '${VM_DISKFILE_RO}'..." - # TODO: WTF? This is fucked up, VM_DISKFILE_RW is set if we want to run in persistent mode, - # this plugin shouldn't mess around with it.... - declare -rg VM_DISKFILE_RW="${TMPDIR}/$(basename ${VM_DISKFILE_RO}).qcow2" - if qemu-img create -f qcow2 -b "${VM_DISKFILE_RO}" "${VM_DISKFILE_RW}"; then - # all good, use it as main disk drive - # TODO: determine the proper type of controller to use, ideally virtio? - VIRTCMDOPTS+=("-drive" "if=virtio,format=qcow2,file=${VM_DISKFILE_RW}" ) - else - writelog "Error creating backing file for '${VM_DISKFILE_RO}'" - # TODO use -snapshot as fallback, test it! - # How is this supposed to even work without a disk? - VIRTCMDOPTS+=( "-snapshot" ) - fi -} - -call_post_source setup_rw_layer diff --git a/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include b/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include deleted file mode 100644 index 7d1149b0..00000000 --- a/core/modules/qemukvm/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include +++ /dev/null @@ -1,44 +0,0 @@ -# ----------------------------------------------------------------------------- -# -# Copyright (c) 2009..2018 bwLehrpool-Projektteam -# -# This program/file is free software distributed under the GPL version 2. -# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html -# -# If you have any feedback please consult https://bwlehrpool.de and -# send your feedback to bwlehrpool@hs-offenburg.de. -# -# General information about bwLehrpool can be found at https://bwlehrpool.de -# -# ----------------------------------------------------------------------------- -# run-virt.include -# - qemu/kvm plugin for vmchooser run-virt -################################################################################ - -# BASH_SOURCE[0] contains the file being sourced, namely this one -declare -rg QEMUKVM_PLUGIN_DIR="$(dirname "${BASH_SOURCE[0]}")" -declare -rg QEMUKVM_INCLUDE_DIR="${QEMUKVM_PLUGIN_DIR}/includes" - -# TODO make this part of the metadata coming from the server -# TBD: "firewall printer usb slxfloppy sound netshares" -declare -rg PLUGIN_FEATURES="slxfloppy" - -run_plugin() { - # declaration of default functions and variables for vmware - $(safesource --exit "${QEMUKVM_INCLUDE_DIR}/init_core.inc") - - # determine limitations wrt RAM and CPU count of VM - $(safesource "${QEMUKVM_INCLUDE_DIR}/determine_hardware_limitations.inc") - - # setup networking - $(safesource "${QEMUKVM_INCLUDE_DIR}/setup_network.inc") - - # setup rw layer for ro image - $(safesource "${QEMUKVM_INCLUDE_DIR}/setup_rw_layer.inc") - - # build the final start command - $(safesource "${QEMUKVM_INCLUDE_DIR}/finalize_start_command.inc") - - # print summary - needs writelog() from vmchooser-run_virt - $(safesource "${QEMUKVM_INCLUDE_DIR}/log_config_summary.inc") -} diff --git a/core/modules/qemukvm/module.build b/core/modules/qemukvm/module.build deleted file mode 100644 index f2a0df9e..00000000 --- a/core/modules/qemukvm/module.build +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -fetch_source() { - : -} - -build() { - COPYLIST="list_dpkg_output" - [ -e "$COPYLIST" ] && rm "$COPYLIST" - list_packet_files >> "$COPYLIST" - - - tarcopy "$(cat "${COPYLIST}" | sort -u)" "${MODULE_BUILD_DIR}" -} - -post_copy() { - # qemu-bridge-helper needs suid to be called within run-virt - find ${TARGET_BUILD_DIR} -type f -executable -name "*qemu-bridge-helper*" -exec chmod u+s {} \; -} diff --git a/core/modules/qemukvm/module.conf b/core/modules/qemukvm/module.conf deleted file mode 100644 index 0cf394cf..00000000 --- a/core/modules/qemukvm/module.conf +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -REQUIRED_MODULES="" -REQUIRED_DIRECTORIES=" - / -" diff --git a/core/modules/qemukvm/module.conf.debian b/core/modules/qemukvm/module.conf.debian deleted file mode 100644 index 4773a871..00000000 --- a/core/modules/qemukvm/module.conf.debian +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -REQUIRED_INSTALLED_PACKAGES=" - qemu - qemu-kvm -" - -REQUIRED_CONTENT_PACKAGES=" - qemu - qemu-kvm - qemu-system-common - qemu-system-x86 - qemu-user - qemu-utils - seabios -" diff --git a/core/modules/qemukvm/module.conf.ubuntu b/core/modules/qemukvm/module.conf.ubuntu deleted file mode 100644 index 4773a871..00000000 --- a/core/modules/qemukvm/module.conf.ubuntu +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -REQUIRED_INSTALLED_PACKAGES=" - qemu - qemu-kvm -" - -REQUIRED_CONTENT_PACKAGES=" - qemu - qemu-kvm - qemu-system-common - qemu-system-x86 - qemu-user - qemu-utils - seabios -" -- cgit v1.2.3-55-g7522 From d06889f7a59724823a6bae05b309704322d86a35 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Thu, 4 Feb 2021 10:13:25 +0100 Subject: [qemu] Rename 'qemukvm' occurrences in the core module to 'qemu' --- core/modules/qemu/data/addon-init | 6 +- core/modules/qemu/data/etc/qemu/bridge.conf | 6 -- .../qemu/data/etc/systemd/system/qemu.service | 9 +++ .../qemu/data/etc/systemd/system/qemukvm.service | 9 --- .../qemu/data/opt/openslx/scripts/systemd-qemu_env | 27 +++++++ .../data/opt/openslx/scripts/systemd-qemukvm_env | 28 ------- .../includes/determine_hardware_limitations.inc | 89 ++++++++++++++++++++++ .../qemu/includes/finalize_start_command.inc | 49 ++++++++++++ .../vmchooser/plugins/qemu/includes/init_core.inc | 54 +++++++++++++ .../plugins/qemu/includes/log_config_summary.inc | 35 +++++++++ .../plugins/qemu/includes/setup_network.inc | 56 ++++++++++++++ .../plugins/qemu/includes/setup_rw_layer.inc | 25 ++++++ .../vmchooser/plugins/qemu/run-virt.include | 44 +++++++++++ .../opt/openslx/vmchooser/plugins/qemukvm/README | 1 - .../includes/determine_hardware_limitations.inc | 89 ---------------------- .../qemukvm/includes/finalize_start_command.inc | 49 ------------ .../plugins/qemukvm/includes/init_core.inc | 54 ------------- .../qemukvm/includes/log_config_summary.inc | 35 --------- .../plugins/qemukvm/includes/setup_network.inc | 56 -------------- .../plugins/qemukvm/includes/setup_rw_layer.inc | 25 ------ .../vmchooser/plugins/qemukvm/run-virt.include | 44 ----------- core/modules/qemu/module.conf | 5 +- core/modules/qemu/module.conf.debian | 19 ++--- core/modules/qemu/module.conf.ubuntu | 19 ++--- core/targets/qemu/qemu | 1 + core/targets/qemukvm/qemukvm | 1 - 26 files changed, 411 insertions(+), 424 deletions(-) delete mode 100644 core/modules/qemu/data/etc/qemu/bridge.conf create mode 100644 core/modules/qemu/data/etc/systemd/system/qemu.service delete mode 100644 core/modules/qemu/data/etc/systemd/system/qemukvm.service create mode 100755 core/modules/qemu/data/opt/openslx/scripts/systemd-qemu_env delete mode 100755 core/modules/qemu/data/opt/openslx/scripts/systemd-qemukvm_env create mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/determine_hardware_limitations.inc create mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/finalize_start_command.inc create mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/init_core.inc create mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/log_config_summary.inc create mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/setup_network.inc create mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/setup_rw_layer.inc create mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/run-virt.include delete mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/README delete mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/determine_hardware_limitations.inc delete mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/finalize_start_command.inc delete mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/init_core.inc delete mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/log_config_summary.inc delete mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_network.inc delete mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_rw_layer.inc delete mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include create mode 120000 core/targets/qemu/qemu delete mode 120000 core/targets/qemukvm/qemukvm diff --git a/core/modules/qemu/data/addon-init b/core/modules/qemu/data/addon-init index cccc1e8a..c7c96ae4 100755 --- a/core/modules/qemu/data/addon-init +++ b/core/modules/qemu/data/addon-init @@ -1,8 +1,4 @@ #!/bin/ash systemctl daemon-reload -systemctl start qemukvm.service - -# this seems to be necessary due to the misbehaviour of udevd -# in view of the undetected ENV dev_type -systemctl restart systemd-udevd +systemctl start qemu.service diff --git a/core/modules/qemu/data/etc/qemu/bridge.conf b/core/modules/qemu/data/etc/qemu/bridge.conf deleted file mode 100644 index b8478434..00000000 --- a/core/modules/qemu/data/etc/qemu/bridge.conf +++ /dev/null @@ -1,6 +0,0 @@ -# These needs to be compatible with the -# bridge's names generated by -# /opt/openslx/scripts/systemd-run_virt_env -allow br0 -allow nat1 -allow vsw2 diff --git a/core/modules/qemu/data/etc/systemd/system/qemu.service b/core/modules/qemu/data/etc/systemd/system/qemu.service new file mode 100644 index 00000000..914e956c --- /dev/null +++ b/core/modules/qemu/data/etc/systemd/system/qemu.service @@ -0,0 +1,9 @@ +[Unit] +Description=Sets up the QEMU hypervisor +Requires=run-virt-env.service +After=run-virt-env.service + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/opt/openslx/scripts/systemd-qemu_env start diff --git a/core/modules/qemu/data/etc/systemd/system/qemukvm.service b/core/modules/qemu/data/etc/systemd/system/qemukvm.service deleted file mode 100644 index f1f3dec6..00000000 --- a/core/modules/qemu/data/etc/systemd/system/qemukvm.service +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=Sets up the virtual box environment -Requires=run-virt-env.service -After=run-virt-env.service - -[Service] -Type=oneshot -RemainAfterExit=yes -ExecStart=/opt/openslx/scripts/systemd-qemukvm_env start diff --git a/core/modules/qemu/data/opt/openslx/scripts/systemd-qemu_env b/core/modules/qemu/data/opt/openslx/scripts/systemd-qemu_env new file mode 100755 index 00000000..c8343cd5 --- /dev/null +++ b/core/modules/qemu/data/opt/openslx/scripts/systemd-qemu_env @@ -0,0 +1,27 @@ +#!/bin/bash +# ----------------------------------------------------------------------------- +# +# Copyright (c) 2017..2021 bwLehrpool-Projektteam +# +# This program/file is free software distributed under the GPL version 2. +# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html +# +# If you have any feedback please consult https://bwlehrpool.de and +# send your feedback to bwlehrpool@hs-offenburg.de. +# +# General information about bwLehrpool can be found at https://bwlehrpool.de +# +# ----------------------------------------------------------------------------- +# systemd-qemu_env +# - This is the preparation script for the configuration of QEMU on Linux. +################################################################################ + +# lazy load all kvm related modules +modprobe kvm +modprobe kvm_amd +modprobe kvm_intel + +if [ ! -e /dev/kvm ]; then + slxlog "qemu-modules" "/dev/kvm not found! Missing kvm kernel module(s)?" + exit 1 +fi diff --git a/core/modules/qemu/data/opt/openslx/scripts/systemd-qemukvm_env b/core/modules/qemu/data/opt/openslx/scripts/systemd-qemukvm_env deleted file mode 100755 index 631c159f..00000000 --- a/core/modules/qemu/data/opt/openslx/scripts/systemd-qemukvm_env +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/ash -# ----------------------------------------------------------------------------- -# -# Copyright (c) 2017..2018 bwLehrpool-Projektteam -# -# This program/file is free software distributed under the GPL version 2. -# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html -# -# If you have any feedback please consult https://bwlehrpool.de and -# send your feedback to bwlehrpool@hs-offenburg.de. -# -# General information about bwLehrpool can be found at https://bwlehrpool.de -# -# ----------------------------------------------------------------------------- -# systemd-qemukvm_env -# - This is the preparation script for the configuration of Linux Qemu/KVM. -################################################################################ - -# lazy load all kvm related modules -modprobe kvm -modprobe kvm_amd -modprobe kvm_intel - -if [ ! -e /dev/kvm ]; then - slxlog "qemukvm-modules" "/dev/kvm not found! Missing kvm kernel module(s)?" - exit 1 -fi - diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/determine_hardware_limitations.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/determine_hardware_limitations.inc new file mode 100644 index 00000000..dd83b587 --- /dev/null +++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/determine_hardware_limitations.inc @@ -0,0 +1,89 @@ +################################################################## +# qemu/kvm include: determine virtual hardware based on guest OS # +################################################################## + +set_vm_hw_limits() { + # FIXME when we have better metadata for qemu + if isempty VM_OS_TYPE; then + writelog "VM_OS_TYPE is empty! This should have been parsed from the XML file" + EXIT_TYPE="user" EXIT_REASON="Konnte Gastbetriebsystems der virtuellen Maschine nicht ermitteln!" cleanexit 1 + fi + + # define global hardware-related variables + declare -g MAXMEM="9999999" + declare -g MAXCORES="4" + declare -g SOUND_DEV="es1370" + + # determine if we need a 32bit or 64bit machine + # FIXME depending on the guest OS for now + # (sadly does not support all the exotic OSs the + # the world has even seen like vmware plugin :<) + local bits=64 + case "${VM_OS_TYPE}" in + beos*) + bits=32 + SOUND_DEV="sb16" + ;; + win3*|win*3*|Win*3*) + bits=32 + SOUND_DEV="sb16" + MAXMEM=32 + ;; + win95*|Win*95) + bits=32 + MAXMEM=96 + ;; + win98) + bits=32 + MAXMEM=256 + ;; + winme*|windowsme*) + bits=32 + SOUND_DEV="ac97" + MAXMEM=384 + ;; + winxp*64|windowsxp*64) + SOUND_DEV="ac97" + ;; + windows7|windows8|windows9) + SOUND_DEV="ac97" + MAXMEM="8000" + MAXCORES="4" + ;; + windows7-64|windows8-64|windows9-64) + SOUND_DEV="ac97" + MAXMEM="32000" + MAXCORES="8" + ;; + *64) + MAXMEM="16000" + MAXCORES="4" + ;; + *) + bits=32 + MAXMEM="8000" + MAXCORES="1" + ;; + esac + declare -g VIRTCMD + if [ "$bits" = 32 ]; then + declare -rg VIRTCMD="qemu-system-i386" + VIRTCMDOPTS+=( "-machine" "accel=tcg" ) # TODO: 32bit VMs can't use kvm!? + else # 64 bit + declare -rg VIRTCMD="qemu-system-x86_64" + VIRTCMDOPTS+=( "-machine" "accel=kvm" ) + fi + + + # check for allocated cores + declare -g CPU_CORES="${HW_THREADS:-1}" + declare -rg HOST_CORE_COUNT="${CPU_CORES}" + [ "${CPU_CORES}" -gt "${MAXCORES}" ] && CPU_CORES="${MAXCORES}" + + # check if memory set by the generic run-virt is above the threshold + [ "${VM_MEM}" -gt "${MAXMEM}" ] && VM_MEM="${MAXMEM}" + return 0 +} + +## MAIN ## +call_post_source set_vm_hw_limits diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/finalize_start_command.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/finalize_start_command.inc new file mode 100644 index 00000000..6d9df363 --- /dev/null +++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/finalize_start_command.inc @@ -0,0 +1,49 @@ +# ----------------------------------------------------------------------------- +# +# Copyright (c) 2009..2018 bwLehrpool-Projektteam +# +# This program/file is free software distributed under the GPL version 2. +# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html +# +# If you have any feedback please consult https://bwlehrpool.de and +# send your feedback to bwlehrpool@hs-offenburg.de. +# +# General information about bwLehrpool can be found at https://bwlehrpool.de +# +# ----------------------------------------------------------------------------- +# run-virt.include +# - Include script for running the QEMU/Linux KVM virtual machine on an +# OpenSLX client via the run-virt.sh or run-vmgrid.sh +################################################################################ + +# set options that depend on previous includes +# and build the final start command +finalize_start_command() { + + # set cpu type + VIRTCMDOPTS+=( "-cpu" "host" ) + # set cpu cores + VIRTCMDOPTS+=( "-smp" "${CPU_CORES}" ) + + # set RAM + VIRTCMDOPTS+=( "-m" "${VM_MEM}" ) + + # special feature for real and virtual floppy disks + isset FLOPPY_0 && VIRTCMDOPTS+=( "-fda" "${FLOPPY_0}" ) + isset SLX_FLOPPY_IMG && VIRTCMDOPTS+=( "-fdb" "${SLX_FLOPPY_IMG}" ) + + # add optical drive if available + isset CDROM_0 && VIRTCMDOPTS+=( "-cdrom" "${CDROM_0}" ) + + # audio + isset SOUND_DEV && VIRTCMDOPTS+=( "-soundhw" "${SOUND_DEV}" ) + + # serial devices TODO test + if isset SERIAL_PORTS; then + for DEV in $SERIAL_PORTS; do + : # buggeh: VIRTCMDOPTS+=( "-serial" "${DEV}" ) + done + fi +} + +call_post_source finalize_start_command diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/init_core.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/init_core.inc new file mode 100644 index 00000000..fee2cd1c --- /dev/null +++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/init_core.inc @@ -0,0 +1,54 @@ +# ----------------------------------------------------------------------------- +# +# Copyright (c) 2009..2018 bwLehrpool-Projektteam +# +# This program/file is free software distributed under the GPL version 2. +# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html +# +# If you have any feedback please consult https://bwlehrpool.de and +# send your feedback to bwlehrpool@hs-offenburg.de. +# +# General information about bwLehrpool can be found at https://bwlehrpool.de +# +# ----------------------------------------------------------------------------- +# run-virt.include +# - Include script for running the QEMU/Linux KVM virtual machine on an +# OpenSLX client via the run-virt.sh or run-vmgrid.sh +################################################################################ + +# check if kvm kernel module are available +if [ ! -c /dev/kvm ]; then + writelog "KVM kernel modules not loaded!" + EXIT_TYPE="internal" EXIT_REASON="QEMU/KVM Virtualisierer nicht initialisiert!" cleanexit 1 +fi + +# check if qemu binaries are available +if ! check_dep qemu-system-{i386,x86_64}; then + writelog "QEMU binaries not available!" + EXIT_TYPE="internal" EXIT_REASON="QEMU/KVM Virtualisierer nicht initialisiert!" cleanexit 1 +fi + +# set general purpose options here, mostly evaluates information +# contained in /opt/openslx/vmchooser/config/virtualization.conf + +# TODO some options should come from the server, in particular +# - disk controller type (virtio, scsi, ide...) +# - arch to emulate (x86_64, i386, ...) +# - graphics mode? +# - sound dev? +# - tbd + +# display name, remove blanks because of cmdline problems +declare -rg CMD_DISPLAYNAME=$(echo ${VM_DISPLAYNAME} | sed -e "s, ,-,g;s,(,[,g;s,),],g") +VIRTCMDOPTS+=( "-name" "${CMD_DISPLAYNAME}" ) + +# graphical start: vga, vmware, qxl, spice? +VIRTCMDOPTS+=( "-vga" "std" "-full-screen" ) + +# hot keys ALT+CTRL+SHIFT (does not work properly!?) +VIRTCMDOPTS+=( "-alt-grab" ) + +# TODO support other types of boot? any usecase for network boot? +# for now just boot from disk +VIRTCMDOPTS+=( "-boot" "c" ) + diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/log_config_summary.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/log_config_summary.inc new file mode 100644 index 00000000..6b4b279f --- /dev/null +++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/log_config_summary.inc @@ -0,0 +1,35 @@ +################################################## +# Include: Print vm config summary into log file # +################################################## + +log_config_summary() { + writelog "Directories:" + writelog "\tTMPDIR:\t\t\t$TMPDIR" + writelog "Disk image:" + writelog "\tSource disk:\t\t$VM_DISKFILE_RO" + if [ -e "${VM_DISKFILE_RW}" ]; then + writelog "\tDisk mode:\t\twritable" + writelog "\tRW-Layer:\t\t$VM_DISKFILE_RW" + else + writelog "\tDisk mode:\t\tread-only" + fi + + writelog "Virtual Hardware:" + writelog "\tvCPU cores:\t\t${CPU_CORES}" + writelog "\tGuest RAM:\t\t${VM_MEM} MB" + + # echo nur wenn HOST_MEM_REMAINING gesetzt + if isset HOST_MEM_REMAINING; then + writelog "\tHost RAM:\t\t${HOST_MEM_REMAINING} MB" + fi + writelog "\tMAC address:\t\t${VM_MAC_ADDR}" + writelog "\tNetwork card:\t\t${NIC_MODEL}" + writelog "\tNetwork kind:\t\t${NETWORK_MODE}" + writelog "\tCD-ROM1:\t${CDROM_0}" + writelog "\tCD-ROM2:\t${CDROM_1}" + writelog "\tFloppy_A:\t${FLOPPY_0}" + writelog "\tFloppy_B:\t${SLX_FLOPPY_IMG}" + #writelog "\tShared Folders 'home':\t/home/${USER}" +} + +call_post_source log_config_summary diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/setup_network.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/setup_network.inc new file mode 100644 index 00000000..73fb2518 --- /dev/null +++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/setup_network.inc @@ -0,0 +1,56 @@ +################################### +# qemu/kvm include: Network setup # +################################### +# This now makes use of the qemu's bridge helper +# which creates a tap device and adds it to the +# bridge corresponding to the network type +# TODO configurable network type +setup_network() { + # list available models with: + # qemu-system-x86_64 -net nic,model=? + # e.g. as of 2.0.0: + # ne2k_pci,i82551,i82557b,i82559er,rtl8139,e1000,pcnet,virtio + declare -rg NIC_MODEL="e1000" + + # add MAC address and network card model + VIRTCMDOPTS+=( "-device" "${NIC_MODEL},mac=${VM_MAC_ADDR},netdev=guestnet0" ) + + # TODO support different network kinds for lectures in bwlehrpool-suite, just NAT for now + declare -g NETWORK_MODE="nat" + + # detect if qemu's bridge helper binary is available + declare -g QEMU_BRIDGE_HELPER= + for HELPER_PATH in /usr/lib/qemu-bridge-helper /usr/local/libexec/qemu-bridge-helper; do + if [ -x "${HELPER_PATH}" ] && [ -u "${HELPER_PATH}" ]; then + QEMU_BRIDGE_HELPER="${HELPER_PATH}" + readonly QEMU_BRIDGE_HELPER + break + fi + done + if isempty QEMU_BRIDGE_HELPER; then + writelog "Could not find qemu-bridge-helper on this machine. Setting network mode to user." + # Even though falling back to creating tap devices ourselves, we should instead + # garantee the existance of qemu's helper on minilinux build time. + # qemu's user network mode allows tcp/udp connections in a nat-fashion and + # it allows access to the web which seems suffisant for a fallback. + NETWORK_MODE="user" + fi + + case "${NETWORK_MODE}" in + nat*) + VIRTCMDOPTS+=( "-netdev" "bridge,br=nat1,id=guestnet0,helper=${QEMU_BRIDGE_HELPER}" ) + ;; + bridge*) + VIRTCMDOPTS+=( "-netdev" "bridge,br=br0,id=guestnet0,helper=${QEMU_BRIDGE_HELPER}" ) + ;; + host*) + VIRTCMDOPTS+=( "-netdev" "bridge,br=vsw2,id=guestnet0,helper=${QEMU_BRIDGE_HELPER}" ) + ;; + user*|*) + VIRTCMDOPTS+=( "-netdev" "user,id=guestnet0" ) + ;; + esac +} + +## MAIN ## +call_post_source setup_network diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/setup_rw_layer.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/setup_rw_layer.inc new file mode 100644 index 00000000..32637e5d --- /dev/null +++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/setup_rw_layer.inc @@ -0,0 +1,25 @@ + +setup_rw_layer() { + if isempty VM_DISKFILE_RO; then + writelog "No source diskfile found! This should be specified in the given XML file. Is it valid?" + EXIT_TYPE="user" EXIT_REASON="Keine virtuelle Festplatte zu dieser Veranstaltung angegeben!" cleanexit 1 + fi + + # setup qcow2 backing file for that disk file + writelog "Creating backing file for '${VM_DISKFILE_RO}'..." + # TODO: WTF? This is fucked up, VM_DISKFILE_RW is set if we want to run in persistent mode, + # this plugin shouldn't mess around with it.... + declare -rg VM_DISKFILE_RW="${TMPDIR}/$(basename ${VM_DISKFILE_RO}).qcow2" + if qemu-img create -f qcow2 -b "${VM_DISKFILE_RO}" "${VM_DISKFILE_RW}"; then + # all good, use it as main disk drive + # TODO: determine the proper type of controller to use, ideally virtio? + VIRTCMDOPTS+=("-drive" "if=virtio,format=qcow2,file=${VM_DISKFILE_RW}" ) + else + writelog "Error creating backing file for '${VM_DISKFILE_RO}'" + # TODO use -snapshot as fallback, test it! + # How is this supposed to even work without a disk? + VIRTCMDOPTS+=( "-snapshot" ) + fi +} + +call_post_source setup_rw_layer diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/run-virt.include b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/run-virt.include new file mode 100644 index 00000000..9f2b1291 --- /dev/null +++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/run-virt.include @@ -0,0 +1,44 @@ +# ----------------------------------------------------------------------------- +# +# Copyright (c) 2009..2021 bwLehrpool-Projektteam +# +# This program/file is free software distributed under the GPL version 2. +# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html +# +# If you have any feedback please consult https://bwlehrpool.de and +# send your feedback to bwlehrpool@hs-offenburg.de. +# +# General information about bwLehrpool can be found at https://bwlehrpool.de +# +# ----------------------------------------------------------------------------- +# run-virt.include +# - qemu plugin for vmchooser run-virt +################################################################################ + +# BASH_SOURCE[0] contains the file being sourced, namely this one +declare -rg QEMU_PLUGIN_DIR="$(dirname "${BASH_SOURCE[0]}")" +declare -rg QEMU_INCLUDE_DIR="${QEMU_PLUGIN_DIR}/includes" + +# TODO make this part of the metadata coming from the server +# TBD: "firewall printer usb slxfloppy sound netshares" +declare -rg PLUGIN_FEATURES="slxfloppy" + +run_plugin() { + # declaration of default functions and variables for vmware + $(safesource --exit "${QEMU_INCLUDE_DIR}/init_core.inc") + + # determine limitations wrt RAM and CPU count of VM + $(safesource "${QEMU_INCLUDE_DIR}/determine_hardware_limitations.inc") + + # setup networking + $(safesource "${QEMU_INCLUDE_DIR}/setup_network.inc") + + # setup rw layer for ro image + $(safesource "${QEMU_INCLUDE_DIR}/setup_rw_layer.inc") + + # build the final start command + $(safesource "${QEMU_INCLUDE_DIR}/finalize_start_command.inc") + + # print summary - needs writelog() from vmchooser-run_virt + $(safesource "${QEMU_INCLUDE_DIR}/log_config_summary.inc") +} diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/README b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/README deleted file mode 100644 index 549d0037..00000000 --- a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/README +++ /dev/null @@ -1 +0,0 @@ -Not tested since refactoring! (January 2017) diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/determine_hardware_limitations.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/determine_hardware_limitations.inc deleted file mode 100644 index dd83b587..00000000 --- a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/determine_hardware_limitations.inc +++ /dev/null @@ -1,89 +0,0 @@ -################################################################## -# qemu/kvm include: determine virtual hardware based on guest OS # -################################################################## - -set_vm_hw_limits() { - # FIXME when we have better metadata for qemu - if isempty VM_OS_TYPE; then - writelog "VM_OS_TYPE is empty! This should have been parsed from the XML file" - EXIT_TYPE="user" EXIT_REASON="Konnte Gastbetriebsystems der virtuellen Maschine nicht ermitteln!" cleanexit 1 - fi - - # define global hardware-related variables - declare -g MAXMEM="9999999" - declare -g MAXCORES="4" - declare -g SOUND_DEV="es1370" - - # determine if we need a 32bit or 64bit machine - # FIXME depending on the guest OS for now - # (sadly does not support all the exotic OSs the - # the world has even seen like vmware plugin :<) - local bits=64 - case "${VM_OS_TYPE}" in - beos*) - bits=32 - SOUND_DEV="sb16" - ;; - win3*|win*3*|Win*3*) - bits=32 - SOUND_DEV="sb16" - MAXMEM=32 - ;; - win95*|Win*95) - bits=32 - MAXMEM=96 - ;; - win98) - bits=32 - MAXMEM=256 - ;; - winme*|windowsme*) - bits=32 - SOUND_DEV="ac97" - MAXMEM=384 - ;; - winxp*64|windowsxp*64) - SOUND_DEV="ac97" - ;; - windows7|windows8|windows9) - SOUND_DEV="ac97" - MAXMEM="8000" - MAXCORES="4" - ;; - windows7-64|windows8-64|windows9-64) - SOUND_DEV="ac97" - MAXMEM="32000" - MAXCORES="8" - ;; - *64) - MAXMEM="16000" - MAXCORES="4" - ;; - *) - bits=32 - MAXMEM="8000" - MAXCORES="1" - ;; - esac - declare -g VIRTCMD - if [ "$bits" = 32 ]; then - declare -rg VIRTCMD="qemu-system-i386" - VIRTCMDOPTS+=( "-machine" "accel=tcg" ) # TODO: 32bit VMs can't use kvm!? - else # 64 bit - declare -rg VIRTCMD="qemu-system-x86_64" - VIRTCMDOPTS+=( "-machine" "accel=kvm" ) - fi - - - # check for allocated cores - declare -g CPU_CORES="${HW_THREADS:-1}" - declare -rg HOST_CORE_COUNT="${CPU_CORES}" - [ "${CPU_CORES}" -gt "${MAXCORES}" ] && CPU_CORES="${MAXCORES}" - - # check if memory set by the generic run-virt is above the threshold - [ "${VM_MEM}" -gt "${MAXMEM}" ] && VM_MEM="${MAXMEM}" - return 0 -} - -## MAIN ## -call_post_source set_vm_hw_limits diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/finalize_start_command.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/finalize_start_command.inc deleted file mode 100644 index 6d9df363..00000000 --- a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/finalize_start_command.inc +++ /dev/null @@ -1,49 +0,0 @@ -# ----------------------------------------------------------------------------- -# -# Copyright (c) 2009..2018 bwLehrpool-Projektteam -# -# This program/file is free software distributed under the GPL version 2. -# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html -# -# If you have any feedback please consult https://bwlehrpool.de and -# send your feedback to bwlehrpool@hs-offenburg.de. -# -# General information about bwLehrpool can be found at https://bwlehrpool.de -# -# ----------------------------------------------------------------------------- -# run-virt.include -# - Include script for running the QEMU/Linux KVM virtual machine on an -# OpenSLX client via the run-virt.sh or run-vmgrid.sh -################################################################################ - -# set options that depend on previous includes -# and build the final start command -finalize_start_command() { - - # set cpu type - VIRTCMDOPTS+=( "-cpu" "host" ) - # set cpu cores - VIRTCMDOPTS+=( "-smp" "${CPU_CORES}" ) - - # set RAM - VIRTCMDOPTS+=( "-m" "${VM_MEM}" ) - - # special feature for real and virtual floppy disks - isset FLOPPY_0 && VIRTCMDOPTS+=( "-fda" "${FLOPPY_0}" ) - isset SLX_FLOPPY_IMG && VIRTCMDOPTS+=( "-fdb" "${SLX_FLOPPY_IMG}" ) - - # add optical drive if available - isset CDROM_0 && VIRTCMDOPTS+=( "-cdrom" "${CDROM_0}" ) - - # audio - isset SOUND_DEV && VIRTCMDOPTS+=( "-soundhw" "${SOUND_DEV}" ) - - # serial devices TODO test - if isset SERIAL_PORTS; then - for DEV in $SERIAL_PORTS; do - : # buggeh: VIRTCMDOPTS+=( "-serial" "${DEV}" ) - done - fi -} - -call_post_source finalize_start_command diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/init_core.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/init_core.inc deleted file mode 100644 index fee2cd1c..00000000 --- a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/init_core.inc +++ /dev/null @@ -1,54 +0,0 @@ -# ----------------------------------------------------------------------------- -# -# Copyright (c) 2009..2018 bwLehrpool-Projektteam -# -# This program/file is free software distributed under the GPL version 2. -# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html -# -# If you have any feedback please consult https://bwlehrpool.de and -# send your feedback to bwlehrpool@hs-offenburg.de. -# -# General information about bwLehrpool can be found at https://bwlehrpool.de -# -# ----------------------------------------------------------------------------- -# run-virt.include -# - Include script for running the QEMU/Linux KVM virtual machine on an -# OpenSLX client via the run-virt.sh or run-vmgrid.sh -################################################################################ - -# check if kvm kernel module are available -if [ ! -c /dev/kvm ]; then - writelog "KVM kernel modules not loaded!" - EXIT_TYPE="internal" EXIT_REASON="QEMU/KVM Virtualisierer nicht initialisiert!" cleanexit 1 -fi - -# check if qemu binaries are available -if ! check_dep qemu-system-{i386,x86_64}; then - writelog "QEMU binaries not available!" - EXIT_TYPE="internal" EXIT_REASON="QEMU/KVM Virtualisierer nicht initialisiert!" cleanexit 1 -fi - -# set general purpose options here, mostly evaluates information -# contained in /opt/openslx/vmchooser/config/virtualization.conf - -# TODO some options should come from the server, in particular -# - disk controller type (virtio, scsi, ide...) -# - arch to emulate (x86_64, i386, ...) -# - graphics mode? -# - sound dev? -# - tbd - -# display name, remove blanks because of cmdline problems -declare -rg CMD_DISPLAYNAME=$(echo ${VM_DISPLAYNAME} | sed -e "s, ,-,g;s,(,[,g;s,),],g") -VIRTCMDOPTS+=( "-name" "${CMD_DISPLAYNAME}" ) - -# graphical start: vga, vmware, qxl, spice? -VIRTCMDOPTS+=( "-vga" "std" "-full-screen" ) - -# hot keys ALT+CTRL+SHIFT (does not work properly!?) -VIRTCMDOPTS+=( "-alt-grab" ) - -# TODO support other types of boot? any usecase for network boot? -# for now just boot from disk -VIRTCMDOPTS+=( "-boot" "c" ) - diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/log_config_summary.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/log_config_summary.inc deleted file mode 100644 index 6b4b279f..00000000 --- a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/log_config_summary.inc +++ /dev/null @@ -1,35 +0,0 @@ -################################################## -# Include: Print vm config summary into log file # -################################################## - -log_config_summary() { - writelog "Directories:" - writelog "\tTMPDIR:\t\t\t$TMPDIR" - writelog "Disk image:" - writelog "\tSource disk:\t\t$VM_DISKFILE_RO" - if [ -e "${VM_DISKFILE_RW}" ]; then - writelog "\tDisk mode:\t\twritable" - writelog "\tRW-Layer:\t\t$VM_DISKFILE_RW" - else - writelog "\tDisk mode:\t\tread-only" - fi - - writelog "Virtual Hardware:" - writelog "\tvCPU cores:\t\t${CPU_CORES}" - writelog "\tGuest RAM:\t\t${VM_MEM} MB" - - # echo nur wenn HOST_MEM_REMAINING gesetzt - if isset HOST_MEM_REMAINING; then - writelog "\tHost RAM:\t\t${HOST_MEM_REMAINING} MB" - fi - writelog "\tMAC address:\t\t${VM_MAC_ADDR}" - writelog "\tNetwork card:\t\t${NIC_MODEL}" - writelog "\tNetwork kind:\t\t${NETWORK_MODE}" - writelog "\tCD-ROM1:\t${CDROM_0}" - writelog "\tCD-ROM2:\t${CDROM_1}" - writelog "\tFloppy_A:\t${FLOPPY_0}" - writelog "\tFloppy_B:\t${SLX_FLOPPY_IMG}" - #writelog "\tShared Folders 'home':\t/home/${USER}" -} - -call_post_source log_config_summary diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_network.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_network.inc deleted file mode 100644 index 73fb2518..00000000 --- a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_network.inc +++ /dev/null @@ -1,56 +0,0 @@ -################################### -# qemu/kvm include: Network setup # -################################### -# This now makes use of the qemu's bridge helper -# which creates a tap device and adds it to the -# bridge corresponding to the network type -# TODO configurable network type -setup_network() { - # list available models with: - # qemu-system-x86_64 -net nic,model=? - # e.g. as of 2.0.0: - # ne2k_pci,i82551,i82557b,i82559er,rtl8139,e1000,pcnet,virtio - declare -rg NIC_MODEL="e1000" - - # add MAC address and network card model - VIRTCMDOPTS+=( "-device" "${NIC_MODEL},mac=${VM_MAC_ADDR},netdev=guestnet0" ) - - # TODO support different network kinds for lectures in bwlehrpool-suite, just NAT for now - declare -g NETWORK_MODE="nat" - - # detect if qemu's bridge helper binary is available - declare -g QEMU_BRIDGE_HELPER= - for HELPER_PATH in /usr/lib/qemu-bridge-helper /usr/local/libexec/qemu-bridge-helper; do - if [ -x "${HELPER_PATH}" ] && [ -u "${HELPER_PATH}" ]; then - QEMU_BRIDGE_HELPER="${HELPER_PATH}" - readonly QEMU_BRIDGE_HELPER - break - fi - done - if isempty QEMU_BRIDGE_HELPER; then - writelog "Could not find qemu-bridge-helper on this machine. Setting network mode to user." - # Even though falling back to creating tap devices ourselves, we should instead - # garantee the existance of qemu's helper on minilinux build time. - # qemu's user network mode allows tcp/udp connections in a nat-fashion and - # it allows access to the web which seems suffisant for a fallback. - NETWORK_MODE="user" - fi - - case "${NETWORK_MODE}" in - nat*) - VIRTCMDOPTS+=( "-netdev" "bridge,br=nat1,id=guestnet0,helper=${QEMU_BRIDGE_HELPER}" ) - ;; - bridge*) - VIRTCMDOPTS+=( "-netdev" "bridge,br=br0,id=guestnet0,helper=${QEMU_BRIDGE_HELPER}" ) - ;; - host*) - VIRTCMDOPTS+=( "-netdev" "bridge,br=vsw2,id=guestnet0,helper=${QEMU_BRIDGE_HELPER}" ) - ;; - user*|*) - VIRTCMDOPTS+=( "-netdev" "user,id=guestnet0" ) - ;; - esac -} - -## MAIN ## -call_post_source setup_network diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_rw_layer.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_rw_layer.inc deleted file mode 100644 index 32637e5d..00000000 --- a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_rw_layer.inc +++ /dev/null @@ -1,25 +0,0 @@ - -setup_rw_layer() { - if isempty VM_DISKFILE_RO; then - writelog "No source diskfile found! This should be specified in the given XML file. Is it valid?" - EXIT_TYPE="user" EXIT_REASON="Keine virtuelle Festplatte zu dieser Veranstaltung angegeben!" cleanexit 1 - fi - - # setup qcow2 backing file for that disk file - writelog "Creating backing file for '${VM_DISKFILE_RO}'..." - # TODO: WTF? This is fucked up, VM_DISKFILE_RW is set if we want to run in persistent mode, - # this plugin shouldn't mess around with it.... - declare -rg VM_DISKFILE_RW="${TMPDIR}/$(basename ${VM_DISKFILE_RO}).qcow2" - if qemu-img create -f qcow2 -b "${VM_DISKFILE_RO}" "${VM_DISKFILE_RW}"; then - # all good, use it as main disk drive - # TODO: determine the proper type of controller to use, ideally virtio? - VIRTCMDOPTS+=("-drive" "if=virtio,format=qcow2,file=${VM_DISKFILE_RW}" ) - else - writelog "Error creating backing file for '${VM_DISKFILE_RO}'" - # TODO use -snapshot as fallback, test it! - # How is this supposed to even work without a disk? - VIRTCMDOPTS+=( "-snapshot" ) - fi -} - -call_post_source setup_rw_layer diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include deleted file mode 100644 index 7d1149b0..00000000 --- a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include +++ /dev/null @@ -1,44 +0,0 @@ -# ----------------------------------------------------------------------------- -# -# Copyright (c) 2009..2018 bwLehrpool-Projektteam -# -# This program/file is free software distributed under the GPL version 2. -# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html -# -# If you have any feedback please consult https://bwlehrpool.de and -# send your feedback to bwlehrpool@hs-offenburg.de. -# -# General information about bwLehrpool can be found at https://bwlehrpool.de -# -# ----------------------------------------------------------------------------- -# run-virt.include -# - qemu/kvm plugin for vmchooser run-virt -################################################################################ - -# BASH_SOURCE[0] contains the file being sourced, namely this one -declare -rg QEMUKVM_PLUGIN_DIR="$(dirname "${BASH_SOURCE[0]}")" -declare -rg QEMUKVM_INCLUDE_DIR="${QEMUKVM_PLUGIN_DIR}/includes" - -# TODO make this part of the metadata coming from the server -# TBD: "firewall printer usb slxfloppy sound netshares" -declare -rg PLUGIN_FEATURES="slxfloppy" - -run_plugin() { - # declaration of default functions and variables for vmware - $(safesource --exit "${QEMUKVM_INCLUDE_DIR}/init_core.inc") - - # determine limitations wrt RAM and CPU count of VM - $(safesource "${QEMUKVM_INCLUDE_DIR}/determine_hardware_limitations.inc") - - # setup networking - $(safesource "${QEMUKVM_INCLUDE_DIR}/setup_network.inc") - - # setup rw layer for ro image - $(safesource "${QEMUKVM_INCLUDE_DIR}/setup_rw_layer.inc") - - # build the final start command - $(safesource "${QEMUKVM_INCLUDE_DIR}/finalize_start_command.inc") - - # print summary - needs writelog() from vmchooser-run_virt - $(safesource "${QEMUKVM_INCLUDE_DIR}/log_config_summary.inc") -} diff --git a/core/modules/qemu/module.conf b/core/modules/qemu/module.conf index 0cf394cf..61069809 100644 --- a/core/modules/qemu/module.conf +++ b/core/modules/qemu/module.conf @@ -1,5 +1,2 @@ #!/bin/bash -REQUIRED_MODULES="" -REQUIRED_DIRECTORIES=" - / -" +REQUIRED_MODULES="libvirt" diff --git a/core/modules/qemu/module.conf.debian b/core/modules/qemu/module.conf.debian index 4773a871..d4af965d 100644 --- a/core/modules/qemu/module.conf.debian +++ b/core/modules/qemu/module.conf.debian @@ -1,15 +1,16 @@ #!/bin/bash REQUIRED_INSTALLED_PACKAGES=" - qemu - qemu-kvm + qemu + qemu-kvm " REQUIRED_CONTENT_PACKAGES=" - qemu - qemu-kvm - qemu-system-common - qemu-system-x86 - qemu-user - qemu-utils - seabios + qemu + qemu-kvm + qemu-system-common + qemu-system-arm + qemu-system-x86 + qemu-utils + seabios + ovmf " diff --git a/core/modules/qemu/module.conf.ubuntu b/core/modules/qemu/module.conf.ubuntu index 4773a871..d4af965d 100644 --- a/core/modules/qemu/module.conf.ubuntu +++ b/core/modules/qemu/module.conf.ubuntu @@ -1,15 +1,16 @@ #!/bin/bash REQUIRED_INSTALLED_PACKAGES=" - qemu - qemu-kvm + qemu + qemu-kvm " REQUIRED_CONTENT_PACKAGES=" - qemu - qemu-kvm - qemu-system-common - qemu-system-x86 - qemu-user - qemu-utils - seabios + qemu + qemu-kvm + qemu-system-common + qemu-system-arm + qemu-system-x86 + qemu-utils + seabios + ovmf " diff --git a/core/targets/qemu/qemu b/core/targets/qemu/qemu new file mode 120000 index 00000000..bb8ffc08 --- /dev/null +++ b/core/targets/qemu/qemu @@ -0,0 +1 @@ +../../modules/qemu \ No newline at end of file diff --git a/core/targets/qemukvm/qemukvm b/core/targets/qemukvm/qemukvm deleted file mode 120000 index e8e7d1b3..00000000 --- a/core/targets/qemukvm/qemukvm +++ /dev/null @@ -1 +0,0 @@ -../../modules/qemukvm \ No newline at end of file -- cgit v1.2.3-55-g7522 From 288523c21e7560e3b97608e9f463f1e7ffeab069 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Thu, 4 Feb 2021 12:00:25 +0100 Subject: [libvirt] Add Libvirt virtualization daemon as new module --- core/modules/libvirt/data/addon-init | 4 ++++ core/modules/libvirt/module.build | 14 ++++++++++++++ core/modules/libvirt/module.conf.debian | 16 ++++++++++++++++ core/modules/libvirt/module.conf.ubuntu.18 | 12 ++++++++++++ core/modules/libvirt/module.conf.ubuntu.20 | 16 ++++++++++++++++ core/targets/qemu/libvirt | 1 + 6 files changed, 63 insertions(+) create mode 100755 core/modules/libvirt/data/addon-init create mode 100644 core/modules/libvirt/module.build create mode 100644 core/modules/libvirt/module.conf.debian create mode 100644 core/modules/libvirt/module.conf.ubuntu.18 create mode 100644 core/modules/libvirt/module.conf.ubuntu.20 create mode 120000 core/targets/qemu/libvirt diff --git a/core/modules/libvirt/data/addon-init b/core/modules/libvirt/data/addon-init new file mode 100755 index 00000000..8070d171 --- /dev/null +++ b/core/modules/libvirt/data/addon-init @@ -0,0 +1,4 @@ +#!/bin/ash + +systemctl daemon-reload +systemctl start libvirtd.service diff --git a/core/modules/libvirt/module.build b/core/modules/libvirt/module.build new file mode 100644 index 00000000..5fa3a36f --- /dev/null +++ b/core/modules/libvirt/module.build @@ -0,0 +1,14 @@ +#!/bin/bash +fetch_source() { + : +} + +build() { + COPYLIST="list_dpkg_output" + list_packet_files > "$COPYLIST" + tarcopy "$(cat "${COPYLIST}" | sort -u)" "${MODULE_BUILD_DIR}" +} + +post_copy() { + : +} diff --git a/core/modules/libvirt/module.conf.debian b/core/modules/libvirt/module.conf.debian new file mode 100644 index 00000000..a4ecd34a --- /dev/null +++ b/core/modules/libvirt/module.conf.debian @@ -0,0 +1,16 @@ +#!/bin/bash +REQUIRED_INSTALLED_PACKAGES=" + libvirt-daemon-system + libvirt-daemon + libvirt-clients + virt-manager + virt-viewer +" + +REQUIRED_CONTENT_PACKAGES=" + libvirt-daemon-system + libvirt-daemon + libvirt-clients + virt-manager + virt-viewer +" diff --git a/core/modules/libvirt/module.conf.ubuntu.18 b/core/modules/libvirt/module.conf.ubuntu.18 new file mode 100644 index 00000000..fbe60f37 --- /dev/null +++ b/core/modules/libvirt/module.conf.ubuntu.18 @@ -0,0 +1,12 @@ +#!/bin/bash +REQUIRED_INSTALLED_PACKAGES=" + libvirt-bin + virt-manager + virt-viewer +" + +REQUIRED_CONTENT_PACKAGES=" + libvirt-bin + virt-manager + virt-viewer +" diff --git a/core/modules/libvirt/module.conf.ubuntu.20 b/core/modules/libvirt/module.conf.ubuntu.20 new file mode 100644 index 00000000..a4ecd34a --- /dev/null +++ b/core/modules/libvirt/module.conf.ubuntu.20 @@ -0,0 +1,16 @@ +#!/bin/bash +REQUIRED_INSTALLED_PACKAGES=" + libvirt-daemon-system + libvirt-daemon + libvirt-clients + virt-manager + virt-viewer +" + +REQUIRED_CONTENT_PACKAGES=" + libvirt-daemon-system + libvirt-daemon + libvirt-clients + virt-manager + virt-viewer +" diff --git a/core/targets/qemu/libvirt b/core/targets/qemu/libvirt new file mode 120000 index 00000000..3e853b08 --- /dev/null +++ b/core/targets/qemu/libvirt @@ -0,0 +1 @@ +../../modules/libvirt \ No newline at end of file -- cgit v1.2.3-55-g7522 From f0668d5ff2cffc92d1226be4605f46b1aa4deb26 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Thu, 4 Feb 2021 14:26:39 +0100 Subject: [qemu] Fix installation of package files --- core/modules/qemu/module.build | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/core/modules/qemu/module.build b/core/modules/qemu/module.build index f2a0df9e..fc1bc074 100644 --- a/core/modules/qemu/module.build +++ b/core/modules/qemu/module.build @@ -5,14 +5,11 @@ fetch_source() { build() { COPYLIST="list_dpkg_output" - [ -e "$COPYLIST" ] && rm "$COPYLIST" - list_packet_files >> "$COPYLIST" - - + [ -e "${COPYLIST}" ] && rm "${COPYLIST}" + list_packet_files >> "${COPYLIST}" tarcopy "$(cat "${COPYLIST}" | sort -u)" "${MODULE_BUILD_DIR}" } post_copy() { - # qemu-bridge-helper needs suid to be called within run-virt - find ${TARGET_BUILD_DIR} -type f -executable -name "*qemu-bridge-helper*" -exec chmod u+s {} \; + : } -- cgit v1.2.3-55-g7522 From 7bb3768bbb924bb34267b12eab6a9ed6f26addbf Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Thu, 4 Feb 2021 14:26:53 +0100 Subject: [libvirt] Fix installation of package files --- core/modules/libvirt/module.build | 3 ++- core/modules/libvirt/module.conf | 1 + core/modules/libvirt/module.conf.ubuntu.18 | 12 ------------ core/modules/libvirt/module.conf.ubuntu.18.04 | 12 ++++++++++++ core/modules/libvirt/module.conf.ubuntu.20 | 16 ---------------- core/modules/libvirt/module.conf.ubuntu.20.04 | 16 ++++++++++++++++ 6 files changed, 31 insertions(+), 29 deletions(-) create mode 100644 core/modules/libvirt/module.conf delete mode 100644 core/modules/libvirt/module.conf.ubuntu.18 create mode 100644 core/modules/libvirt/module.conf.ubuntu.18.04 delete mode 100644 core/modules/libvirt/module.conf.ubuntu.20 create mode 100644 core/modules/libvirt/module.conf.ubuntu.20.04 diff --git a/core/modules/libvirt/module.build b/core/modules/libvirt/module.build index 5fa3a36f..fc1bc074 100644 --- a/core/modules/libvirt/module.build +++ b/core/modules/libvirt/module.build @@ -5,7 +5,8 @@ fetch_source() { build() { COPYLIST="list_dpkg_output" - list_packet_files > "$COPYLIST" + [ -e "${COPYLIST}" ] && rm "${COPYLIST}" + list_packet_files >> "${COPYLIST}" tarcopy "$(cat "${COPYLIST}" | sort -u)" "${MODULE_BUILD_DIR}" } diff --git a/core/modules/libvirt/module.conf b/core/modules/libvirt/module.conf new file mode 100644 index 00000000..a9bf588e --- /dev/null +++ b/core/modules/libvirt/module.conf @@ -0,0 +1 @@ +#!/bin/bash diff --git a/core/modules/libvirt/module.conf.ubuntu.18 b/core/modules/libvirt/module.conf.ubuntu.18 deleted file mode 100644 index fbe60f37..00000000 --- a/core/modules/libvirt/module.conf.ubuntu.18 +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -REQUIRED_INSTALLED_PACKAGES=" - libvirt-bin - virt-manager - virt-viewer -" - -REQUIRED_CONTENT_PACKAGES=" - libvirt-bin - virt-manager - virt-viewer -" diff --git a/core/modules/libvirt/module.conf.ubuntu.18.04 b/core/modules/libvirt/module.conf.ubuntu.18.04 new file mode 100644 index 00000000..fbe60f37 --- /dev/null +++ b/core/modules/libvirt/module.conf.ubuntu.18.04 @@ -0,0 +1,12 @@ +#!/bin/bash +REQUIRED_INSTALLED_PACKAGES=" + libvirt-bin + virt-manager + virt-viewer +" + +REQUIRED_CONTENT_PACKAGES=" + libvirt-bin + virt-manager + virt-viewer +" diff --git a/core/modules/libvirt/module.conf.ubuntu.20 b/core/modules/libvirt/module.conf.ubuntu.20 deleted file mode 100644 index a4ecd34a..00000000 --- a/core/modules/libvirt/module.conf.ubuntu.20 +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -REQUIRED_INSTALLED_PACKAGES=" - libvirt-daemon-system - libvirt-daemon - libvirt-clients - virt-manager - virt-viewer -" - -REQUIRED_CONTENT_PACKAGES=" - libvirt-daemon-system - libvirt-daemon - libvirt-clients - virt-manager - virt-viewer -" diff --git a/core/modules/libvirt/module.conf.ubuntu.20.04 b/core/modules/libvirt/module.conf.ubuntu.20.04 new file mode 100644 index 00000000..a4ecd34a --- /dev/null +++ b/core/modules/libvirt/module.conf.ubuntu.20.04 @@ -0,0 +1,16 @@ +#!/bin/bash +REQUIRED_INSTALLED_PACKAGES=" + libvirt-daemon-system + libvirt-daemon + libvirt-clients + virt-manager + virt-viewer +" + +REQUIRED_CONTENT_PACKAGES=" + libvirt-daemon-system + libvirt-daemon + libvirt-clients + virt-manager + virt-viewer +" -- cgit v1.2.3-55-g7522 From 150b2366f88788b1415e6c43f33043ef4df908cb Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Fri, 5 Feb 2021 09:17:43 +0100 Subject: [qemu] Add empty Maven project for 'qemu' runvirt plugin --- core/modules/qemu/module.conf.debian | 4 ++ core/modules/qemu/module.conf.ubuntu | 4 ++ core/modules/qemu/runvirt-plugin-qemu/.gitignore | 3 + core/modules/qemu/runvirt-plugin-qemu/pom.xml | 84 ++++++++++++++++++++++ .../java/org/openslx/runvirt/plugin/qemu/App.java | 12 ++++ .../org/openslx/runvirt/plugin/qemu/AppTest.java | 20 ++++++ 6 files changed, 127 insertions(+) create mode 100644 core/modules/qemu/runvirt-plugin-qemu/.gitignore create mode 100644 core/modules/qemu/runvirt-plugin-qemu/pom.xml create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/AppTest.java diff --git a/core/modules/qemu/module.conf.debian b/core/modules/qemu/module.conf.debian index d4af965d..f4892d81 100644 --- a/core/modules/qemu/module.conf.debian +++ b/core/modules/qemu/module.conf.debian @@ -2,6 +2,9 @@ REQUIRED_INSTALLED_PACKAGES=" qemu qemu-kvm + mvn + openjdk-11-jdk-headless + openjdk-11-jre " REQUIRED_CONTENT_PACKAGES=" @@ -13,4 +16,5 @@ REQUIRED_CONTENT_PACKAGES=" qemu-utils seabios ovmf + openjdk-11-jre " diff --git a/core/modules/qemu/module.conf.ubuntu b/core/modules/qemu/module.conf.ubuntu index d4af965d..651d7a37 100644 --- a/core/modules/qemu/module.conf.ubuntu +++ b/core/modules/qemu/module.conf.ubuntu @@ -2,6 +2,9 @@ REQUIRED_INSTALLED_PACKAGES=" qemu qemu-kvm + mvn + openjdk-8-jdk-headless + openjdk-8-jre " REQUIRED_CONTENT_PACKAGES=" @@ -13,4 +16,5 @@ REQUIRED_CONTENT_PACKAGES=" qemu-utils seabios ovmf + openjdk-8-jre " diff --git a/core/modules/qemu/runvirt-plugin-qemu/.gitignore b/core/modules/qemu/runvirt-plugin-qemu/.gitignore new file mode 100644 index 00000000..49b2bfee --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/.gitignore @@ -0,0 +1,3 @@ +/target/ +.classpath +.settings/ diff --git a/core/modules/qemu/runvirt-plugin-qemu/pom.xml b/core/modules/qemu/runvirt-plugin-qemu/pom.xml new file mode 100644 index 00000000..d4aace6e --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/pom.xml @@ -0,0 +1,84 @@ + + + + 4.0.0 + + org.openslx.runvirt.plugin.qemu + runvirt-plugin-qemu + 1.0-SNAPSHOT + + runvirt-plugin-qemu + https://git.openslx.org/openslx-ng/mltk.git/ + + + UTF-8 + 1.8 + 1.8 + + + + + org.junit.jupiter + junit-jupiter-api + 5.7.1 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.7.1 + test + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-failsafe-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java new file mode 100644 index 00000000..ce6e7e12 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java @@ -0,0 +1,12 @@ +package org.openslx.runvirt.plugin.qemu; + +/** + * Hello world! + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/AppTest.java b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/AppTest.java new file mode 100644 index 00000000..90b658cd --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/AppTest.java @@ -0,0 +1,20 @@ +package org.openslx.runvirt.plugin.qemu; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +/** + * Unit test for simple App. + */ +public class AppTest +{ + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() + { + assertTrue( true ); + } +} -- cgit v1.2.3-55-g7522 From 1cd128ea0a58403c09d90323ee10021848a227b4 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Fri, 5 Feb 2021 11:09:28 +0100 Subject: [libvirt] Install/Copy package files into MiniLinux --- core/modules/libvirt/module.conf | 56 +++++++++++++++++++++++++++ core/modules/libvirt/module.conf.debian | 2 - core/modules/libvirt/module.conf.ubuntu.18.04 | 2 - core/modules/libvirt/module.conf.ubuntu.20.04 | 2 - 4 files changed, 56 insertions(+), 6 deletions(-) diff --git a/core/modules/libvirt/module.conf b/core/modules/libvirt/module.conf index a9bf588e..bcc4b9f4 100644 --- a/core/modules/libvirt/module.conf +++ b/core/modules/libvirt/module.conf @@ -1 +1,57 @@ #!/bin/bash + +REQUIRED_BINARIES=" + libvirtd + virtlockd + virtlogd + virt-sanlock-cleanup + remote-viewer + virsh + virt-admin + virt-host-validate + virt-login-shell + virt-pki-validate + virt-viewer + virt-xml-validate + libvirt-guests.sh + libvirt_iohelper + libvirt_leaseshelper + libvirt_lxc + libvirt_parthelper + libvirt_sanlock_helper + virt-aa-helper + virt-login-shell-helper +" +REQUIRED_FILES=" + /usr/lib/x86_64-linux-gnu/libvirt/connection-driver/libvirt_driver_interface.so + /usr/lib/x86_64-linux-gnu/libvirt/connection-driver/libvirt_driver_network.so + /usr/lib/x86_64-linux-gnu/libvirt/connection-driver/libvirt_driver_nodedev.so + /usr/lib/x86_64-linux-gnu/libvirt/connection-driver/libvirt_driver_nwfilter.so + /usr/lib/x86_64-linux-gnu/libvirt/connection-driver/libvirt_driver_secret.so + /usr/lib/x86_64-linux-gnu/libvirt/connection-driver/libvirt_driver_storage.so + /usr/lib/x86_64-linux-gnu/libvirt/lock-driver/lockd.so + /usr/lib/x86_64-linux-gnu/libvirt/storage-backend/libvirt_storage_backend_disk.so + /usr/lib/x86_64-linux-gnu/libvirt/storage-backend/libvirt_storage_backend_fs.so + /usr/lib/x86_64-linux-gnu/libvirt/storage-backend/libvirt_storage_backend_iscsi.so + /usr/lib/x86_64-linux-gnu/libvirt/storage-backend/libvirt_storage_backend_logical.so + /usr/lib/x86_64-linux-gnu/libvirt/storage-backend/libvirt_storage_backend_mpath.so + /usr/lib/x86_64-linux-gnu/libvirt/storage-backend/libvirt_storage_backend_scsi.so + /usr/lib/x86_64-linux-gnu/libvirt/storage-file/libvirt_storage_file_fs.so +" +REQUIRED_DIRECTORIES=" + /etc + /usr/lib/libvirt + /usr/lib/systemd + /usr/share/mime + /usr/share/icons + /usr/share/systemtap + /usr/share/apport + /usr/share/augeas + /usr/share/bash-completion + /usr/share/polkit-1 + /usr/share/appdata + /usr/share/bug + /usr/share/locale + /usr/share/applications + /var +" diff --git a/core/modules/libvirt/module.conf.debian b/core/modules/libvirt/module.conf.debian index a4ecd34a..66627d5a 100644 --- a/core/modules/libvirt/module.conf.debian +++ b/core/modules/libvirt/module.conf.debian @@ -3,7 +3,6 @@ REQUIRED_INSTALLED_PACKAGES=" libvirt-daemon-system libvirt-daemon libvirt-clients - virt-manager virt-viewer " @@ -11,6 +10,5 @@ REQUIRED_CONTENT_PACKAGES=" libvirt-daemon-system libvirt-daemon libvirt-clients - virt-manager virt-viewer " diff --git a/core/modules/libvirt/module.conf.ubuntu.18.04 b/core/modules/libvirt/module.conf.ubuntu.18.04 index fbe60f37..10414a9e 100644 --- a/core/modules/libvirt/module.conf.ubuntu.18.04 +++ b/core/modules/libvirt/module.conf.ubuntu.18.04 @@ -1,12 +1,10 @@ #!/bin/bash REQUIRED_INSTALLED_PACKAGES=" libvirt-bin - virt-manager virt-viewer " REQUIRED_CONTENT_PACKAGES=" libvirt-bin - virt-manager virt-viewer " diff --git a/core/modules/libvirt/module.conf.ubuntu.20.04 b/core/modules/libvirt/module.conf.ubuntu.20.04 index a4ecd34a..66627d5a 100644 --- a/core/modules/libvirt/module.conf.ubuntu.20.04 +++ b/core/modules/libvirt/module.conf.ubuntu.20.04 @@ -3,7 +3,6 @@ REQUIRED_INSTALLED_PACKAGES=" libvirt-daemon-system libvirt-daemon libvirt-clients - virt-manager virt-viewer " @@ -11,6 +10,5 @@ REQUIRED_CONTENT_PACKAGES=" libvirt-daemon-system libvirt-daemon libvirt-clients - virt-manager virt-viewer " -- cgit v1.2.3-55-g7522 From 5bedad1a4b1d98dab66cef77684d59c43f5be88a Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Fri, 5 Feb 2021 14:26:42 +0100 Subject: [openjdk-8-jre-headless] Add Java runtime environment 8 as new module --- core/modules/openjdk-8-jre-headless/module.build | 17 +++++++++++++++++ core/modules/openjdk-8-jre-headless/module.conf | 10 ++++++++++ .../modules/openjdk-8-jre-headless/module.config.ubuntu | 9 +++++++++ core/targets/qemu/openjdk-8-jre-headless | 1 + 4 files changed, 37 insertions(+) create mode 100644 core/modules/openjdk-8-jre-headless/module.build create mode 100644 core/modules/openjdk-8-jre-headless/module.conf create mode 100644 core/modules/openjdk-8-jre-headless/module.config.ubuntu create mode 120000 core/targets/qemu/openjdk-8-jre-headless diff --git a/core/modules/openjdk-8-jre-headless/module.build b/core/modules/openjdk-8-jre-headless/module.build new file mode 100644 index 00000000..5854e16a --- /dev/null +++ b/core/modules/openjdk-8-jre-headless/module.build @@ -0,0 +1,17 @@ +#!/bin/bash + +fetch_source() { + : +} + +build() { + # copy mandatory system packages + COPYLIST="list_dpkg_output" + [ -e "${COPYLIST}" ] && rm "${COPYLIST}" + list_packet_files >> "${COPYLIST}" + tarcopy "$(cat "${COPYLIST}" | sort -u)" "${MODULE_BUILD_DIR}" +} + +post_copy() { + : +} diff --git a/core/modules/openjdk-8-jre-headless/module.conf b/core/modules/openjdk-8-jre-headless/module.conf new file mode 100644 index 00000000..fba37fa8 --- /dev/null +++ b/core/modules/openjdk-8-jre-headless/module.conf @@ -0,0 +1,10 @@ +#!/bin/bash + +REQUIRED_BINARIES=" + java +" + +REQUIRED_DIRECTORIES=" + /etc + /usr/lib/jvm/java-8-openjdk-amd64/jre/lib +" diff --git a/core/modules/openjdk-8-jre-headless/module.config.ubuntu b/core/modules/openjdk-8-jre-headless/module.config.ubuntu new file mode 100644 index 00000000..aa99a07c --- /dev/null +++ b/core/modules/openjdk-8-jre-headless/module.config.ubuntu @@ -0,0 +1,9 @@ +#!/bin/bash + +REQUIRED_INSTALLED_PACKAGES=" + openjdk-8-jre-headless +" + +REQUIRED_CONTENT_PACKAGES=" + openjdk-8-jre-headless +" \ No newline at end of file diff --git a/core/targets/qemu/openjdk-8-jre-headless b/core/targets/qemu/openjdk-8-jre-headless new file mode 120000 index 00000000..b899a6a4 --- /dev/null +++ b/core/targets/qemu/openjdk-8-jre-headless @@ -0,0 +1 @@ +../../modules/openjdk-8-jre-headless/ \ No newline at end of file -- cgit v1.2.3-55-g7522 From 27a7b7273bff3386d79a82a5ec56b5eed8afd908 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Fri, 5 Feb 2021 14:30:22 +0100 Subject: [openjdk-8-jre-headless] Rename wrong Ubuntu config file name --- core/modules/openjdk-8-jre-headless/module.conf.ubuntu | 9 +++++++++ core/modules/openjdk-8-jre-headless/module.config.ubuntu | 9 --------- 2 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 core/modules/openjdk-8-jre-headless/module.conf.ubuntu delete mode 100644 core/modules/openjdk-8-jre-headless/module.config.ubuntu diff --git a/core/modules/openjdk-8-jre-headless/module.conf.ubuntu b/core/modules/openjdk-8-jre-headless/module.conf.ubuntu new file mode 100644 index 00000000..aa99a07c --- /dev/null +++ b/core/modules/openjdk-8-jre-headless/module.conf.ubuntu @@ -0,0 +1,9 @@ +#!/bin/bash + +REQUIRED_INSTALLED_PACKAGES=" + openjdk-8-jre-headless +" + +REQUIRED_CONTENT_PACKAGES=" + openjdk-8-jre-headless +" \ No newline at end of file diff --git a/core/modules/openjdk-8-jre-headless/module.config.ubuntu b/core/modules/openjdk-8-jre-headless/module.config.ubuntu deleted file mode 100644 index aa99a07c..00000000 --- a/core/modules/openjdk-8-jre-headless/module.config.ubuntu +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -REQUIRED_INSTALLED_PACKAGES=" - openjdk-8-jre-headless -" - -REQUIRED_CONTENT_PACKAGES=" - openjdk-8-jre-headless -" \ No newline at end of file -- cgit v1.2.3-55-g7522 From b2dcc3e01cb2de8a3665c55f731e8a2dd97eff40 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Fri, 5 Feb 2021 14:33:56 +0100 Subject: [qemu] Add support to build the qemu runvirt plugin --- core/modules/qemu/module.build | 19 ++++++++++++++++++- core/modules/qemu/module.conf | 36 +++++++++++++++++++++++++++++++++++- core/modules/qemu/module.conf.debian | 20 -------------------- core/modules/qemu/module.conf.ubuntu | 5 ++--- 4 files changed, 55 insertions(+), 25 deletions(-) delete mode 100644 core/modules/qemu/module.conf.debian diff --git a/core/modules/qemu/module.build b/core/modules/qemu/module.build index fc1bc074..d1d9a691 100644 --- a/core/modules/qemu/module.build +++ b/core/modules/qemu/module.build @@ -1,13 +1,30 @@ #!/bin/bash + fetch_source() { - : + # copy qemu runvirt plugin source to working directory + local src_dir="${MODULE_DIR}/runvirt-plugin-qemu" + local dst_dir="${MODULE_WORK_DIR}/src" + mkdir -p "${dst_dir}" || perror "Could not create source folder for qemu runvirt plugin!" + cp -r "${src_dir}" "${dst_dir}" || perror "Could not copy source files for qemu runvirt plugin!" } build() { + # copy mandatory system packages COPYLIST="list_dpkg_output" [ -e "${COPYLIST}" ] && rm "${COPYLIST}" list_packet_files >> "${COPYLIST}" tarcopy "$(cat "${COPYLIST}" | sort -u)" "${MODULE_BUILD_DIR}" + + # build qemu runvirt plugin + local build_dir="${MODULE_WORK_DIR}/src/runvirt-plugin-qemu" + mvn -f "${build_dir}" clean package || perror "Could not build runvirt-plugin-qemu with Maven!" + + # install qemu runvirt plugin + local build_artifact_filename="runvirt-plugin-qemu-1.0-SNAPSHOT.jar" + local install_dir="${MODULE_BUILD_DIR}/opt/openslx/share/java" + local install_filename="runvirt-plugin-qemu.jar" + mkdir -p "${install_dir}" + cp "${build_dir}/target/${build_artifact_filename}" "${install_dir}/${install_filename}" || perror "Could not install runvirt-plugin-qemu!" } post_copy() { diff --git a/core/modules/qemu/module.conf b/core/modules/qemu/module.conf index 61069809..def35459 100644 --- a/core/modules/qemu/module.conf +++ b/core/modules/qemu/module.conf @@ -1,2 +1,36 @@ #!/bin/bash -REQUIRED_MODULES="libvirt" + +REQUIRED_MODULES=" + libvirt + openjdk-8-jre-headless +" + +REQUIRED_BINARIES=" + ivshmem-client + ivshmem-server + kvm + qemu-img + qemu-io + qemu-nbd + qemu-pr-helper + qemu-system-aarch64 + qemu-system-arm + qemu-system-i386 + qemu-system-x86_64 + virtfs-proxy-helper + qemu-make-debian-root + qemu-bridge-helper + vhost-user-gpu +" + +REQUIRED_DIRECTORIES=" + /etc + /usr/share/ovmf + /usr/share/OVMF + /usr/share/qemu + /usr/share/seabios +" + +REQUIRED_FILES=" + /opt/openslx/share/java/runvirt-plugin-qemu.jar +" diff --git a/core/modules/qemu/module.conf.debian b/core/modules/qemu/module.conf.debian deleted file mode 100644 index f4892d81..00000000 --- a/core/modules/qemu/module.conf.debian +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -REQUIRED_INSTALLED_PACKAGES=" - qemu - qemu-kvm - mvn - openjdk-11-jdk-headless - openjdk-11-jre -" - -REQUIRED_CONTENT_PACKAGES=" - qemu - qemu-kvm - qemu-system-common - qemu-system-arm - qemu-system-x86 - qemu-utils - seabios - ovmf - openjdk-11-jre -" diff --git a/core/modules/qemu/module.conf.ubuntu b/core/modules/qemu/module.conf.ubuntu index 651d7a37..5f9bc981 100644 --- a/core/modules/qemu/module.conf.ubuntu +++ b/core/modules/qemu/module.conf.ubuntu @@ -1,10 +1,10 @@ #!/bin/bash + REQUIRED_INSTALLED_PACKAGES=" qemu qemu-kvm - mvn + maven openjdk-8-jdk-headless - openjdk-8-jre " REQUIRED_CONTENT_PACKAGES=" @@ -16,5 +16,4 @@ REQUIRED_CONTENT_PACKAGES=" qemu-utils seabios ovmf - openjdk-8-jre " -- cgit v1.2.3-55-g7522 From c5788c0b4073bc510b3084dbbff2cea73b2f55cf Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Mon, 8 Feb 2021 09:17:46 +0100 Subject: [qemu] Replace lazy load of KVM kernel modules --- .../qemu/data/opt/openslx/scripts/systemd-qemu_env | 29 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/core/modules/qemu/data/opt/openslx/scripts/systemd-qemu_env b/core/modules/qemu/data/opt/openslx/scripts/systemd-qemu_env index c8343cd5..3355b7a0 100755 --- a/core/modules/qemu/data/opt/openslx/scripts/systemd-qemu_env +++ b/core/modules/qemu/data/opt/openslx/scripts/systemd-qemu_env @@ -16,12 +16,31 @@ # - This is the preparation script for the configuration of QEMU on Linux. ################################################################################ -# lazy load all kvm related modules -modprobe kvm -modprobe kvm_amd -modprobe kvm_intel +# +# load general KVM module +# +modprobe "kvm" || slxlog "qemu" "Could not load 'kvm' kernel modul!" + +# +# load CPU specific KVM implementation +# +virt=$(egrep -m1 -w '^flags[[:blank:]]*:' /proc/cpuinfo | egrep -wo '(vmx|svm)') || true +if [ "${virt}" = "vmx" ]; then + kmod="kvm_intel" +elif [ "${virt}" = "svm" ]; then + kmod="kvm_amd" +else + slxlog "qemu" "CPU does not support KVM extensions!" + exit 1 +fi + +modprobe "${kmod}" || slxlog "qemu" "Could not load '${kmod}' kernel modul!" + +# +# check that the KVM exposed device exists +# if [ ! -e /dev/kvm ]; then - slxlog "qemu-modules" "/dev/kvm not found! Missing kvm kernel module(s)?" + slxlog "qemu" "/dev/kvm not found! Missing kvm kernel module(s)?" exit 1 fi -- cgit v1.2.3-55-g7522 From 3ce16192db58bdbf2bd8fb5f8d85f2dd9a93ff80 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Mon, 8 Feb 2021 09:32:10 +0100 Subject: [qemu] Start 'qemu' after 'libvirtd' is ready --- .../qemu/data/etc/systemd/system/graphical.target.wants/qemu.service | 1 + .../qemu/data/etc/systemd/system/graphical.target.wants/qemukvm.service | 1 - core/modules/qemu/data/etc/systemd/system/qemu.service | 2 ++ 3 files changed, 3 insertions(+), 1 deletion(-) create mode 120000 core/modules/qemu/data/etc/systemd/system/graphical.target.wants/qemu.service delete mode 120000 core/modules/qemu/data/etc/systemd/system/graphical.target.wants/qemukvm.service diff --git a/core/modules/qemu/data/etc/systemd/system/graphical.target.wants/qemu.service b/core/modules/qemu/data/etc/systemd/system/graphical.target.wants/qemu.service new file mode 120000 index 00000000..a301779d --- /dev/null +++ b/core/modules/qemu/data/etc/systemd/system/graphical.target.wants/qemu.service @@ -0,0 +1 @@ +../qemu.service \ No newline at end of file diff --git a/core/modules/qemu/data/etc/systemd/system/graphical.target.wants/qemukvm.service b/core/modules/qemu/data/etc/systemd/system/graphical.target.wants/qemukvm.service deleted file mode 120000 index 89d8afbf..00000000 --- a/core/modules/qemu/data/etc/systemd/system/graphical.target.wants/qemukvm.service +++ /dev/null @@ -1 +0,0 @@ -../qemukvm.service \ No newline at end of file diff --git a/core/modules/qemu/data/etc/systemd/system/qemu.service b/core/modules/qemu/data/etc/systemd/system/qemu.service index 914e956c..7a1d3b4d 100644 --- a/core/modules/qemu/data/etc/systemd/system/qemu.service +++ b/core/modules/qemu/data/etc/systemd/system/qemu.service @@ -1,7 +1,9 @@ [Unit] Description=Sets up the QEMU hypervisor Requires=run-virt-env.service +Requires=libvirtd.service After=run-virt-env.service +After=libvirtd.service [Service] Type=oneshot -- cgit v1.2.3-55-g7522 From c157235d20b02f8917899a1e57e097371e877b5c Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Mon, 8 Feb 2021 10:06:31 +0100 Subject: [libvirt] Remove default network configuration --- core/modules/libvirt/module.build | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/modules/libvirt/module.build b/core/modules/libvirt/module.build index fc1bc074..2e2f8e12 100644 --- a/core/modules/libvirt/module.build +++ b/core/modules/libvirt/module.build @@ -11,5 +11,9 @@ build() { } post_copy() { - : + # + # remove default network configuration + # + rm /etc/libvirt/qemu/networks/default.xml + rm /etc/libvirt/qemu/networks/autostart/default.xml } -- cgit v1.2.3-55-g7522 From bd52d04d486fafb7b781b3d7ee4eff936a17c53a Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Mon, 8 Feb 2021 10:07:38 +0100 Subject: [libvirt] Add user and groups to run libvirt --- core/modules/libvirt/data/addon-init | 78 ++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/core/modules/libvirt/data/addon-init b/core/modules/libvirt/data/addon-init index 8070d171..034eb22a 100755 --- a/core/modules/libvirt/data/addon-init +++ b/core/modules/libvirt/data/addon-init @@ -1,4 +1,82 @@ #!/bin/ash +# +# allocated UID and GID for libvirt-qemu +# +LIBVIRT_QEMU_UID=64055 +LIBVIRT_QEMU_GID=64055 + +# +# add groups to run libvirt +# +if ! getent group libvirt >/dev/null; then + addgroup --quiet --system libvirt +fi + +if ! getent group kvm >/dev/null; then + addgroup --quiet --system kvm +fi + +# +# add user and group libvirt runs qemu/kvm instances with +# +if ! getent passwd libvirt-qemu >/dev/null; then + + # set uid if available (expected); don't fail otherwise. + PARAMETER_UID='' + if ! getent passwd $LIBVIRT_QEMU_UID >/dev/null; then + PARAMETER_UID="--uid $LIBVIRT_QEMU_UID" + fi + + adduser --quiet \ + --system \ + --ingroup kvm \ + --quiet \ + --disabled-login \ + --disabled-password \ + --home /var/lib/libvirt \ + --no-create-home \ + --gecos "Libvirt Qemu" \ + $PARAMETER_UID \ + libvirt-qemu +fi + +if ! getent group libvirt-qemu >/dev/null; then + + # set gid if available (expected); don't fail otherwise. + PARAMETER_GID='' + if ! getent group $LIBVIRT_QEMU_GID >/dev/null; then + PARAMETER_GID="--gid $LIBVIRT_QEMU_GID" + fi + + addgroup --quiet --system $PARAMETER_GID libvirt-qemu + adduser --quiet libvirt-qemu libvirt-qemu +fi + +# +# add each sudo user to the libvirt group +# +for u in $(getent group sudo | sed -e "s/^.*://" -e "s/,/ /g"); do + adduser "$u" libvirt >/dev/null || true +done + +if ! getent group libvirt-dnsmasq >/dev/null; then + addgroup --quiet --system libvirt-dnsmasq +fi +if ! getent passwd libvirt-dnsmasq >/dev/null; then + adduser --quiet \ + --system \ + --ingroup libvirt-dnsmasq \ + --disabled-login \ + --disabled-password \ + --home /var/lib/libvirt/dnsmasq \ + --no-create-home \ + --gecos "Libvirt Dnsmasq" \ + libvirt-dnsmasq +fi + +# +# register and start libvirt service +# systemctl daemon-reload systemctl start libvirtd.service -- cgit v1.2.3-55-g7522 From 50c7465038361b080ccc81559e25de0375fbb407 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Tue, 9 Feb 2021 08:15:31 +0100 Subject: [libvirt] Add definition default bwLehrpool networks --- .../modules/libvirt/data/etc/libvirt/qemu/networks/autostart/br0.xml | 1 + .../libvirt/data/etc/libvirt/qemu/networks/autostart/nat1.xml | 1 + .../libvirt/data/etc/libvirt/qemu/networks/autostart/vsw2.xml | 1 + core/modules/libvirt/data/etc/libvirt/qemu/networks/br0.xml | 5 +++++ core/modules/libvirt/data/etc/libvirt/qemu/networks/nat1.xml | 5 +++++ core/modules/libvirt/data/etc/libvirt/qemu/networks/vsw2.xml | 5 +++++ core/modules/libvirt/module.build | 4 ++-- 7 files changed, 20 insertions(+), 2 deletions(-) create mode 120000 core/modules/libvirt/data/etc/libvirt/qemu/networks/autostart/br0.xml create mode 120000 core/modules/libvirt/data/etc/libvirt/qemu/networks/autostart/nat1.xml create mode 120000 core/modules/libvirt/data/etc/libvirt/qemu/networks/autostart/vsw2.xml create mode 100644 core/modules/libvirt/data/etc/libvirt/qemu/networks/br0.xml create mode 100644 core/modules/libvirt/data/etc/libvirt/qemu/networks/nat1.xml create mode 100644 core/modules/libvirt/data/etc/libvirt/qemu/networks/vsw2.xml diff --git a/core/modules/libvirt/data/etc/libvirt/qemu/networks/autostart/br0.xml b/core/modules/libvirt/data/etc/libvirt/qemu/networks/autostart/br0.xml new file mode 120000 index 00000000..e31f4a71 --- /dev/null +++ b/core/modules/libvirt/data/etc/libvirt/qemu/networks/autostart/br0.xml @@ -0,0 +1 @@ +../br0.xml \ No newline at end of file diff --git a/core/modules/libvirt/data/etc/libvirt/qemu/networks/autostart/nat1.xml b/core/modules/libvirt/data/etc/libvirt/qemu/networks/autostart/nat1.xml new file mode 120000 index 00000000..9e35bd99 --- /dev/null +++ b/core/modules/libvirt/data/etc/libvirt/qemu/networks/autostart/nat1.xml @@ -0,0 +1 @@ +../nat1.xml \ No newline at end of file diff --git a/core/modules/libvirt/data/etc/libvirt/qemu/networks/autostart/vsw2.xml b/core/modules/libvirt/data/etc/libvirt/qemu/networks/autostart/vsw2.xml new file mode 120000 index 00000000..1600f8a6 --- /dev/null +++ b/core/modules/libvirt/data/etc/libvirt/qemu/networks/autostart/vsw2.xml @@ -0,0 +1 @@ +../vsw2.xml \ No newline at end of file diff --git a/core/modules/libvirt/data/etc/libvirt/qemu/networks/br0.xml b/core/modules/libvirt/data/etc/libvirt/qemu/networks/br0.xml new file mode 100644 index 00000000..cf0876dc --- /dev/null +++ b/core/modules/libvirt/data/etc/libvirt/qemu/networks/br0.xml @@ -0,0 +1,5 @@ + + br0 + + + diff --git a/core/modules/libvirt/data/etc/libvirt/qemu/networks/nat1.xml b/core/modules/libvirt/data/etc/libvirt/qemu/networks/nat1.xml new file mode 100644 index 00000000..3411fbbb --- /dev/null +++ b/core/modules/libvirt/data/etc/libvirt/qemu/networks/nat1.xml @@ -0,0 +1,5 @@ + + nat1 + + + diff --git a/core/modules/libvirt/data/etc/libvirt/qemu/networks/vsw2.xml b/core/modules/libvirt/data/etc/libvirt/qemu/networks/vsw2.xml new file mode 100644 index 00000000..cc40a0c3 --- /dev/null +++ b/core/modules/libvirt/data/etc/libvirt/qemu/networks/vsw2.xml @@ -0,0 +1,5 @@ + + vsw2 + + + diff --git a/core/modules/libvirt/module.build b/core/modules/libvirt/module.build index 2e2f8e12..141e076e 100644 --- a/core/modules/libvirt/module.build +++ b/core/modules/libvirt/module.build @@ -14,6 +14,6 @@ post_copy() { # # remove default network configuration # - rm /etc/libvirt/qemu/networks/default.xml - rm /etc/libvirt/qemu/networks/autostart/default.xml + rm "${MODULE_BUILD_DIR}/etc/libvirt/qemu/networks/default.xml" + rm "${MODULE_BUILD_DIR}/etc/libvirt/qemu/networks/autostart/default.xml" } -- cgit v1.2.3-55-g7522 From d7e17204f14f90d0c2c1f8fb71d3e68edda9d83d Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Tue, 9 Feb 2021 10:05:18 +0100 Subject: [qemu] Remove unused run-virt includes --- .../includes/determine_hardware_limitations.inc | 89 ---------------------- .../qemu/includes/finalize_start_command.inc | 49 ------------ .../vmchooser/plugins/qemu/includes/init_core.inc | 54 ------------- .../plugins/qemu/includes/log_config_summary.inc | 35 --------- .../plugins/qemu/includes/setup_network.inc | 56 -------------- .../plugins/qemu/includes/setup_rw_layer.inc | 25 ------ 6 files changed, 308 deletions(-) delete mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/determine_hardware_limitations.inc delete mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/finalize_start_command.inc delete mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/init_core.inc delete mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/log_config_summary.inc delete mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/setup_network.inc delete mode 100644 core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/setup_rw_layer.inc diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/determine_hardware_limitations.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/determine_hardware_limitations.inc deleted file mode 100644 index dd83b587..00000000 --- a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/determine_hardware_limitations.inc +++ /dev/null @@ -1,89 +0,0 @@ -################################################################## -# qemu/kvm include: determine virtual hardware based on guest OS # -################################################################## - -set_vm_hw_limits() { - # FIXME when we have better metadata for qemu - if isempty VM_OS_TYPE; then - writelog "VM_OS_TYPE is empty! This should have been parsed from the XML file" - EXIT_TYPE="user" EXIT_REASON="Konnte Gastbetriebsystems der virtuellen Maschine nicht ermitteln!" cleanexit 1 - fi - - # define global hardware-related variables - declare -g MAXMEM="9999999" - declare -g MAXCORES="4" - declare -g SOUND_DEV="es1370" - - # determine if we need a 32bit or 64bit machine - # FIXME depending on the guest OS for now - # (sadly does not support all the exotic OSs the - # the world has even seen like vmware plugin :<) - local bits=64 - case "${VM_OS_TYPE}" in - beos*) - bits=32 - SOUND_DEV="sb16" - ;; - win3*|win*3*|Win*3*) - bits=32 - SOUND_DEV="sb16" - MAXMEM=32 - ;; - win95*|Win*95) - bits=32 - MAXMEM=96 - ;; - win98) - bits=32 - MAXMEM=256 - ;; - winme*|windowsme*) - bits=32 - SOUND_DEV="ac97" - MAXMEM=384 - ;; - winxp*64|windowsxp*64) - SOUND_DEV="ac97" - ;; - windows7|windows8|windows9) - SOUND_DEV="ac97" - MAXMEM="8000" - MAXCORES="4" - ;; - windows7-64|windows8-64|windows9-64) - SOUND_DEV="ac97" - MAXMEM="32000" - MAXCORES="8" - ;; - *64) - MAXMEM="16000" - MAXCORES="4" - ;; - *) - bits=32 - MAXMEM="8000" - MAXCORES="1" - ;; - esac - declare -g VIRTCMD - if [ "$bits" = 32 ]; then - declare -rg VIRTCMD="qemu-system-i386" - VIRTCMDOPTS+=( "-machine" "accel=tcg" ) # TODO: 32bit VMs can't use kvm!? - else # 64 bit - declare -rg VIRTCMD="qemu-system-x86_64" - VIRTCMDOPTS+=( "-machine" "accel=kvm" ) - fi - - - # check for allocated cores - declare -g CPU_CORES="${HW_THREADS:-1}" - declare -rg HOST_CORE_COUNT="${CPU_CORES}" - [ "${CPU_CORES}" -gt "${MAXCORES}" ] && CPU_CORES="${MAXCORES}" - - # check if memory set by the generic run-virt is above the threshold - [ "${VM_MEM}" -gt "${MAXMEM}" ] && VM_MEM="${MAXMEM}" - return 0 -} - -## MAIN ## -call_post_source set_vm_hw_limits diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/finalize_start_command.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/finalize_start_command.inc deleted file mode 100644 index 6d9df363..00000000 --- a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/finalize_start_command.inc +++ /dev/null @@ -1,49 +0,0 @@ -# ----------------------------------------------------------------------------- -# -# Copyright (c) 2009..2018 bwLehrpool-Projektteam -# -# This program/file is free software distributed under the GPL version 2. -# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html -# -# If you have any feedback please consult https://bwlehrpool.de and -# send your feedback to bwlehrpool@hs-offenburg.de. -# -# General information about bwLehrpool can be found at https://bwlehrpool.de -# -# ----------------------------------------------------------------------------- -# run-virt.include -# - Include script for running the QEMU/Linux KVM virtual machine on an -# OpenSLX client via the run-virt.sh or run-vmgrid.sh -################################################################################ - -# set options that depend on previous includes -# and build the final start command -finalize_start_command() { - - # set cpu type - VIRTCMDOPTS+=( "-cpu" "host" ) - # set cpu cores - VIRTCMDOPTS+=( "-smp" "${CPU_CORES}" ) - - # set RAM - VIRTCMDOPTS+=( "-m" "${VM_MEM}" ) - - # special feature for real and virtual floppy disks - isset FLOPPY_0 && VIRTCMDOPTS+=( "-fda" "${FLOPPY_0}" ) - isset SLX_FLOPPY_IMG && VIRTCMDOPTS+=( "-fdb" "${SLX_FLOPPY_IMG}" ) - - # add optical drive if available - isset CDROM_0 && VIRTCMDOPTS+=( "-cdrom" "${CDROM_0}" ) - - # audio - isset SOUND_DEV && VIRTCMDOPTS+=( "-soundhw" "${SOUND_DEV}" ) - - # serial devices TODO test - if isset SERIAL_PORTS; then - for DEV in $SERIAL_PORTS; do - : # buggeh: VIRTCMDOPTS+=( "-serial" "${DEV}" ) - done - fi -} - -call_post_source finalize_start_command diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/init_core.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/init_core.inc deleted file mode 100644 index fee2cd1c..00000000 --- a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/init_core.inc +++ /dev/null @@ -1,54 +0,0 @@ -# ----------------------------------------------------------------------------- -# -# Copyright (c) 2009..2018 bwLehrpool-Projektteam -# -# This program/file is free software distributed under the GPL version 2. -# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html -# -# If you have any feedback please consult https://bwlehrpool.de and -# send your feedback to bwlehrpool@hs-offenburg.de. -# -# General information about bwLehrpool can be found at https://bwlehrpool.de -# -# ----------------------------------------------------------------------------- -# run-virt.include -# - Include script for running the QEMU/Linux KVM virtual machine on an -# OpenSLX client via the run-virt.sh or run-vmgrid.sh -################################################################################ - -# check if kvm kernel module are available -if [ ! -c /dev/kvm ]; then - writelog "KVM kernel modules not loaded!" - EXIT_TYPE="internal" EXIT_REASON="QEMU/KVM Virtualisierer nicht initialisiert!" cleanexit 1 -fi - -# check if qemu binaries are available -if ! check_dep qemu-system-{i386,x86_64}; then - writelog "QEMU binaries not available!" - EXIT_TYPE="internal" EXIT_REASON="QEMU/KVM Virtualisierer nicht initialisiert!" cleanexit 1 -fi - -# set general purpose options here, mostly evaluates information -# contained in /opt/openslx/vmchooser/config/virtualization.conf - -# TODO some options should come from the server, in particular -# - disk controller type (virtio, scsi, ide...) -# - arch to emulate (x86_64, i386, ...) -# - graphics mode? -# - sound dev? -# - tbd - -# display name, remove blanks because of cmdline problems -declare -rg CMD_DISPLAYNAME=$(echo ${VM_DISPLAYNAME} | sed -e "s, ,-,g;s,(,[,g;s,),],g") -VIRTCMDOPTS+=( "-name" "${CMD_DISPLAYNAME}" ) - -# graphical start: vga, vmware, qxl, spice? -VIRTCMDOPTS+=( "-vga" "std" "-full-screen" ) - -# hot keys ALT+CTRL+SHIFT (does not work properly!?) -VIRTCMDOPTS+=( "-alt-grab" ) - -# TODO support other types of boot? any usecase for network boot? -# for now just boot from disk -VIRTCMDOPTS+=( "-boot" "c" ) - diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/log_config_summary.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/log_config_summary.inc deleted file mode 100644 index 6b4b279f..00000000 --- a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/log_config_summary.inc +++ /dev/null @@ -1,35 +0,0 @@ -################################################## -# Include: Print vm config summary into log file # -################################################## - -log_config_summary() { - writelog "Directories:" - writelog "\tTMPDIR:\t\t\t$TMPDIR" - writelog "Disk image:" - writelog "\tSource disk:\t\t$VM_DISKFILE_RO" - if [ -e "${VM_DISKFILE_RW}" ]; then - writelog "\tDisk mode:\t\twritable" - writelog "\tRW-Layer:\t\t$VM_DISKFILE_RW" - else - writelog "\tDisk mode:\t\tread-only" - fi - - writelog "Virtual Hardware:" - writelog "\tvCPU cores:\t\t${CPU_CORES}" - writelog "\tGuest RAM:\t\t${VM_MEM} MB" - - # echo nur wenn HOST_MEM_REMAINING gesetzt - if isset HOST_MEM_REMAINING; then - writelog "\tHost RAM:\t\t${HOST_MEM_REMAINING} MB" - fi - writelog "\tMAC address:\t\t${VM_MAC_ADDR}" - writelog "\tNetwork card:\t\t${NIC_MODEL}" - writelog "\tNetwork kind:\t\t${NETWORK_MODE}" - writelog "\tCD-ROM1:\t${CDROM_0}" - writelog "\tCD-ROM2:\t${CDROM_1}" - writelog "\tFloppy_A:\t${FLOPPY_0}" - writelog "\tFloppy_B:\t${SLX_FLOPPY_IMG}" - #writelog "\tShared Folders 'home':\t/home/${USER}" -} - -call_post_source log_config_summary diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/setup_network.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/setup_network.inc deleted file mode 100644 index 73fb2518..00000000 --- a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/setup_network.inc +++ /dev/null @@ -1,56 +0,0 @@ -################################### -# qemu/kvm include: Network setup # -################################### -# This now makes use of the qemu's bridge helper -# which creates a tap device and adds it to the -# bridge corresponding to the network type -# TODO configurable network type -setup_network() { - # list available models with: - # qemu-system-x86_64 -net nic,model=? - # e.g. as of 2.0.0: - # ne2k_pci,i82551,i82557b,i82559er,rtl8139,e1000,pcnet,virtio - declare -rg NIC_MODEL="e1000" - - # add MAC address and network card model - VIRTCMDOPTS+=( "-device" "${NIC_MODEL},mac=${VM_MAC_ADDR},netdev=guestnet0" ) - - # TODO support different network kinds for lectures in bwlehrpool-suite, just NAT for now - declare -g NETWORK_MODE="nat" - - # detect if qemu's bridge helper binary is available - declare -g QEMU_BRIDGE_HELPER= - for HELPER_PATH in /usr/lib/qemu-bridge-helper /usr/local/libexec/qemu-bridge-helper; do - if [ -x "${HELPER_PATH}" ] && [ -u "${HELPER_PATH}" ]; then - QEMU_BRIDGE_HELPER="${HELPER_PATH}" - readonly QEMU_BRIDGE_HELPER - break - fi - done - if isempty QEMU_BRIDGE_HELPER; then - writelog "Could not find qemu-bridge-helper on this machine. Setting network mode to user." - # Even though falling back to creating tap devices ourselves, we should instead - # garantee the existance of qemu's helper on minilinux build time. - # qemu's user network mode allows tcp/udp connections in a nat-fashion and - # it allows access to the web which seems suffisant for a fallback. - NETWORK_MODE="user" - fi - - case "${NETWORK_MODE}" in - nat*) - VIRTCMDOPTS+=( "-netdev" "bridge,br=nat1,id=guestnet0,helper=${QEMU_BRIDGE_HELPER}" ) - ;; - bridge*) - VIRTCMDOPTS+=( "-netdev" "bridge,br=br0,id=guestnet0,helper=${QEMU_BRIDGE_HELPER}" ) - ;; - host*) - VIRTCMDOPTS+=( "-netdev" "bridge,br=vsw2,id=guestnet0,helper=${QEMU_BRIDGE_HELPER}" ) - ;; - user*|*) - VIRTCMDOPTS+=( "-netdev" "user,id=guestnet0" ) - ;; - esac -} - -## MAIN ## -call_post_source setup_network diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/setup_rw_layer.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/setup_rw_layer.inc deleted file mode 100644 index 32637e5d..00000000 --- a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/includes/setup_rw_layer.inc +++ /dev/null @@ -1,25 +0,0 @@ - -setup_rw_layer() { - if isempty VM_DISKFILE_RO; then - writelog "No source diskfile found! This should be specified in the given XML file. Is it valid?" - EXIT_TYPE="user" EXIT_REASON="Keine virtuelle Festplatte zu dieser Veranstaltung angegeben!" cleanexit 1 - fi - - # setup qcow2 backing file for that disk file - writelog "Creating backing file for '${VM_DISKFILE_RO}'..." - # TODO: WTF? This is fucked up, VM_DISKFILE_RW is set if we want to run in persistent mode, - # this plugin shouldn't mess around with it.... - declare -rg VM_DISKFILE_RW="${TMPDIR}/$(basename ${VM_DISKFILE_RO}).qcow2" - if qemu-img create -f qcow2 -b "${VM_DISKFILE_RO}" "${VM_DISKFILE_RW}"; then - # all good, use it as main disk drive - # TODO: determine the proper type of controller to use, ideally virtio? - VIRTCMDOPTS+=("-drive" "if=virtio,format=qcow2,file=${VM_DISKFILE_RW}" ) - else - writelog "Error creating backing file for '${VM_DISKFILE_RO}'" - # TODO use -snapshot as fallback, test it! - # How is this supposed to even work without a disk? - VIRTCMDOPTS+=( "-snapshot" ) - fi -} - -call_post_source setup_rw_layer -- cgit v1.2.3-55-g7522 From db718d9c2be08c873790236cb9456a31b59abc99 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Tue, 9 Feb 2021 10:40:55 +0100 Subject: [qemu] Call Java run-virt tool to finalize Libvirt configuration --- .../vmchooser/plugins/qemu/run-virt.include | 42 ++++++++++++---------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/run-virt.include b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/run-virt.include index 9f2b1291..ee9d8e36 100644 --- a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/run-virt.include +++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/run-virt.include @@ -19,26 +19,32 @@ declare -rg QEMU_PLUGIN_DIR="$(dirname "${BASH_SOURCE[0]}")" declare -rg QEMU_INCLUDE_DIR="${QEMU_PLUGIN_DIR}/includes" -# TODO make this part of the metadata coming from the server -# TBD: "firewall printer usb slxfloppy sound netshares" -declare -rg PLUGIN_FEATURES="slxfloppy" +# Define which features the VMware plugin supports +declare -rg PLUGIN_FEATURES="firewall printer usb slxfloppy sound netshares" run_plugin() { - # declaration of default functions and variables for vmware - $(safesource --exit "${QEMU_INCLUDE_DIR}/init_core.inc") - - # determine limitations wrt RAM and CPU count of VM - $(safesource "${QEMU_INCLUDE_DIR}/determine_hardware_limitations.inc") + # write finalized config to temporary folder for debugging purposes + local vm_final_run_file="/tmp/qemu-last-config.xml" - # setup networking - $(safesource "${QEMU_INCLUDE_DIR}/setup_network.inc") - - # setup rw layer for ro image - $(safesource "${QEMU_INCLUDE_DIR}/setup_rw_layer.inc") + # call the Libvirt Java tool to finalize configuration and start VM + declare -rg VIRTCMD="java -jar /opt/openslx/share/java/runvirt-plugin-qemu.jar" - # build the final start command - $(safesource "${QEMU_INCLUDE_DIR}/finalize_start_command.inc") - - # print summary - needs writelog() from vmchooser-run_virt - $(safesource "${QEMU_INCLUDE_DIR}/log_config_summary.inc") + isset VM_CLEANNAME && VIRTCMDOPTS+=( "-vmname" "${VM_CLEANNAME}" ) + isset VM_DISPLAYNAME && VIRTCMDOPTS+=( "-vmdsplname" "${VM_DISPLAYNAME}" ) + isset VM_OS_TYPE && VIRTCMDOPTS+=( "-vmos" "${VM_OS_TYPE}" ) + isset VM_RUN_FILE && VIRTCMDOPTS+=( "-vminpcfg" "${VM_RUN_FILE}" ) + isset vm_final_run_file && VIRTCMDOPTS+=( "-vmoutcfg" "${vm_final_run_file}" ) + isset IMGUUID && VIRTCMDOPTS+=( "-vmuuid" "${IMGUUID}" ) + isset CPU_CORES && VIRTCMDOPTS+=( "-vmncpus" "${CPU_CORES}" ) + isset VM_MEM && VIRTCMDOPTS+=( "-vmmem" "${VM_MEM}" ) + isset VM_MAC_ADDR && VIRTCMDOPTS+=( "-vmmac0" "${VM_MAC_ADDR}" ) + isset VM_ETH0_NETWORK && VIRTCMDOPTS+=( "-vmeth0" "${VM_ETH0_NETWORK}" ) + isset VM_DISKFILE_RO && VIRTCMDOPTS+=( "-vmhdd0" "${VM_DISKFILE_RO}" ) + isset FLOPPY_0 && VIRTCMDOPTS+=( "-vmfloppy0" "${FLOPPY_0}" ) + isset SLX_FLOPPY_IMG && VIRTCMDOPTS+=( "-vmfloppy1" "${SLX_FLOPPY_IMG}" ) + isset CDROM_0 && VIRTCMDOPTS+=( "-vmcdrom0" "${CDROM_0}" ) + isset CDROM_1 && VIRTCMDOPTS+=( "-vmcdrom1" "${CDROM_1}" ) + isset SERIAL0 && VIRTCMDOPTS+=( "-vmserial0" "${SERIAL0}" ) + isset PARALLEL0 && VIRTCMDOPTS+=( "-vmparallel0" "${PARALLEL0}" ) + isset SOUND_DEV && VIRTCMDOPTS+=( "-vmsound0" "${SOUND_DEV}" ) } -- cgit v1.2.3-55-g7522 From cdd849cc9a5c748627f7882974c9e3cb7e9457ba Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Thu, 11 Feb 2021 09:00:09 +0100 Subject: [qemu] Add command line argument parsing to 'qemu' runvirt plugin --- .../vmchooser/plugins/qemu/run-virt.include | 5 +- core/modules/qemu/runvirt-plugin-qemu/pom.xml | 17 + .../java/org/openslx/runvirt/plugin/qemu/App.java | 113 +++++- .../runvirt/plugin/qemu/cmdln/CommandLineArgs.java | 406 +++++++++++++++++++++ .../qemu/cmdln/CommandLineArgsException.java | 25 ++ .../org/openslx/runvirt/plugin/qemu/AppTest.java | 16 +- 6 files changed, 571 insertions(+), 11 deletions(-) create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgs.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgsException.java diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/run-virt.include b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/run-virt.include index ee9d8e36..5b320bcc 100644 --- a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/run-virt.include +++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/run-virt.include @@ -32,13 +32,12 @@ run_plugin() { isset VM_CLEANNAME && VIRTCMDOPTS+=( "-vmname" "${VM_CLEANNAME}" ) isset VM_DISPLAYNAME && VIRTCMDOPTS+=( "-vmdsplname" "${VM_DISPLAYNAME}" ) isset VM_OS_TYPE && VIRTCMDOPTS+=( "-vmos" "${VM_OS_TYPE}" ) - isset VM_RUN_FILE && VIRTCMDOPTS+=( "-vminpcfg" "${VM_RUN_FILE}" ) - isset vm_final_run_file && VIRTCMDOPTS+=( "-vmoutcfg" "${vm_final_run_file}" ) + isset VM_RUN_FILE && VIRTCMDOPTS+=( "-vmcfginp" "${VM_RUN_FILE}" ) + isset vm_final_run_file && VIRTCMDOPTS+=( "-vmcfgout" "${vm_final_run_file}" ) isset IMGUUID && VIRTCMDOPTS+=( "-vmuuid" "${IMGUUID}" ) isset CPU_CORES && VIRTCMDOPTS+=( "-vmncpus" "${CPU_CORES}" ) isset VM_MEM && VIRTCMDOPTS+=( "-vmmem" "${VM_MEM}" ) isset VM_MAC_ADDR && VIRTCMDOPTS+=( "-vmmac0" "${VM_MAC_ADDR}" ) - isset VM_ETH0_NETWORK && VIRTCMDOPTS+=( "-vmeth0" "${VM_ETH0_NETWORK}" ) isset VM_DISKFILE_RO && VIRTCMDOPTS+=( "-vmhdd0" "${VM_DISKFILE_RO}" ) isset FLOPPY_0 && VIRTCMDOPTS+=( "-vmfloppy0" "${FLOPPY_0}" ) isset SLX_FLOPPY_IMG && VIRTCMDOPTS+=( "-vmfloppy1" "${SLX_FLOPPY_IMG}" ) diff --git a/core/modules/qemu/runvirt-plugin-qemu/pom.xml b/core/modules/qemu/runvirt-plugin-qemu/pom.xml index d4aace6e..45b8f1d5 100644 --- a/core/modules/qemu/runvirt-plugin-qemu/pom.xml +++ b/core/modules/qemu/runvirt-plugin-qemu/pom.xml @@ -30,6 +30,23 @@ 5.7.1 test + + commons-cli + commons-cli + 1.4 + + + log4j + log4j + [1.2.10,1.2.20] + compile + + + org.slf4j + slf4j-log4j12 + 1.7.25 + compile + diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java index ce6e7e12..fb72f18a 100644 --- a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java @@ -1,12 +1,121 @@ package org.openslx.runvirt.plugin.qemu; +import org.apache.log4j.BasicConfigurator; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs.CmdLnOption; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgsException; + /** - * Hello world! + * Run-virt QEMU plugin (command line tool) to finalize a Libvirt domain XML configuration. + * + * @author Manuel Bentele + * @version 1.0 */ public class App { + /** + * Stores name of the run-virt QEMU plugin (command line tool). + */ + private static final String APP_NAME = "run-virt QEMU plugin"; + + /** + * Stores description of the run-virt QEMU plugin (command line tool). + */ + private static final String APP_DESC = "Finalize a Libvirt VM (domain XML) configuration and manage the VM."; + + /** + * Stores additional information for the run-virt QEMU plugin (command line tool). + */ + private static final String APP_INFO = "The " + APP_NAME + " is part of the bwLehrpool infrastructure."; + + /** + * Instance of a logger to log messages. + */ + private static final Logger LOGGER = LogManager.getLogger( App.class ); + + /** + * Entry point of the run-virt QEMU plugin (command line tool). + * + * @param args command line arguments passed to the run-virt QEMU plugin (command line tool). + */ public static void main( String[] args ) { - System.out.println( "Hello World!" ); + // initialize logging + BasicConfigurator.configure(); + + // parse command line arguments + CommandLineArgs cmdLn = new CommandLineArgs(); + + try { + cmdLn.parseCmdLnArgs( args ); + } catch ( CommandLineArgsException e ) { + LOGGER.error( "Parsing of command line arguments failed: " + e.getLocalizedMessage() ); + App.printUsage( cmdLn ); + System.exit( 1 ); + } + + // show help if 'help' command line option is set + if ( cmdLn.isHelpAquired() ) { + App.printUsage( cmdLn ); + System.exit( 0 ); + } + + // print command line arguments for debugging purposes + App.printCmdLnArgs( cmdLn ); + } + + /** + * Helper utility to print the run-virt QEMU plugin help text. + * + * @param cmdLn parsed command line arguments. + */ + public static void printUsage( CommandLineArgs cmdLn ) + { + final String newLine = System.lineSeparator(); + final String fullAppDesc = newLine + App.APP_DESC + newLine + newLine; + final String fullAppInfo = newLine + App.APP_INFO; + + cmdLn.printHelp( App.APP_NAME, fullAppDesc, fullAppInfo ); + } + + /** + * Helper utility to log the run-virt QEMU plugin's submitted command line arguments. + * + * @param cmdLn parsed command line arguments. + * + * @implNote This method is intended to be used for debugging purposes. + */ + public static void printCmdLnArgs( CommandLineArgs cmdLn ) + { + // determine length of longest command line option + int longOptionLengthMax = 0; + + for ( CmdLnOption option : CmdLnOption.values() ) { + // store length of current long option + final int longOptionLength = option.getLongOption().length(); + + // if length is longer than every length before, store this length as longest length + if ( longOptionLength > longOptionLengthMax ) { + longOptionLengthMax = longOptionLength; + } + } + + LOGGER.debug( "Command line arguments: --------------" ); + + for ( CmdLnOption option : CmdLnOption.values() ) { + final String paddedLongOption = String.format( "%-" + longOptionLengthMax + "s", option.getLongOption() ); + final String longOptionArgument; + + // only request and log argument if option has an command line argument + if ( option.hasArgument() ) { + longOptionArgument = cmdLn.getArgument( option ); + } else { + longOptionArgument = new String( "[option has no argument]" ); + } + + LOGGER.debug( "\t" + paddedLongOption + ": " + longOptionArgument ); + } } } diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgs.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgs.java new file mode 100644 index 00000000..13b8c0e2 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgs.java @@ -0,0 +1,406 @@ +package org.openslx.runvirt.plugin.qemu.cmdln; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.HelpFormatter; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; + +/** + * Command line argument parser for the run-virt QEMU plugin (command line tool). + * + * @author Manuel Bentele + * @version 1.0 + */ +public class CommandLineArgs +{ + /** + * Parser for parsing command line arguments. + */ + private CommandLineParser cmdLnParser = null; + + /** + * Stores specified command line options. + */ + private Options cmdLnOptions = null; + + /** + * Stores the parsed command line arguments. + */ + private CommandLine cmdLn = null; + + /** + * Creates a new command line argument parser for the run-virt QEMU plugin. + * + * @implNote Please call {@link CommandLineArgs#parseCmdLnArgs(String[])} manually after + * obtaining the command line argument parser from this method. + */ + public CommandLineArgs() + { + this.createCmdLnParser(); + this.createCmdLnOptions(); + } + + /** + * Creates a new command line argument parser for the run-virt QEMU plugin and parses the command + * line arguments. + * + * @param args command line arguments submitted to the application. + * + * @throws CommandLineArgsException parsing of command line arguments failed. + */ + public CommandLineArgs( String[] args ) throws CommandLineArgsException + { + this(); + this.parseCmdLnArgs( args ); + } + + /** + * Creates a new parser and empty command line options for parsing command line arguments. + */ + private void createCmdLnParser() + { + this.cmdLnParser = new DefaultParser(); + this.cmdLnOptions = new Options(); + } + + /** + * Creates command line options specified by {@link CmdLnOption}. + */ + private void createCmdLnOptions() + { + for ( CmdLnOption option : CmdLnOption.values() ) { + this.cmdLnOptions.addOption( option.getShortOption(), option.getLongOption(), option.hasArgument(), + option.getDescription() ); + } + } + + /** + * Prints command line help for the current application. + * + * @param appName name of the current application. + * @param header header for the command line help. + * @param footer footer for the command line help. + */ + public void printHelp( String appName, String header, String footer ) + { + HelpFormatter formatter = new HelpFormatter(); + formatter.setLeftPadding( 2 ); + formatter.printHelp( appName, header, this.cmdLnOptions, footer, true ); + } + + /** + * Parses command line arguments from a given argument {@link String}. + * + * @param args command line arguments submitted to the application. + * + * @throws CommandLineArgsException parsing of command line arguments failed. + */ + public void parseCmdLnArgs( String[] args ) throws CommandLineArgsException + { + try { + this.cmdLn = this.cmdLnParser.parse( this.cmdLnOptions, args ); + } catch ( ParseException e ) { + throw new CommandLineArgsException( e.getLocalizedMessage() ); + } + } + + /** + * Returns the parsed argument of the specified command line option. + * + * @param cmdLnOption command line option for that the parsed argument should be returned. + * @return parsed argument of the command line option. + */ + public String getArgument( CmdLnOption cmdLnOption ) + { + return this.cmdLn.getOptionValue( cmdLnOption.getShortOption() ); + } + + /** + * Returns the presence of the command line option {@link CmdLnOption#HELP}. + * + * @return presence of the command line option {@link CmdLnOption#HELP}. + */ + public boolean isHelpAquired() + { + return this.cmdLn.hasOption( CmdLnOption.HELP.getShortOption() ); + } + + /** + * Returns the argument of the command line option {@link CmdLnOption#VM_CFGINP}. + * + * @return argument of the command line option {@link CmdLnOption#VM_CFGINP}. + */ + public String getVmCfgInpFileName() + { + return this.getArgument( CmdLnOption.VM_CFGINP ); + } + + /** + * Returns the argument of the command line option {@link CmdLnOption#VM_CFGOUT}. + * + * @return argument of the command line option {@link CmdLnOption#VM_CFGOUT}. + */ + public String getVmCfgOutFileName() + { + return this.getArgument( CmdLnOption.VM_CFGOUT ); + } + + /** + * Returns the argument of the command line option {@link CmdLnOption#VM_NAME}. + * + * @return argument of the command line option {@link CmdLnOption#VM_NAME}. + */ + public String getVmName() + { + return this.getArgument( CmdLnOption.VM_NAME ); + } + + /** + * Returns the argument of the command line option {@link CmdLnOption#VM_UUID}. + * + * @return argument of the command line option {@link CmdLnOption#VM_UUID}. + */ + public String getVmUuid() + { + return this.getArgument( CmdLnOption.VM_UUID ); + } + + /** + * Returns the argument of the command line option {@link CmdLnOption#VM_DSPLNAME}. + * + * @return argument of the command line option {@link CmdLnOption#VM_DSPLNAME}. + */ + public String getVmDisplayName() + { + return this.getArgument( CmdLnOption.VM_DSPLNAME ); + } + + /** + * Returns the argument of the command line option {@link CmdLnOption#VM_OS}. + * + * @return argument of the command line option {@link CmdLnOption#VM_OS}. + */ + public String getVmOperatingSystem() + { + return this.getArgument( CmdLnOption.VM_OS ); + } + + /** + * Returns the argument of the command line option {@link CmdLnOption#VM_NCPUS}. + * + * @return argument of the command line option {@link CmdLnOption#VM_NCPUS}. + */ + public int getVmNumCpus() + { + final String numCpus = this.getArgument( CmdLnOption.VM_NCPUS ); + return Integer.parseInt( numCpus ); + } + + /** + * Returns the argument of the command line option {@link CmdLnOption#VM_MEM}. + * + * @return argument of the command line option {@link CmdLnOption#VM_MEM}. + */ + public String getVmMemory() + { + return this.getArgument( CmdLnOption.VM_MEM ); + } + + /** + * Returns the argument of the command line option {@link CmdLnOption#VM_HDD0}. + * + * @return argument of the command line option {@link CmdLnOption#VM_HDD0}. + */ + public String getVmDiskFileNameHDD0() + { + return this.getArgument( CmdLnOption.VM_HDD0 ); + } + + /** + * Returns the argument of the command line option {@link CmdLnOption#VM_FLOPPY0}. + * + * @return argument of the command line option {@link CmdLnOption#VM_FLOPPY0}. + */ + public String getVmDiskFileNameFloppy0() + { + return this.getArgument( CmdLnOption.VM_FLOPPY0 ); + } + + /** + * Returns the argument of the command line option {@link CmdLnOption#VM_FLOPPY1}. + * + * @return argument of the command line option {@link CmdLnOption#VM_FLOPPY1}. + */ + public String getVmDiskFileNameFloppy1() + { + return this.getArgument( CmdLnOption.VM_FLOPPY1 ); + } + + /** + * Returns the argument of the command line option {@link CmdLnOption#VM_CDROM0}. + * + * @return argument of the command line option {@link CmdLnOption#VM_CDROM0}. + */ + public String getVmDiskFileNameCdrom0() + { + return this.getArgument( CmdLnOption.VM_CDROM0 ); + } + + /** + * Returns the argument of the command line option {@link CmdLnOption#VM_CDROM1}. + * + * @return argument of the command line option {@link CmdLnOption#VM_CDROM1}. + */ + public String getVmDiskFileNameCdrom1() + { + return this.getArgument( CmdLnOption.VM_CDROM1 ); + } + + /** + * Returns the argument of the command line option {@link CmdLnOption#VM_PARALLEL0}. + * + * @return argument of the command line option {@link CmdLnOption#VM_SERIAL0}. + */ + public String getVmDeviceParallel0() + { + return this.getArgument( CmdLnOption.VM_PARALLEL0 ); + } + + /** + * Returns the argument of the command line option {@link CmdLnOption#VM_SERIAL0}. + * + * @return argument of the command line option {@link CmdLnOption#VM_SERIAL0}. + */ + public String getVmDeviceSerial0() + { + return this.getArgument( CmdLnOption.VM_SERIAL0 ); + } + + /** + * Returns the argument of the command line option {@link CmdLnOption#VM_MAC0}. + * + * @return argument of the command line option {@link CmdLnOption#VM_MAC0}. + */ + public String getVmMacAddress0() + { + return this.getArgument( CmdLnOption.VM_MAC0 ); + } + + /** + * Returns the argument of the command line option {@link CmdLnOption#VM_AUDIO0}. + * + * @return argument of the command line option {@link CmdLnOption#VM_AUDIO0}. + */ + public String getVmModelSoundCard0() + { + return this.getArgument( CmdLnOption.VM_AUDIO0 ); + } + + /** + * Command line options for the run-virt QEMU plugin (command line tool). + * + * @author Manuel Bentele + * @version 1.0 + */ + public enum CmdLnOption + { + // @formatter:off + HELP ( 'h', "help", false, "" ), + VM_CFGINP ( 'i', "vmcfginp", true, "File name of an existing and filtered Libvirt domain XML configuration file" ), + VM_CFGOUT ( 'o', "vmcfgout", true, "File name to output a finalized Libvirt domain XML configuration file" ), + VM_NAME ( 'n', "vmname", true, "Name for the virtual machine" ), + VM_UUID ( 'u', "vmuuid", true, "UUID for the virtual machine" ), + VM_DSPLNAME ( 'd', "vmdsplname", true, "Display name for the virtual machine" ), + VM_OS ( 's', "vmos", true, "Operating system running in the virtual machine" ), + VM_NCPUS ( 'c', "vmncpus", true, "Number of virtual CPUs for the virtual machine" ), + VM_MEM ( 'm', "vmmem", true, "Amount of memory for the virtual machine" ), + VM_HDD0 ( 'r', "vmhdd0", true, "Disk image for the first HDD device" ), + VM_FLOPPY0 ( 'f', "vmfloppy0", true, "Disk image for the first floppy drive" ), + VM_FLOPPY1 ( 'g', "vmfloppy1", true, "Disk image for the second floppy drive" ), + VM_CDROM0 ( 'k', "vmcdrom0", true, "Disk image for the first CDROM drive" ), + VM_CDROM1 ( 'l', "vmcdrom1", true, "Disk image for the second CDROM drive" ), + VM_PARALLEL0( 'p', "vmparallel0", true, "Device for the first parallel port interface" ), + VM_SERIAL0 ( 'q', "vmserial0", true, "Device for the first serial port interface" ), + VM_MAC0 ( 'a', "vmmac0", true, "MAC address for the first network interface" ), + VM_AUDIO0 ( 'x', "vmaudio0", true, "Hardware model for the first sound card" ); + // @formatter:on + + /** + * Stores the {@link Character} of the short command line option. + */ + private final char shortOption; + + /** + * Stores the {@link String} of the long command line option. + */ + private final String longOption; + + /** + * Stores the presence of an argument for the command line option. + */ + private final boolean hasArgument; + + /** + * Stores the textual description of the command line option. + */ + private final String description; + + /** + * Creates a new command line option for the run-virt QEMU plugin (command line tool). + * + * @param shortOption {@link Character} for the short command line option. + * @param longOption {@link String} for the long command line option. + * @param hasArgument presence of an argument for the command line option. + * @param description textual description of the command line option. + */ + CmdLnOption( char shortOption, String longOption, boolean hasArgument, String description ) + { + this.shortOption = shortOption; + this.longOption = longOption; + this.hasArgument = hasArgument; + this.description = description; + } + + /** + * Returns the {@link Character} of the short command line option. + * + * @return {@link Character} of the short command line option. + */ + public String getShortOption() + { + return Character.toString( this.shortOption ); + } + + /** + * Returns the {@link String} of the long command line option. + * + * @return {@link String} of the long command line option. + */ + public String getLongOption() + { + return this.longOption; + } + + /** + * Returns the presence of an argument for the command line option. + * + * @return presence of an argument for the command line option. + */ + public boolean hasArgument() + { + return this.hasArgument; + } + + /** + * Returns the textual description of the command line option. + * + * @return textual description of the command line option. + */ + public String getDescription() + { + return this.description; + } + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgsException.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgsException.java new file mode 100644 index 00000000..a327b813 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgsException.java @@ -0,0 +1,25 @@ +package org.openslx.runvirt.plugin.qemu.cmdln; + +/** + * An exception during the parsing of command line arguments. + * + * @author Manuel Bentele + * @version 1.0 + */ +public class CommandLineArgsException extends Exception +{ + /** + * Version number for serialization. + */ + private static final long serialVersionUID = 8371924151602194406L; + + /** + * Creates an command line argument parsing exception including an error message. + * + * @param errorMsg message to describe a specific parsing error. + */ + public CommandLineArgsException( String errorMsg ) + { + super( errorMsg ); + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/AppTest.java b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/AppTest.java index 90b658cd..110fb639 100644 --- a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/AppTest.java +++ b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/AppTest.java @@ -2,16 +2,20 @@ package org.openslx.runvirt.plugin.qemu; import static org.junit.jupiter.api.Assertions.assertTrue; +import org.apache.log4j.Level; +import org.apache.log4j.LogManager; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -/** - * Unit test for simple App. - */ public class AppTest { - /** - * Rigorous Test :-) - */ + @BeforeAll + public static void setUp() + { + // disable logging with log4j + LogManager.getRootLogger().setLevel( Level.OFF ); + } + @Test public void shouldAnswerWithTrue() { -- cgit v1.2.3-55-g7522 From 0d48a4b54de060725e3337af5664e94ba4f1a3ae Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Fri, 12 Feb 2021 12:07:24 +0100 Subject: [qemu] Add unit tests for run-virt plugin's help option --- core/modules/qemu/runvirt-plugin-qemu/pom.xml | 6 + .../java/org/openslx/runvirt/plugin/qemu/App.java | 9 +- .../org/openslx/runvirt/plugin/qemu/AppTest.java | 186 ++++++++++++++++++++- 3 files changed, 194 insertions(+), 7 deletions(-) diff --git a/core/modules/qemu/runvirt-plugin-qemu/pom.xml b/core/modules/qemu/runvirt-plugin-qemu/pom.xml index 45b8f1d5..f744c4f3 100644 --- a/core/modules/qemu/runvirt-plugin-qemu/pom.xml +++ b/core/modules/qemu/runvirt-plugin-qemu/pom.xml @@ -47,6 +47,12 @@ 1.7.25 compile + + com.ginsberg + junit5-system-exit + 1.0.0 + test + diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java index fb72f18a..8a70be33 100644 --- a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java @@ -18,17 +18,17 @@ public class App /** * Stores name of the run-virt QEMU plugin (command line tool). */ - private static final String APP_NAME = "run-virt QEMU plugin"; + public static final String APP_NAME = "run-virt QEMU plugin"; /** * Stores description of the run-virt QEMU plugin (command line tool). */ - private static final String APP_DESC = "Finalize a Libvirt VM (domain XML) configuration and manage the VM."; + public static final String APP_DESC = "Finalize a Libvirt VM (domain XML) configuration and manage the VM."; /** * Stores additional information for the run-virt QEMU plugin (command line tool). */ - private static final String APP_INFO = "The " + APP_NAME + " is part of the bwLehrpool infrastructure."; + public static final String APP_INFO = "The " + APP_NAME + " is part of the bwLehrpool infrastructure."; /** * Instance of a logger to log messages. @@ -64,6 +64,9 @@ public class App // print command line arguments for debugging purposes App.printCmdLnArgs( cmdLn ); + + // return with successful exit code + System.exit( 0 ); } /** diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/AppTest.java b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/AppTest.java index 110fb639..126fd26d 100644 --- a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/AppTest.java +++ b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/AppTest.java @@ -1,24 +1,202 @@ package org.openslx.runvirt.plugin.qemu; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + import org.apache.log4j.Level; import org.apache.log4j.LogManager; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs.CmdLnOption; + +import com.ginsberg.junit.exit.ExpectSystemExit; +import com.ginsberg.junit.exit.ExpectSystemExitWithStatus; public class AppTest { @BeforeAll - public static void setUp() + private static void setUp() { // disable logging with log4j LogManager.getRootLogger().setLevel( Level.OFF ); } - @Test - public void shouldAnswerWithTrue() + @Nested + public class CmdLnTest { - assertTrue( true ); + private final ByteArrayOutputStream out = new ByteArrayOutputStream(); + private final ByteArrayOutputStream err = new ByteArrayOutputStream(); + + private void setUp() + { + // redirect output and error stream content + System.setOut( new PrintStream( this.out ) ); + System.setErr( new PrintStream( this.err ) ); + } + + @Test + @DisplayName( "Test ouput of correct 'help' command line option (short version)" ) + @ExpectSystemExit + public void testCmdLnOptionHelpShortCorrect() + { + String[] argsShortHelpOptionCorrect = { "-" + CmdLnOption.HELP.getShortOption() }; + + this.setUp(); + + // test correct usage of the short help option + try { + App.main( argsShortHelpOptionCorrect ); + } catch ( Exception e ) { + // do nothing and check output afterwards + } + + final String shortHelpOptionCorrectOutput = new String( this.out.toString() ); + final String shortHelpOptionCorrectErrOutput = new String( this.err.toString() ); + assertTrue( shortHelpOptionCorrectOutput.contains( "usage" ) ); + assertTrue( shortHelpOptionCorrectOutput.contains( App.APP_NAME ) ); + assertTrue( shortHelpOptionCorrectOutput.contains( App.APP_INFO ) ); + assertTrue( shortHelpOptionCorrectOutput.contains( App.APP_DESC ) ); + + // test that no error was logged and output is available + assertEquals( 1641, shortHelpOptionCorrectOutput.length() ); + assertEquals( 0, shortHelpOptionCorrectErrOutput.length() ); + } + + @Test + @DisplayName( "Test ouput of correct 'help' command line option (long version)" ) + @ExpectSystemExit + public void testCmdLnOptionHelpLongCorrect() + { + String[] argsLongHelpOptionCorrect = { "--" + CmdLnOption.HELP.getLongOption() }; + + this.setUp(); + + // test correct usage of the long help option + try { + App.main( argsLongHelpOptionCorrect ); + } catch ( Exception e ) { + // do nothing and check output afterwards + } + + final String longHelpOptionCorrectOutput = this.out.toString(); + final String longHelpOptionCorrectErrOutput = this.err.toString(); + assertTrue( longHelpOptionCorrectOutput.contains( "usage" ) ); + assertTrue( longHelpOptionCorrectOutput.contains( App.APP_NAME ) ); + assertTrue( longHelpOptionCorrectOutput.contains( App.APP_INFO ) ); + assertTrue( longHelpOptionCorrectOutput.contains( App.APP_DESC ) ); + + // test that no error was logged and output is available + assertEquals( 1641, longHelpOptionCorrectOutput.length() ); + assertEquals( 0, longHelpOptionCorrectErrOutput.length() ); + } + + @Test + @DisplayName( "Test ouput of incorrect 'help' command line option (short version)" ) + @ExpectSystemExit + public void testCmdLnOptionHelpShortIncorrect() + { + String[] argsShortHelpOptionIncorrect = { "---" + CmdLnOption.HELP.getShortOption() }; + + this.setUp(); + + // test incorrect usage of the short help option + try { + App.main( argsShortHelpOptionIncorrect ); + } catch ( Exception e ) { + // do nothing and check output afterwards + } + + final String shortHelpOptionIncorrectOutput = this.out.toString(); + final String shortHelpOptionIncorrectErrOutput = this.err.toString(); + assertTrue( shortHelpOptionIncorrectOutput.contains( "usage" ) ); + assertTrue( shortHelpOptionIncorrectOutput.contains( App.APP_NAME ) ); + assertTrue( shortHelpOptionIncorrectOutput.contains( App.APP_INFO ) ); + assertTrue( shortHelpOptionIncorrectOutput.contains( App.APP_DESC ) ); + + // test that error was logged and output is available + assertEquals( 1641, shortHelpOptionIncorrectOutput.length() ); + assertEquals( 0, shortHelpOptionIncorrectErrOutput.length() ); + } + + @Test + @DisplayName( "Test ouput of incorrect 'help' command line option (long version)" ) + @ExpectSystemExit + public void testCmdLnOptionHelpLongIncorrect() + { + String[] argsLongHelpOptionIncorrect = { "---" + CmdLnOption.HELP.getLongOption() }; + + this.setUp(); + + // test incorrect usage of the long help option + try { + App.main( argsLongHelpOptionIncorrect ); + } catch ( Exception e ) { + // do nothing and check output afterwards + } + + final String longHelpOptionIncorrectOutput = this.out.toString(); + final String longHelpOptionIncorrectErrOutput = this.err.toString(); + assertTrue( longHelpOptionIncorrectOutput.contains( "usage" ) ); + assertTrue( longHelpOptionIncorrectOutput.contains( App.APP_NAME ) ); + assertTrue( longHelpOptionIncorrectOutput.contains( App.APP_INFO ) ); + assertTrue( longHelpOptionIncorrectOutput.contains( App.APP_DESC ) ); + + // test that error was logged and output is available + assertEquals( 1641, longHelpOptionIncorrectOutput.length() ); + assertEquals( 0, longHelpOptionIncorrectErrOutput.length() ); + } + + @Test + @DisplayName( "Test exit status of application invoked with correct 'help' command line option (short version)" ) + @ExpectSystemExitWithStatus( 0 ) + public void testCmdLnOptionHelpShortCorrectExit() + { + String[] argsShortHelpOptionCorrect = { "-" + CmdLnOption.HELP.getShortOption() }; + + this.setUp(); + + App.main( argsShortHelpOptionCorrect ); + } + + @Test + @DisplayName( "Test exit status of application invoked with correct 'help' command line option (long version)" ) + @ExpectSystemExitWithStatus( 0 ) + public void testCmdLnOptionHelpLongCorrectExit() + { + String[] argsLongHelpOptionCorrect = { "--" + CmdLnOption.HELP.getLongOption() }; + + this.setUp(); + + App.main( argsLongHelpOptionCorrect ); + } + + @Test + @DisplayName( "Test exit status of application invoked with incorrect 'help' command line option (short version)" ) + @ExpectSystemExitWithStatus( 1 ) + public void testCmdLnOptionHelpShortIncorrectExit() + { + String[] argsShortHelpOptionCorrect = { "---" + CmdLnOption.HELP.getShortOption() }; + + this.setUp(); + + App.main( argsShortHelpOptionCorrect ); + } + + @Test + @DisplayName( "Test exit status of application invoked with incorrect 'help' command line option (long version)" ) + @ExpectSystemExitWithStatus( 1 ) + public void testCmdLnOptionHelpLongIncorrectExit() + { + String[] argsLongHelpOptionCorrect = { "---" + CmdLnOption.HELP.getLongOption() }; + + this.setUp(); + + App.main( argsLongHelpOptionCorrect ); + } } } -- cgit v1.2.3-55-g7522 From 4f9e5f2dafeb8a379b38873d18203e3d1b77bc74 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Tue, 16 Feb 2021 09:15:46 +0100 Subject: [qemu] Add unit tests for run-virt plugin's command line argument parser --- .../plugin/qemu/cmdln/CommandLineArgsTest.java | 548 +++++++++++++++++++++ 1 file changed, 548 insertions(+) create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgsTest.java diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgsTest.java b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgsTest.java new file mode 100644 index 00000000..1399f9a4 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgsTest.java @@ -0,0 +1,548 @@ +package org.openslx.runvirt.plugin.qemu.cmdln; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.File; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs.CmdLnOption; + +public class CommandLineArgsTest +{ + // @formatter:off + private static final String CMDLN_PREFIX_OPTION_SHORT = "-"; + private static final String CMDLN_PREFIX_OPTION_LONG = "--"; + + private static final String CMDLN_TEST_NAME = "test"; + private static final String CMDLN_TEST_FILENAME = System.getProperty( "user.dir" ) + File.separator + CMDLN_TEST_NAME; + private static final String CMDLN_TEST_UUID = "c9570672-cbae-4cbd-801a-881b281b8d79"; + private static final String CMDLN_TEST_OS = "Windows 10 (x64)"; + private static final int CMDLN_TEST_NCPUS = 4; + private static final String CMDLN_TEST_MEM = "1024"; + private static final String CMDLN_TEST_PARPORT = "/dev/parport0"; + private static final String CMDLN_TEST_SERPORT = "/dev/ttyS0"; + private static final String CMDLN_TEST_MAC = "02:42:8e:77:1b:e6"; + private static final String CMDLN_TEST_AUDIO_MODEL = "sb16"; + // @formatter:on + + @Test + @DisplayName( "Test the parsing of wrong command line options" ) + public void testCmdlnOptionsIncorrect() + { + final String[] args = { + CMDLN_PREFIX_OPTION_SHORT + "hello", + "world argument", + CMDLN_PREFIX_OPTION_LONG + "info", + "description" + }; + + CommandLineArgs cmdLn = new CommandLineArgs(); + + assertThrows( CommandLineArgsException.class, () -> cmdLn.parseCmdLnArgs( args ) ); + } + + @Test + @DisplayName( "Test the parsing of the help command line option (short version)" ) + public void testCmdlnOptionHelpShort() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.HELP.getShortOption() + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertTrue( cmdLn.isHelpAquired() ); + } + + @Test + @DisplayName( "Test the parsing of the help command line option (long version)" ) + public void testCmdlnOptionHelpLong() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_LONG + CmdLnOption.HELP.getLongOption() + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertTrue( cmdLn.isHelpAquired() ); + } + + @Test + @DisplayName( "Test the parsing of the VM configuration input command line option (short version)" ) + public void testCmdlnOptionVmCfgInpShort() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.VM_CFGINP.getShortOption(), + CMDLN_TEST_FILENAME + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_FILENAME, cmdLn.getVmCfgInpFileName() ); + } + + @Test + @DisplayName( "Test the parsing of the VM configuration input command line option (long version)" ) + public void testCmdlnOptionVmCfgInpLong() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_CFGINP.getLongOption(), + CMDLN_TEST_FILENAME + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_FILENAME, cmdLn.getVmCfgInpFileName() ); + } + + @Test + @DisplayName( "Test the parsing of the VM configuration output command line option (short version)" ) + public void testCmdlnOptionVmCfgOutShort() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.VM_CFGOUT.getShortOption(), + CMDLN_TEST_FILENAME + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_FILENAME, cmdLn.getVmCfgOutFileName() ); + } + + @Test + @DisplayName( "Test the parsing of the VM configuration output command line option (long version)" ) + public void testCmdlnOptionVmCfgOutLong() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_CFGOUT.getLongOption(), + CMDLN_TEST_FILENAME + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_FILENAME, cmdLn.getVmCfgOutFileName() ); + } + + @Test + @DisplayName( "Test the parsing of the VM name command line option (short version)" ) + public void testCmdlnOptionVmNameShort() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.VM_NAME.getShortOption(), + CMDLN_TEST_NAME + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_NAME, cmdLn.getVmName() ); + } + + @Test + @DisplayName( "Test the parsing of the VM name command line option (long version)" ) + public void testCmdlnOptionVmNameLong() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_NAME.getLongOption(), + CMDLN_TEST_NAME + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_NAME, cmdLn.getVmName() ); + } + + @Test + @DisplayName( "Test the parsing of the VM UUID command line option (short version)" ) + public void testCmdlnOptionVmUuidShort() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.VM_UUID.getShortOption(), + CMDLN_TEST_UUID + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_UUID, cmdLn.getVmUuid() ); + } + + @Test + @DisplayName( "Test the parsing of the VM UUID command line option (long version)" ) + public void testCmdlnOptionVmUuidLong() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_UUID.getLongOption(), + CMDLN_TEST_UUID + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_UUID, cmdLn.getVmUuid() ); + } + + @Test + @DisplayName( "Test the parsing of the VM display name command line option (short version)" ) + public void testCmdlnOptionVmDsplNameShort() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.VM_DSPLNAME.getShortOption(), + CMDLN_TEST_NAME + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_NAME, cmdLn.getVmDisplayName() ); + } + + @Test + @DisplayName( "Test the parsing of the VM display name command line option (long version)" ) + public void testCmdlnOptionVmDsplNameLong() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_DSPLNAME.getLongOption(), + CMDLN_TEST_NAME + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_NAME, cmdLn.getVmDisplayName() ); + } + + @Test + @DisplayName( "Test the parsing of the VM OS command line option (short version)" ) + public void testCmdlnOptionVmOsShort() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.VM_OS.getShortOption(), + CMDLN_TEST_OS + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_OS, cmdLn.getVmOperatingSystem() ); + } + + @Test + @DisplayName( "Test the parsing of the VM OS command line option (long version)" ) + public void testCmdlnOptionVmOsLong() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_OS.getLongOption(), + CMDLN_TEST_OS + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_OS, cmdLn.getVmOperatingSystem() ); + } + + @Test + @DisplayName( "Test the parsing of the VM CPU number command line option (short version)" ) + public void testCmdlnOptionVmNCpusShort() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.VM_NCPUS.getShortOption(), + Integer.toString( CMDLN_TEST_NCPUS ) + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_NCPUS, cmdLn.getVmNumCpus() ); + } + + @Test + @DisplayName( "Test the parsing of the VM CPU number command line option (long version)" ) + public void testCmdlnOptionVmNCpusLong() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_NCPUS.getLongOption(), + Integer.toString( CMDLN_TEST_NCPUS ) + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_NCPUS, cmdLn.getVmNumCpus() ); + } + + @Test + @DisplayName( "Test the parsing of the VM memory command line option (short version)" ) + public void testCmdlnOptionVmMemShort() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.VM_MEM.getShortOption(), + CMDLN_TEST_MEM + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_MEM, cmdLn.getVmMemory() ); + } + + @Test + @DisplayName( "Test the parsing of the VM memory command line option (long version)" ) + public void testCmdlnOptionVmMemLong() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_MEM.getLongOption(), + CMDLN_TEST_MEM + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_MEM, cmdLn.getVmMemory() ); + } + + @Test + @DisplayName( "Test the parsing of the VM first HDD disk image command line option (short version)" ) + public void testCmdlnOptionVmHdd0Short() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.VM_HDD0.getShortOption(), + CMDLN_TEST_FILENAME + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_FILENAME, cmdLn.getVmDiskFileNameHDD0() ); + } + + @Test + @DisplayName( "Test the parsing of the VM first HDD disk image command line option (long version)" ) + public void testCmdlnOptionVmHdd0Long() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_HDD0.getLongOption(), + CMDLN_TEST_FILENAME + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_FILENAME, cmdLn.getVmDiskFileNameHDD0() ); + } + + @Test + @DisplayName( "Test the parsing of the VM first floppy disk image command line option (short version)" ) + public void testCmdlnOptionVmFloppy0Short() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.VM_FLOPPY0.getShortOption(), + CMDLN_TEST_FILENAME + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_FILENAME, cmdLn.getVmDiskFileNameFloppy0() ); + } + + @Test + @DisplayName( "Test the parsing of the VM first floppy disk image command line option (long version)" ) + public void testCmdlnOptionVmFloppy0Long() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_FLOPPY0.getLongOption(), + CMDLN_TEST_FILENAME + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_FILENAME, cmdLn.getVmDiskFileNameFloppy0() ); + } + + @Test + @DisplayName( "Test the parsing of the VM second floppy disk image command line option (short version)" ) + public void testCmdlnOptionVmFloppy1Short() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.VM_FLOPPY1.getShortOption(), + CMDLN_TEST_FILENAME + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_FILENAME, cmdLn.getVmDiskFileNameFloppy1() ); + } + + @Test + @DisplayName( "Test the parsing of the VM second floppy disk image command line option (long version)" ) + public void testCmdlnOptionVmFloppy1Long() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_FLOPPY1.getLongOption(), + CMDLN_TEST_FILENAME + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_FILENAME, cmdLn.getVmDiskFileNameFloppy1() ); + } + + @Test + @DisplayName( "Test the parsing of the VM first CDROM disk image command line option (short version)" ) + public void testCmdlnOptionVmCdrom0Short() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.VM_CDROM0.getShortOption(), + CMDLN_TEST_FILENAME + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_FILENAME, cmdLn.getVmDiskFileNameCdrom0() ); + } + + @Test + @DisplayName( "Test the parsing of the VM first CDROM disk image command line option (long version)" ) + public void testCmdlnOptionVmCdrom0Long() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_CDROM0.getLongOption(), + CMDLN_TEST_FILENAME + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_FILENAME, cmdLn.getVmDiskFileNameCdrom0() ); + } + + @Test + @DisplayName( "Test the parsing of the VM second CDROM disk image command line option (short version)" ) + public void testCmdlnOptionVmCdrom1Short() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.VM_CDROM1.getShortOption(), + CMDLN_TEST_FILENAME + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_FILENAME, cmdLn.getVmDiskFileNameCdrom1() ); + } + + @Test + @DisplayName( "Test the parsing of the VM second CDROM disk image command line option (long version)" ) + public void testCmdlnOptionVmCdrom1Long() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_CDROM1.getLongOption(), + CMDLN_TEST_FILENAME + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_FILENAME, cmdLn.getVmDiskFileNameCdrom1() ); + } + + @Test + @DisplayName( "Test the parsing of the VM first parallel interface command line option (short version)" ) + public void testCmdlnOptionVmParallel0Short() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.VM_PARALLEL0.getShortOption(), + CMDLN_TEST_PARPORT + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_PARPORT, cmdLn.getVmDeviceParallel0() ); + } + + @Test + @DisplayName( "Test the parsing of the VM first parallel interface command line option (long version)" ) + public void testCmdlnOptionVmParallel0Long() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_PARALLEL0.getLongOption(), + CMDLN_TEST_PARPORT + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_PARPORT, cmdLn.getVmDeviceParallel0() ); + } + + @Test + @DisplayName( "Test the parsing of the VM first serial interface command line option (short version)" ) + public void testCmdlnOptionVmSerial0Short() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.VM_SERIAL0.getShortOption(), + CMDLN_TEST_SERPORT + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_SERPORT, cmdLn.getVmDeviceSerial0() ); + } + + @Test + @DisplayName( "Test the parsing of the VM first serial interface command line option (long version)" ) + public void testCmdlnOptionVmSerial0Long() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_SERIAL0.getLongOption(), + CMDLN_TEST_SERPORT + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_SERPORT, cmdLn.getVmDeviceSerial0() ); + } + + @Test + @DisplayName( "Test the parsing of the VM first network interface MAC command line option (short version)" ) + public void testCmdlnOptionVmMac0Short() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.VM_MAC0.getShortOption(), + CMDLN_TEST_MAC + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_MAC, cmdLn.getVmMacAddress0() ); + } + + @Test + @DisplayName( "Test the parsing of the VM first network interface MAC command line option (long version)" ) + public void testCmdlnOptionVmMac0Long() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_MAC0.getLongOption(), + CMDLN_TEST_MAC + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_MAC, cmdLn.getVmMacAddress0() ); + } + + @Test + @DisplayName( "Test the parsing of the VM first sound card type command line option (short version)" ) + public void testCmdlnOptionVmAudio0Short() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.VM_AUDIO0.getShortOption(), + CMDLN_TEST_AUDIO_MODEL + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_AUDIO_MODEL, cmdLn.getVmModelSoundCard0() ); + } + + @Test + @DisplayName( "Test the parsing of the VM first sound card type command line option (long version)" ) + public void testCmdlnOptionVmAudio0Long() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_AUDIO0.getLongOption(), + CMDLN_TEST_AUDIO_MODEL + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_AUDIO_MODEL, cmdLn.getVmModelSoundCard0() ); + } +} -- cgit v1.2.3-55-g7522 From c4e0904d627886bd3b21b8f2131064d41deedfe0 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Tue, 16 Feb 2021 10:19:57 +0100 Subject: [qemu]: Add Libvirt Java bindings as dependencies --- core/modules/qemu/runvirt-plugin-qemu/pom.xml | 111 +++++++++++++++----------- 1 file changed, 64 insertions(+), 47 deletions(-) diff --git a/core/modules/qemu/runvirt-plugin-qemu/pom.xml b/core/modules/qemu/runvirt-plugin-qemu/pom.xml index f744c4f3..ccf03f52 100644 --- a/core/modules/qemu/runvirt-plugin-qemu/pom.xml +++ b/core/modules/qemu/runvirt-plugin-qemu/pom.xml @@ -53,55 +53,72 @@ 1.0.0 test + + org.libvirt + libvirt + 0.5.2 + + + net.java.dev.jna + jna + 4.2.2 + - - - - - maven-clean-plugin - 3.1.0 - - - - maven-resources-plugin - 3.0.2 - - - maven-compiler-plugin - 3.8.0 - - - maven-surefire-plugin - 2.22.1 - - - maven-failsafe-plugin - 2.22.1 - - - maven-jar-plugin - 3.0.2 - - - maven-install-plugin - 2.5.2 - - - maven-deploy-plugin - 2.8.2 - - - - maven-site-plugin - 3.7.1 - - - maven-project-info-reports-plugin - 3.0.0 - - - + + + maven-clean-plugin + 3.1.0 + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-failsafe-plugin + 2.22.1 + + + maven-assembly-plugin + + + package + + single + + + + + + jar-with-dependencies + + + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + -- cgit v1.2.3-55-g7522 From 91f78d427ec54bdae8dba78c45583d1806ced2b6 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Mon, 15 Mar 2021 13:12:07 +0100 Subject: [qemu]: Add Libvirt XML documents as dependencies --- core/modules/qemu/runvirt-plugin-qemu/pom.xml | 34 +++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/core/modules/qemu/runvirt-plugin-qemu/pom.xml b/core/modules/qemu/runvirt-plugin-qemu/pom.xml index ccf03f52..27f33991 100644 --- a/core/modules/qemu/runvirt-plugin-qemu/pom.xml +++ b/core/modules/qemu/runvirt-plugin-qemu/pom.xml @@ -16,6 +16,31 @@ 1.8 1.8 + + + + mltk-repo-snapshot + http://mltk-services.ruf.uni-freiburg.de:8081/nexus/content/repositories/snapshots/ + + false + + + true + always + + + + mltk-repo-release + http://mltk-services.ruf.uni-freiburg.de:8081/nexus/content/repositories/releases/ + + true + always + + + false + + + @@ -34,6 +59,7 @@ commons-cli commons-cli 1.4 + compile log4j @@ -57,11 +83,19 @@ org.libvirt libvirt 0.5.2 + compile net.java.dev.jna jna 4.2.2 + compile + + + org.openslx.bwlp + master-sync-shared + 1.1-SNAPSHOT + compile -- cgit v1.2.3-55-g7522 From 24d4ebdce0a3c022c7ae7c90139235bb4c8dad67 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Thu, 25 Mar 2021 11:25:18 +0100 Subject: [qemu] Add filtering/transformation of config files and VM management --- .../vmchooser/plugins/qemu/run-virt.include | 7 +- core/modules/qemu/runvirt-plugin-qemu/.gitignore | 17 +- core/modules/qemu/runvirt-plugin-qemu/pom.xml | 8 + .../org/openslx/runvirt/configuration/Filter.java | 28 + .../runvirt/configuration/FilterException.java | 14 + .../runvirt/configuration/FilterFunction.java | 12 + .../runvirt/configuration/FilterGeneric.java | 9 + .../runvirt/configuration/FilterManager.java | 80 ++ .../runvirt/configuration/FilterSpecific.java | 18 + .../java/org/openslx/runvirt/plugin/qemu/App.java | 121 +++ .../runvirt/plugin/qemu/cmdln/CommandLineArgs.java | 43 +- .../qemu/configuration/FilterGenericCpu.java | 26 + .../FilterGenericDiskCdromDevices.java | 54 ++ .../FilterGenericDiskFloppyDevices.java | 50 ++ .../FilterGenericDiskStorageDevices.java | 49 + .../FilterGenericFileSystemDevices.java | 64 ++ .../FilterGenericInterfaceDevices.java | 48 + .../qemu/configuration/FilterGenericMemory.java | 28 + .../qemu/configuration/FilterGenericName.java | 23 + .../FilterGenericParallelDevices.java | 58 ++ .../qemu/configuration/FilterGenericUuid.java | 22 + .../FilterSpecificQemuArchitecture.java | 199 +++++ .../FilterSpecificQemuNvidiaGpuPassthrough.java | 26 + .../FilterSpecificQemuSerialDevices.java | 69 ++ .../qemu/virtualization/LibvirtHypervisorQemu.java | 39 + .../runvirt/virtualization/LibvirtHypervisor.java | 99 +++ .../virtualization/LibvirtHypervisorException.java | 14 + .../virtualization/LibvirtVirtualMachine.java | 81 ++ .../LibvirtVirtualMachineException.java | 14 + .../org/openslx/runvirt/plugin/qemu/AppTest.java | 8 +- .../plugin/qemu/cmdln/CommandLineArgsTest.java | 109 ++- .../qemu/configuration/FilterGenericCpuTest.java | 34 + .../FilterGenericDiskStorageDevicesTest.java | 61 ++ .../configuration/FilterGenericMemoryTest.java | 35 + .../qemu/configuration/FilterGenericNameTest.java | 30 + .../qemu/configuration/FilterGenericUuidTest.java | 28 + .../qemu/configuration/FilterTestResources.java | 17 + .../plugin/qemu/configuration/FilterTestUtils.java | 112 +++ .../libvirt/xml/qemu-kvm_capabilities_default.xml | 986 +++++++++++++++++++++ .../xml/qemu-kvm_default-ubuntu-20-04-vm.xml | 164 ++++ 40 files changed, 2877 insertions(+), 27 deletions(-) create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/configuration/Filter.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/configuration/FilterException.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/configuration/FilterFunction.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/configuration/FilterGeneric.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/configuration/FilterManager.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/configuration/FilterSpecific.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericCpu.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericDiskCdromDevices.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericDiskFloppyDevices.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericDiskStorageDevices.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericFileSystemDevices.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericInterfaceDevices.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericMemory.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericName.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericParallelDevices.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericUuid.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterSpecificQemuArchitecture.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterSpecificQemuNvidiaGpuPassthrough.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterSpecificQemuSerialDevices.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/virtualization/LibvirtHypervisorQemu.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtHypervisor.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtHypervisorException.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtVirtualMachine.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtVirtualMachineException.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericCpuTest.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericDiskStorageDevicesTest.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericMemoryTest.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericNameTest.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericUuidTest.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterTestResources.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterTestUtils.java create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/test/resources/libvirt/xml/qemu-kvm_capabilities_default.xml create mode 100644 core/modules/qemu/runvirt-plugin-qemu/src/test/resources/libvirt/xml/qemu-kvm_default-ubuntu-20-04-vm.xml diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/run-virt.include b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/run-virt.include index 5b320bcc..90a00c6e 100644 --- a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/run-virt.include +++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemu/run-virt.include @@ -19,7 +19,7 @@ declare -rg QEMU_PLUGIN_DIR="$(dirname "${BASH_SOURCE[0]}")" declare -rg QEMU_INCLUDE_DIR="${QEMU_PLUGIN_DIR}/includes" -# Define which features the VMware plugin supports +# Define which features the QEMU plugin supports declare -rg PLUGIN_FEATURES="firewall printer usb slxfloppy sound netshares" run_plugin() { @@ -45,5 +45,8 @@ run_plugin() { isset CDROM_1 && VIRTCMDOPTS+=( "-vmcdrom1" "${CDROM_1}" ) isset SERIAL0 && VIRTCMDOPTS+=( "-vmserial0" "${SERIAL0}" ) isset PARALLEL0 && VIRTCMDOPTS+=( "-vmparallel0" "${PARALLEL0}" ) - isset SOUND_DEV && VIRTCMDOPTS+=( "-vmsound0" "${SOUND_DEV}" ) + isset HOME_SHARE_PATH && VIRTCMDOPTS+=( "-vmfssrc0" "${HOME_SHARE_PATH}" ) + isset HOME_SHARE_NAME && VIRTCMDOPTS+=( "-vmfstgt0" "${HOME_SHARE_NAME}" ) + isset COMMON_SHARE_PATH && VIRTCMDOPTS+=( "-vmfssrc1" "${COMMON_SHARE_PATH}" ) + isset COMMON_SHARE_NAME && VIRTCMDOPTS+=( "-vmfstgt1" "${COMMON_SHARE_NAME}" ) } diff --git a/core/modules/qemu/runvirt-plugin-qemu/.gitignore b/core/modules/qemu/runvirt-plugin-qemu/.gitignore index 49b2bfee..6090294a 100644 --- a/core/modules/qemu/runvirt-plugin-qemu/.gitignore +++ b/core/modules/qemu/runvirt-plugin-qemu/.gitignore @@ -1,3 +1,14 @@ -/target/ -.classpath -.settings/ +/testing +/.settings +/.project +/.classpath +/target +/gen-java +*~ +!src/ +!test/ +*.swp + +# Ignore IntelliJ Project Files +/.idea +*.iml diff --git a/core/modules/qemu/runvirt-plugin-qemu/pom.xml b/core/modules/qemu/runvirt-plugin-qemu/pom.xml index 27f33991..197f3df3 100644 --- a/core/modules/qemu/runvirt-plugin-qemu/pom.xml +++ b/core/modules/qemu/runvirt-plugin-qemu/pom.xml @@ -154,5 +154,13 @@ 3.0.0 + + + ${basedir}/src/test/resources + + libvirt/xml/* + + + diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/configuration/Filter.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/configuration/Filter.java new file mode 100644 index 00000000..3fb594a2 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/configuration/Filter.java @@ -0,0 +1,28 @@ +package org.openslx.runvirt.configuration; + +public abstract class Filter implements FilterFunction +{ + private final String name; + private boolean enabled; + + public Filter( String name ) + { + this.name = name; + this.setEnabled( true ); + } + + public String getName() + { + return this.name; + } + + public boolean isEnabled() + { + return this.enabled; + } + + public void setEnabled( boolean enabled ) + { + this.enabled = enabled; + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/configuration/FilterException.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/configuration/FilterException.java new file mode 100644 index 00000000..8969d1a2 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/configuration/FilterException.java @@ -0,0 +1,14 @@ +package org.openslx.runvirt.configuration; + +public class FilterException extends Exception +{ + /** + * Version for serialization. + */ + private static final long serialVersionUID = 7293420658901349154L; + + public FilterException( String errorMsg ) + { + super( errorMsg ); + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/configuration/FilterFunction.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/configuration/FilterFunction.java new file mode 100644 index 00000000..1d716201 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/configuration/FilterFunction.java @@ -0,0 +1,12 @@ +package org.openslx.runvirt.configuration; + +@FunctionalInterface +public interface FilterFunction +{ + public void filter( T config, R args ) throws FilterException; + + public default void apply( T config, R args ) throws FilterException + { + this.filter( config, args ); + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/configuration/FilterGeneric.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/configuration/FilterGeneric.java new file mode 100644 index 00000000..e66c8f21 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/configuration/FilterGeneric.java @@ -0,0 +1,9 @@ +package org.openslx.runvirt.configuration; + +public abstract class FilterGeneric extends Filter +{ + public FilterGeneric( String name ) + { + super( name ); + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/configuration/FilterManager.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/configuration/FilterManager.java new file mode 100644 index 00000000..a97ad6d1 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/configuration/FilterManager.java @@ -0,0 +1,80 @@ +package org.openslx.runvirt.configuration; + +import java.util.ArrayList; + +public final class FilterManager +{ + private ArrayList> filters; + private T config; + private R args; + + public FilterManager( T config, R args ) + { + this.filters = new ArrayList>(); + this.config = config; + this.args = args; + } + + public void register( Filter filter ) + { + this.register( filter, true ); + } + + public void register( Filter filter, boolean enabled ) + { + filter.setEnabled( enabled ); + this.filters.add( filter ); + } + + public void register( String name, FilterFunction filterFunction ) + { + this.register( name, filterFunction, true ); + } + + public void register( String name, FilterFunction filterFunction, boolean enabled ) + { + final Filter filter = new Filter( name ) { + @Override + public void filter( T document, R args ) throws FilterException + { + filterFunction.apply( document, args ); + } + }; + + filter.setEnabled( enabled ); + this.filters.add( filter ); + } + + public void filterAll() throws FilterException + { + for ( Filter filter : this.filters ) { + try { + filter.apply( this.config, this.args ); + } catch ( FilterException e ) { + final String errorMsg = new String( + "Error in configuration filter '" + filter.getName() + "':" + e.getLocalizedMessage() ); + throw new FilterException( errorMsg ); + } + } + } + + private String showFilters() + { + String filterSummary = new String(); + final int maxFilterNumCharacters = ( this.filters.size() + 1 ) / 10; + + for ( int i = 0; i < this.filters.size(); i++ ) { + final Filter filter = this.filters.get( i ); + final String paddedNumber = String.format( "%-" + maxFilterNumCharacters + "s", i + 1 ); + filterSummary += paddedNumber + ": " + filter.getName() + System.lineSeparator(); + } + + return filterSummary; + } + + @Override + public String toString() + { + return this.showFilters(); + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/configuration/FilterSpecific.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/configuration/FilterSpecific.java new file mode 100644 index 00000000..8cff83bd --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/configuration/FilterSpecific.java @@ -0,0 +1,18 @@ +package org.openslx.runvirt.configuration; + +public abstract class FilterSpecific extends Filter +{ + private final H hypervisor; + + public FilterSpecific( String name, H hypervisor ) + { + super( name ); + + this.hypervisor = hypervisor; + } + + public H getHypervisor() + { + return this.hypervisor; + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java index 8a70be33..bf76ebf2 100644 --- a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java @@ -1,11 +1,38 @@ package org.openslx.runvirt.plugin.qemu; +import java.io.File; + import org.apache.log4j.BasicConfigurator; import org.apache.log4j.LogManager; import org.apache.log4j.Logger; +import org.openslx.libvirt.domain.Domain; +import org.openslx.libvirt.xml.LibvirtXmlDocumentException; +import org.openslx.libvirt.xml.LibvirtXmlSerializationException; +import org.openslx.libvirt.xml.LibvirtXmlValidationException; +import org.openslx.runvirt.configuration.FilterException; +import org.openslx.runvirt.configuration.FilterManager; import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs; import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs.CmdLnOption; import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgsException; +import org.openslx.runvirt.plugin.qemu.configuration.FilterGenericCpu; +import org.openslx.runvirt.plugin.qemu.configuration.FilterGenericDiskCdromDevices; +import org.openslx.runvirt.plugin.qemu.configuration.FilterGenericDiskFloppyDevices; +import org.openslx.runvirt.plugin.qemu.configuration.FilterGenericDiskStorageDevices; +import org.openslx.runvirt.plugin.qemu.configuration.FilterGenericFileSystemDevices; +import org.openslx.runvirt.plugin.qemu.configuration.FilterGenericInterfaceDevices; +import org.openslx.runvirt.plugin.qemu.configuration.FilterGenericMemory; +import org.openslx.runvirt.plugin.qemu.configuration.FilterGenericName; +import org.openslx.runvirt.plugin.qemu.configuration.FilterGenericParallelDevices; +import org.openslx.runvirt.plugin.qemu.configuration.FilterSpecificQemuSerialDevices; +import org.openslx.runvirt.plugin.qemu.configuration.FilterGenericUuid; +import org.openslx.runvirt.plugin.qemu.configuration.FilterSpecificQemuArchitecture; +import org.openslx.runvirt.plugin.qemu.configuration.FilterSpecificQemuNvidiaGpuPassthrough; +import org.openslx.runvirt.plugin.qemu.virtualization.LibvirtHypervisorQemu; +import org.openslx.runvirt.plugin.qemu.virtualization.LibvirtHypervisorQemu.QemuSessionType; +import org.openslx.runvirt.virtualization.LibvirtHypervisor; +import org.openslx.runvirt.virtualization.LibvirtHypervisorException; +import org.openslx.runvirt.virtualization.LibvirtVirtualMachine; +import org.openslx.runvirt.virtualization.LibvirtVirtualMachineException; /** * Run-virt QEMU plugin (command line tool) to finalize a Libvirt domain XML configuration. @@ -65,6 +92,100 @@ public class App // print command line arguments for debugging purposes App.printCmdLnArgs( cmdLn ); + // create connection to the QEMU hypervisor via Libvirt + LibvirtHypervisor hypervisor = null; + try { + hypervisor = new LibvirtHypervisorQemu( QemuSessionType.LOCAL_USER_SESSION ); + } catch ( LibvirtHypervisorException e ) { + LOGGER.error( "Failed to connect to the QEMU virtualizer (Libvirt daemon): " + e.getLocalizedMessage() ); + System.exit( 2 ); + } + + // read Libvirt XML domain configuration template + final String xmlInputFileName = cmdLn.getVmCfgInpFileName(); + Domain config = null; + try { + final File xmlInputFile = new File( xmlInputFileName ); + config = new Domain( xmlInputFile ); + } catch ( LibvirtXmlDocumentException | LibvirtXmlSerializationException | LibvirtXmlValidationException e ) { + LOGGER.error( "Failed to read VM input configuration file: " + e.getLocalizedMessage() ); + hypervisor.close(); + System.exit( 3 ); + } + + // create filter manager to finalize VM configuration + final FilterManager filterManager; + filterManager = new FilterManager( config, cmdLn ); + + // register necessary filters to finalize configuration template + filterManager.register( new FilterGenericName(), true ); + filterManager.register( new FilterGenericUuid(), true ); + filterManager.register( new FilterGenericCpu(), true ); + filterManager.register( new FilterGenericMemory(), true ); + filterManager.register( new FilterGenericDiskStorageDevices(), true ); + filterManager.register( new FilterGenericDiskCdromDevices(), true ); + filterManager.register( new FilterGenericDiskFloppyDevices(), true ); + filterManager.register( new FilterGenericInterfaceDevices(), true ); + filterManager.register( new FilterGenericParallelDevices(), true ); + filterManager.register( new FilterGenericFileSystemDevices(), true ); + + // register QEMU specific filters to finalize configuration template + if ( hypervisor instanceof LibvirtHypervisorQemu ) { + final LibvirtHypervisorQemu hypervisorQemu = LibvirtHypervisorQemu.class.cast( hypervisor ); + + filterManager.register( new FilterSpecificQemuArchitecture( hypervisorQemu ), true ); + filterManager.register( new FilterSpecificQemuSerialDevices( hypervisorQemu ), true ); + filterManager.register( new FilterSpecificQemuNvidiaGpuPassthrough( hypervisorQemu ), false ); + } + + // finalize Libvirt VM configuration template + try { + filterManager.filterAll(); + } catch ( FilterException e ) { + LOGGER.error( "Failed to finalize VM configuration file: " + e.getLocalizedMessage() ); + hypervisor.close(); + System.exit( 4 ); + } + + // write finalized configuration to file if output file is specified + final String xmlOutputFileName = cmdLn.getVmCfgOutFileName(); + if ( xmlOutputFileName != null && !xmlOutputFileName.isEmpty() ) { + try { + final File xmlOutputFile = new File( xmlOutputFileName ); + config.toXml( xmlOutputFile ); + } catch ( LibvirtXmlSerializationException e ) { + LOGGER.error( "Failed to write VM output configuration file: " + e.getLocalizedMessage() ); + hypervisor.close(); + System.exit( 5 ); + } + } + + // define QEMU VM from finalized configuration + LibvirtVirtualMachine vm = null; + try { + vm = hypervisor.registerVm( config ); + } catch ( LibvirtHypervisorException e ) { + LOGGER.error( "Failed to define VM from configuration file: " + e.getLocalizedMessage() ); + hypervisor.close(); + System.exit( 6 ); + } + + try { + vm.start(); + } catch ( LibvirtVirtualMachineException e ) { + LOGGER.error( "Failed to start defined VM: " + e.getLocalizedMessage() ); + try { + hypervisor.deregisterVm( vm ); + } catch ( LibvirtHypervisorException | LibvirtVirtualMachineException e1 ) { + LOGGER.error( "Failed to undefine VM: " + e.getLocalizedMessage() ); + } + hypervisor.close(); + System.exit( 7 ); + } + + // close connection and let VM be running + hypervisor.close(); + // return with successful exit code System.exit( 0 ); } diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgs.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgs.java index 13b8c0e2..7e1a7a22 100644 --- a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgs.java +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgs.java @@ -289,13 +289,43 @@ public class CommandLineArgs } /** - * Returns the argument of the command line option {@link CmdLnOption#VM_AUDIO0}. + * Returns the argument of the command line option {@link CmdLnOption#VM_FSSRC0}. * - * @return argument of the command line option {@link CmdLnOption#VM_AUDIO0}. + * @return argument of the command line option {@link CmdLnOption#VM_FSSRC0}. */ - public String getVmModelSoundCard0() + public String getVmFsSrc0() { - return this.getArgument( CmdLnOption.VM_AUDIO0 ); + return this.getArgument( CmdLnOption.VM_FSSRC0 ); + } + + /** + * Returns the argument of the command line option {@link CmdLnOption#VM_FSTGT0}. + * + * @return argument of the command line option {@link CmdLnOption#VM_FSTGT0}. + */ + public String getVmFsTgt0() + { + return this.getArgument( CmdLnOption.VM_FSTGT0 ); + } + + /** + * Returns the argument of the command line option {@link CmdLnOption#VM_FSSRC1}. + * + * @return argument of the command line option {@link CmdLnOption#VM_FSSRC1}. + */ + public String getVmFsSrc1() + { + return this.getArgument( CmdLnOption.VM_FSSRC1 ); + } + + /** + * Returns the argument of the command line option {@link CmdLnOption#VM_FSTGT1}. + * + * @return argument of the command line option {@link CmdLnOption#VM_FSTGT1}. + */ + public String getVmFsTgt1() + { + return this.getArgument( CmdLnOption.VM_FSTGT1 ); } /** @@ -324,7 +354,10 @@ public class CommandLineArgs VM_PARALLEL0( 'p', "vmparallel0", true, "Device for the first parallel port interface" ), VM_SERIAL0 ( 'q', "vmserial0", true, "Device for the first serial port interface" ), VM_MAC0 ( 'a', "vmmac0", true, "MAC address for the first network interface" ), - VM_AUDIO0 ( 'x', "vmaudio0", true, "Hardware model for the first sound card" ); + VM_FSSRC0 ( 't', "vmfssrc0", true, "Source directory for first file system passthrough (shared folder)" ), + VM_FSTGT0 ( 'u', "vmfstgt0", true, "Target directory for first file system passthrough (shared folder)" ), + VM_FSSRC1 ( 'v', "vmfssrc1", true, "Source directory for second file system passthrough (shared folder)" ), + VM_FSTGT1 ( 'w', "vmfstgt1", true, "Target directory for second file system passthrough (shared folder)" ); // @formatter:on /** diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericCpu.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericCpu.java new file mode 100644 index 00000000..1fbcd568 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericCpu.java @@ -0,0 +1,26 @@ +package org.openslx.runvirt.plugin.qemu.configuration; + +import org.openslx.libvirt.domain.Domain; +import org.openslx.libvirt.domain.Domain.CpuCheck; +import org.openslx.libvirt.domain.Domain.CpuMode; +import org.openslx.runvirt.configuration.FilterException; +import org.openslx.runvirt.configuration.FilterGeneric; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs; + +public class FilterGenericCpu extends FilterGeneric +{ + private static final String FILTER_NAME = "CPU [number of cores, mode, ...]"; + + public FilterGenericCpu() + { + super( FilterGenericCpu.FILTER_NAME ); + } + + @Override + public void filter( Domain config, CommandLineArgs args ) throws FilterException + { + config.setVCpu( args.getVmNumCpus() ); + config.setCpuMode( CpuMode.HOST_PASSTHROUGH ); + config.setCpuCheck( CpuCheck.PARTIAL ); + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericDiskCdromDevices.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericDiskCdromDevices.java new file mode 100644 index 00000000..a17f3a8b --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericDiskCdromDevices.java @@ -0,0 +1,54 @@ +package org.openslx.runvirt.plugin.qemu.configuration; + +import java.util.ArrayList; + +import org.openslx.libvirt.domain.Domain; +import org.openslx.libvirt.domain.device.Disk.StorageType; +import org.openslx.libvirt.domain.device.DiskCdrom; +import org.openslx.runvirt.configuration.FilterException; +import org.openslx.runvirt.configuration.FilterGeneric; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs; +import org.openslx.vm.QemuMetaData; +import org.openslx.vm.QemuMetaDataUtils; + +public class FilterGenericDiskCdromDevices extends FilterGeneric +{ + private static final String FILTER_NAME = "Disk CDROM devices"; + + public FilterGenericDiskCdromDevices() + { + super( FilterGenericDiskCdromDevices.FILTER_NAME ); + } + + private void filterDiskCdromDevice( Domain config, String fileName, int index ) throws FilterException + { + final ArrayList devices = config.getDiskCdromDevices(); + final DiskCdrom disk = QemuMetaDataUtils.getArrayIndex( devices, index ); + + if ( disk != null ) { + if ( fileName == null ) { + // do not remove disk CDROM drive, but set local physical drive as input source + disk.setStorage( StorageType.BLOCK, QemuMetaData.CDROM_DEFAULT_PHYSICAL_DRIVE ); + } else if ( fileName.equals( "" ) ) { + // remove storage source if empty string is specified to emulate an empty CDROM drive + disk.removeStorage(); + } else { + // set disk image file as storage source of the disk CDROM drive + disk.setStorage( StorageType.FILE, fileName ); + } + } + } + + @Override + public void filter( Domain config, CommandLineArgs args ) throws FilterException + { + this.filterDiskCdromDevice( config, args.getVmDiskFileNameCdrom0(), 0 ); + this.filterDiskCdromDevice( config, args.getVmDiskFileNameCdrom1(), 1 ); + + // remove all additional disk CDROM devices + final ArrayList devices = config.getDiskCdromDevices(); + for ( int i = 2; i < devices.size(); i++ ) { + devices.get( i ).remove(); + } + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericDiskFloppyDevices.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericDiskFloppyDevices.java new file mode 100644 index 00000000..106e499e --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericDiskFloppyDevices.java @@ -0,0 +1,50 @@ +package org.openslx.runvirt.plugin.qemu.configuration; + +import java.util.ArrayList; + +import org.openslx.libvirt.domain.Domain; +import org.openslx.libvirt.domain.device.Disk.StorageType; +import org.openslx.libvirt.domain.device.DiskFloppy; +import org.openslx.runvirt.configuration.FilterException; +import org.openslx.runvirt.configuration.FilterGeneric; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs; +import org.openslx.vm.QemuMetaDataUtils; + +public class FilterGenericDiskFloppyDevices extends FilterGeneric +{ + private static final String FILTER_NAME = "Disk floppy devices"; + + public FilterGenericDiskFloppyDevices() + { + super( FilterGenericDiskFloppyDevices.FILTER_NAME ); + } + + private void filterDiskFloppyDevice( Domain config, String fileName, int index ) throws FilterException + { + final ArrayList devices = config.getDiskFloppyDevices(); + final DiskFloppy disk = QemuMetaDataUtils.getArrayIndex( devices, index ); + + if ( disk != null ) { + if ( fileName == null ) { + // remove disk floppy device if disk image file name is not set + disk.remove(); + } else { + // set image file of disk storage if disk floppy device is available + disk.setStorage( StorageType.FILE, fileName ); + } + } + } + + @Override + public void filter( Domain config, CommandLineArgs args ) throws FilterException + { + this.filterDiskFloppyDevice( config, args.getVmDiskFileNameFloppy0(), 0 ); + this.filterDiskFloppyDevice( config, args.getVmDiskFileNameFloppy1(), 1 ); + + // remove all additional disk storage devices + final ArrayList devices = config.getDiskFloppyDevices(); + for ( int i = 2; i < devices.size(); i++ ) { + devices.get( i ).remove(); + } + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericDiskStorageDevices.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericDiskStorageDevices.java new file mode 100644 index 00000000..0dcfddf9 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericDiskStorageDevices.java @@ -0,0 +1,49 @@ +package org.openslx.runvirt.plugin.qemu.configuration; + +import java.util.ArrayList; + +import org.openslx.libvirt.domain.Domain; +import org.openslx.libvirt.domain.device.Disk.StorageType; +import org.openslx.libvirt.domain.device.DiskStorage; +import org.openslx.runvirt.configuration.FilterException; +import org.openslx.runvirt.configuration.FilterGeneric; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs; +import org.openslx.vm.QemuMetaDataUtils; + +public class FilterGenericDiskStorageDevices extends FilterGeneric +{ + private static final String FILTER_NAME = "Disk storage devices [HDD, SSD, ...]"; + + public FilterGenericDiskStorageDevices() + { + super( FilterGenericDiskStorageDevices.FILTER_NAME ); + } + + private void filterDiskStorageDevice( Domain config, String fileName, int index ) throws FilterException + { + final ArrayList devices = config.getDiskStorageDevices(); + final DiskStorage disk = QemuMetaDataUtils.getArrayIndex( devices, index ); + + if ( disk != null ) { + if ( fileName == null ) { + // remove disk storage device if disk image file name is not set + disk.remove(); + } else { + // set image file of disk storage if disk storage device is available + disk.setStorage( StorageType.FILE, fileName ); + } + } + } + + @Override + public void filter( Domain config, CommandLineArgs args ) throws FilterException + { + this.filterDiskStorageDevice( config, args.getVmDiskFileNameHDD0(), 0 ); + + // remove all additional disk storage devices + final ArrayList devices = config.getDiskStorageDevices(); + for ( int i = 1; i < devices.size(); i++ ) { + devices.get( i ).remove(); + } + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericFileSystemDevices.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericFileSystemDevices.java new file mode 100644 index 00000000..1d06474f --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericFileSystemDevices.java @@ -0,0 +1,64 @@ +package org.openslx.runvirt.plugin.qemu.configuration; + +import java.util.ArrayList; + +import org.openslx.libvirt.domain.Domain; +import org.openslx.libvirt.domain.device.FileSystem; +import org.openslx.libvirt.domain.device.FileSystem.AccessMode; +import org.openslx.libvirt.domain.device.FileSystem.Type; +import org.openslx.runvirt.configuration.FilterException; +import org.openslx.runvirt.configuration.FilterGeneric; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs; +import org.openslx.vm.QemuMetaDataUtils; + +public class FilterGenericFileSystemDevices extends FilterGeneric +{ + private static final String FILTER_NAME = "File system devices"; + + public FilterGenericFileSystemDevices() + { + super( FilterGenericFileSystemDevices.FILTER_NAME ); + } + + private void filterFileSystemDevice( Domain config, String source, String target, int index ) throws FilterException + { + final ArrayList devices = config.getFileSystemDevices(); + final FileSystem fileSystem = QemuMetaDataUtils.getArrayIndex( devices, index ); + + if ( fileSystem == null ) { + // check if file system device source directory is specified + if ( source != null && target != null ) { + // file system device does not exist, so create new file system device + final FileSystem newFileSystem = config.addFileSystemDevice(); + newFileSystem.setType( Type.MOUNT ); + newFileSystem.setAccessMode( AccessMode.MAPPED ); + newFileSystem.setSource( source ); + newFileSystem.setTarget( target ); + } + } else { + if ( source == null || target == null ) { + // remove file system device since device source or target is not specified + fileSystem.remove(); + } else { + // change type, access mode, source and target of existing file system device + fileSystem.setType( Type.MOUNT ); + fileSystem.setAccessMode( AccessMode.MAPPED ); + fileSystem.setSource( source ); + fileSystem.setTarget( target ); + } + } + } + + @Override + public void filter( Domain config, CommandLineArgs args ) throws FilterException + { + this.filterFileSystemDevice( config, args.getVmFsSrc0(), args.getVmFsTgt0(), 0 ); + this.filterFileSystemDevice( config, args.getVmFsSrc1(), args.getVmFsTgt1(), 1 ); + + // remove all additional file system devices + final ArrayList devices = config.getFileSystemDevices(); + for ( int i = 1; i < devices.size(); i++ ) { + devices.get( i ).remove(); + } + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericInterfaceDevices.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericInterfaceDevices.java new file mode 100644 index 00000000..ea2782ba --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericInterfaceDevices.java @@ -0,0 +1,48 @@ +package org.openslx.runvirt.plugin.qemu.configuration; + +import java.util.ArrayList; + +import org.openslx.libvirt.domain.Domain; +import org.openslx.libvirt.domain.device.Interface; +import org.openslx.runvirt.configuration.FilterException; +import org.openslx.runvirt.configuration.FilterGeneric; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs; +import org.openslx.vm.QemuMetaDataUtils; + +public class FilterGenericInterfaceDevices extends FilterGeneric +{ + private static final String FILTER_NAME = "Network interface devices"; + + public FilterGenericInterfaceDevices() + { + super( FilterGenericInterfaceDevices.FILTER_NAME ); + } + + private void filterInterfaceDevice( Domain config, String macAddress, int index ) throws FilterException + { + final ArrayList devices = config.getInterfaceDevices(); + final Interface device = QemuMetaDataUtils.getArrayIndex( devices, index ); + + if ( device != null ) { + if ( macAddress == null ) { + // remove network interface device if MAC address is not set + device.remove(); + } else { + // set MAC address of network interface device if network interface device is available + device.setMacAddress( macAddress ); + } + } + } + + @Override + public void filter( Domain config, CommandLineArgs args ) throws FilterException + { + this.filterInterfaceDevice( config, args.getVmMacAddress0(), 0 ); + + // remove all additional disk storage devices + final ArrayList devices = config.getInterfaceDevices(); + for ( int i = 1; i < devices.size(); i++ ) { + devices.get( i ).remove(); + } + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericMemory.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericMemory.java new file mode 100644 index 00000000..d8d901d4 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericMemory.java @@ -0,0 +1,28 @@ +package org.openslx.runvirt.plugin.qemu.configuration; + +import java.math.BigInteger; + +import org.openslx.libvirt.domain.Domain; +import org.openslx.libvirt.domain.DomainUtils; +import org.openslx.runvirt.configuration.FilterException; +import org.openslx.runvirt.configuration.FilterGeneric; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs; + +public class FilterGenericMemory extends FilterGeneric +{ + private static final String FILTER_NAME = "Memory [normal, current (balloning)]"; + + public FilterGenericMemory() + { + super( FilterGenericMemory.FILTER_NAME ); + } + + @Override + public void filter( Domain config, CommandLineArgs args ) throws FilterException + { + BigInteger memory = DomainUtils.decodeMemory( args.getVmMemory(), "MiB" ); + + config.setMemory( memory ); + config.setCurrentMemory( memory ); + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericName.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericName.java new file mode 100644 index 00000000..00644b23 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericName.java @@ -0,0 +1,23 @@ +package org.openslx.runvirt.plugin.qemu.configuration; + +import org.openslx.libvirt.domain.Domain; +import org.openslx.runvirt.configuration.FilterException; +import org.openslx.runvirt.configuration.FilterGeneric; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs; + +public class FilterGenericName extends FilterGeneric +{ + private static final String FILTER_NAME = "Name [(display) name]"; + + public FilterGenericName() + { + super( FilterGenericName.FILTER_NAME ); + } + + @Override + public void filter( Domain config, CommandLineArgs args ) throws FilterException + { + config.setName( args.getVmName() ); + config.setTitle( args.getVmDisplayName() ); + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericParallelDevices.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericParallelDevices.java new file mode 100644 index 00000000..458f69cb --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericParallelDevices.java @@ -0,0 +1,58 @@ +package org.openslx.runvirt.plugin.qemu.configuration; + +import java.util.ArrayList; + +import org.openslx.libvirt.domain.Domain; +import org.openslx.libvirt.domain.device.Parallel; +import org.openslx.libvirt.domain.device.Parallel.Type; +import org.openslx.runvirt.configuration.FilterException; +import org.openslx.runvirt.configuration.FilterGeneric; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs; +import org.openslx.vm.QemuMetaDataUtils; + +public class FilterGenericParallelDevices extends FilterGeneric +{ + private static final String FILTER_NAME = "Parallel devices"; + + public FilterGenericParallelDevices() + { + super( FilterGenericParallelDevices.FILTER_NAME ); + } + + private void filterParallelDevice( Domain config, String fileName, int index ) throws FilterException + { + final ArrayList devices = config.getParallelDevices(); + final Parallel device = QemuMetaDataUtils.getArrayIndex( devices, index ); + + if ( device == null ) { + // check if device file name is specified + if ( fileName != null ) { + // parallel port device does not exist, so create new parallel port device + final Parallel newDevice = config.addParallelDevice(); + newDevice.setType( Type.DEV ); + newDevice.setSource( fileName ); + } + } else { + if ( fileName == null ) { + // remove device since device file is not specified + device.remove(); + } else { + // change type and source of existing parallel port device + device.setType( Type.DEV ); + device.setSource( fileName ); + } + } + } + + @Override + public void filter( Domain config, CommandLineArgs args ) throws FilterException + { + this.filterParallelDevice( config, args.getVmDeviceSerial0(), 0 ); + + // remove all additional parallel devices + final ArrayList devices = config.getParallelDevices(); + for ( int i = 1; i < devices.size(); i++ ) { + devices.get( i ).remove(); + } + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericUuid.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericUuid.java new file mode 100644 index 00000000..f10a32b7 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericUuid.java @@ -0,0 +1,22 @@ +package org.openslx.runvirt.plugin.qemu.configuration; + +import org.openslx.libvirt.domain.Domain; +import org.openslx.runvirt.configuration.FilterException; +import org.openslx.runvirt.configuration.FilterGeneric; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs; + +public class FilterGenericUuid extends FilterGeneric +{ + private static final String FILTER_NAME = "UUID"; + + public FilterGenericUuid() + { + super( FilterGenericUuid.FILTER_NAME ); + } + + @Override + public void filter( Domain config, CommandLineArgs args ) throws FilterException + { + config.setUuid( args.getVmUuid() ); + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterSpecificQemuArchitecture.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterSpecificQemuArchitecture.java new file mode 100644 index 00000000..0466b5e9 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterSpecificQemuArchitecture.java @@ -0,0 +1,199 @@ +package org.openslx.runvirt.plugin.qemu.configuration; + +import java.util.ArrayList; +import java.util.List; + +import org.openslx.libvirt.capabilities.Capabilities; +import org.openslx.libvirt.capabilities.guest.Guest; +import org.openslx.libvirt.capabilities.guest.Machine; +import org.openslx.libvirt.domain.Domain; +import org.openslx.libvirt.domain.Domain.OsType; +import org.openslx.libvirt.domain.Domain.Type; +import org.openslx.runvirt.configuration.FilterException; +import org.openslx.runvirt.configuration.FilterSpecific; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs; +import org.openslx.runvirt.plugin.qemu.virtualization.LibvirtHypervisorQemu; +import org.openslx.runvirt.virtualization.LibvirtHypervisorException; + +public class FilterSpecificQemuArchitecture extends FilterSpecific +{ + private static final String FILTER_NAME = "QEMU Architecture [CPU architecture, machine type, ...]"; + + // used as instance of an singelton, always use getCapabilities to retrieve caps instance + private Capabilities capabilities = null; + + public FilterSpecificQemuArchitecture( LibvirtHypervisorQemu hypervisor ) + { + super( FilterSpecificQemuArchitecture.FILTER_NAME, hypervisor ); + } + + private Capabilities getCapabilities() throws FilterException + { + // retrieve capabilities from QEMU hypervisor only once + if ( this.capabilities == null ) { + try { + this.capabilities = this.getHypervisor().getCapabilites(); + } catch ( LibvirtHypervisorException e ) { + final String errorMsg = new String( + "Failed to get host capabilities from QEMU virtualizer: " + e.getLocalizedMessage() ); + throw new FilterException( errorMsg ); + } + } + + return this.capabilities; + } + + private Guest getTargetGuestFromArchName( String architectureName ) throws FilterException + { + final List guests = this.getCapabilities().getGuests(); + Guest targetGuest = null; + + if ( architectureName == null ) { + return targetGuest; + } + + for ( Guest guest : guests ) { + final String guestArchitectureName = guest.getArchName(); + if ( architectureName.equals( guestArchitectureName ) ) { + targetGuest = guest; + break; + } + } + + return targetGuest; + } + + private Machine getTargetMachineFromGuest( Guest guest, String machineName ) throws FilterException + { + final List machines = guest.getArchMachines(); + Machine targetMachine = null; + + if ( machineName == null ) { + return targetMachine; + } + + for ( Machine machine : machines ) { + if ( machineName.equals( machine.getName() ) ) { + targetMachine = machine; + break; + } + } + + return targetMachine; + } + + private List getCanonicalNamesFromTargetMachines( Guest guest ) throws FilterException + { + final List machines = guest.getArchMachines(); + final List canonicalNames = new ArrayList(); + + for ( Machine machine : machines ) { + final String canonicalName = machine.getCanonicalMachine(); + if ( canonicalName != null ) { + canonicalNames.add( canonicalName ); + } + } + + return canonicalNames; + } + + @Override + public void filter( Domain config, CommandLineArgs args ) throws FilterException + { + // get source architecture, machine- and OS type + final String sourceArchitectureName = config.getOsArch(); + final String sourceMachine = config.getOsMachine(); + final OsType sourceOsType = config.getOsType(); + final Type sourceDomainType = config.getType(); + + // check if source architecture is supported by one of the hypervisor's guests + Guest targetGuest = null; + if ( sourceArchitectureName == null ) { + final String errorMsg = new String( "Source architecture is not specified!" ); + throw new FilterException( errorMsg ); + } else { + targetGuest = this.getTargetGuestFromArchName( sourceArchitectureName ); + if ( targetGuest == null ) { + final String errorMsg = new String( "Source architecture is not supported by the virtualizer!" ); + throw new FilterException( errorMsg ); + } + } + + // check if source machine is supported by the hypervisor + Machine targetMachine = null; + if ( sourceMachine == null ) { + final String errorMsg = new String( "Source machine type is not specified!" ); + throw new FilterException( errorMsg ); + } else { + // get all possible machine type for supported source architecture + targetMachine = this.getTargetMachineFromGuest( targetGuest, sourceMachine ); + + if ( targetMachine == null ) { + // source machine is not directly supported by the hypervisor + // check if up- or downgraded version of the chipset is supported by the hypervisor + List targetMachineCanonicalNames = this.getCanonicalNamesFromTargetMachines( targetGuest ); + + // retrieve overwrite chipset name from canonical machine names + String sourceMachineOverwrite = null; + for ( String targetMachineCanonicalName : targetMachineCanonicalNames ) { + if ( sourceMachine.contains( targetMachineCanonicalName ) ) { + sourceMachineOverwrite = targetMachineCanonicalName; + break; + } + } + + // if overwrite available, patch the machine type + if ( sourceMachineOverwrite != null ) { + config.setOsMachine( sourceMachineOverwrite ); + } else { + final String errorMsg = new String( "Source machine type is not supported by the virtualizer!" ); + throw new FilterException( errorMsg ); + } + } + } + + // check if source OS type is supported by the hypervisor's architecture + if ( sourceOsType == null ) { + final String errorMsg = new String( "OS type is not specified!" ); + throw new FilterException( errorMsg ); + } else { + if ( !sourceOsType.toString().equals( targetGuest.getOsType().toString() ) ) { + final String errorMsg = new String( "OS type is not supported by the virtualizer!" ); + throw new FilterException( errorMsg ); + } + } + + // check if source domain type is supported by the hypervisor's architecture + Type targetDomainType = null; + if ( sourceDomainType == null ) { + final String errorMsg = new String( "Source domain type is not specified!" ); + throw new FilterException( errorMsg ); + } else { + final List targetDomains = targetGuest.getArchDomains(); + + // retrieve supported domain type + for ( org.openslx.libvirt.capabilities.guest.Domain domain : targetDomains ) { + final Type domainType = domain.getType(); + if ( domainType == sourceDomainType ) { + targetDomainType = domainType; + break; + } + } + + // check supported domain type + if ( targetDomainType == null ) { + final String errorMsg = new String( "Source domain type is not supported by the virtualizer!" ); + throw new FilterException( errorMsg ); + } + } + + // patch path of QEMU emulator binary + final String archEmulator = targetGuest.getArchEmulator(); + if ( archEmulator == null ) { + final String errorMsg = new String( "Emulation of source architecture is not supported by the virtualizer!" ); + throw new FilterException( errorMsg ); + } else { + config.setDevicesEmulator( targetGuest.getArchEmulator() ); + } + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterSpecificQemuNvidiaGpuPassthrough.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterSpecificQemuNvidiaGpuPassthrough.java new file mode 100644 index 00000000..913eeb5a --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterSpecificQemuNvidiaGpuPassthrough.java @@ -0,0 +1,26 @@ +package org.openslx.runvirt.plugin.qemu.configuration; + +import org.openslx.libvirt.domain.Domain; +import org.openslx.runvirt.configuration.FilterException; +import org.openslx.runvirt.configuration.FilterSpecific; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs; +import org.openslx.runvirt.plugin.qemu.virtualization.LibvirtHypervisorQemu; + +public class FilterSpecificQemuNvidiaGpuPassthrough extends FilterSpecific +{ + private static final String FILTER_NAME = "QEMU GPU passthrough [Nvidia]"; + + public FilterSpecificQemuNvidiaGpuPassthrough( LibvirtHypervisorQemu hypervisor ) + { + super( FilterSpecificQemuNvidiaGpuPassthrough.FILTER_NAME, hypervisor ); + } + + @Override + public void filter( Domain config, CommandLineArgs args ) throws FilterException + { + // check if IOMMU support is available on the host + + // TODO: implement Nvidia hypervisor shadowing + // call this filter at the end, since -> override of software graphics to 'none' necessary + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterSpecificQemuSerialDevices.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterSpecificQemuSerialDevices.java new file mode 100644 index 00000000..258027b8 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/FilterSpecificQemuSerialDevices.java @@ -0,0 +1,69 @@ +package org.openslx.runvirt.plugin.qemu.configuration; + +import java.util.ArrayList; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +import org.openslx.libvirt.domain.Domain; +import org.openslx.libvirt.domain.device.Serial.Type; +import org.openslx.libvirt.domain.device.Serial; +import org.openslx.runvirt.configuration.FilterException; +import org.openslx.runvirt.configuration.FilterSpecific; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs; +import org.openslx.runvirt.plugin.qemu.virtualization.LibvirtHypervisorQemu; +import org.openslx.vm.QemuMetaDataUtils; + +public class FilterSpecificQemuSerialDevices extends FilterSpecific +{ + private static final String FILTER_NAME = "Serial devices"; + + public FilterSpecificQemuSerialDevices( LibvirtHypervisorQemu hypervisor ) + { + super( FilterSpecificQemuSerialDevices.FILTER_NAME, hypervisor ); + } + + private ArrayList getSerialDevDevices( Domain config ) + { + final ArrayList devices = config.getSerialDevices(); + final Predicate byDeviceTypeDev = device -> device.getType() == Type.DEV; + + return devices.stream().filter( byDeviceTypeDev ).collect( Collectors.toCollection( ArrayList::new ) ); + } + + private void filterSerialDevice( Domain config, String fileName, int index ) throws FilterException + { + final ArrayList devices = this.getSerialDevDevices( config ); + final Serial device = QemuMetaDataUtils.getArrayIndex( devices, index ); + + if ( device == null ) { + // check if device file name is specified + if ( fileName != null ) { + // serial port device is not available, so create new serial port device + final Serial newDevice = config.addSerialDevice(); + newDevice.setType( Type.DEV ); + newDevice.setSource( fileName ); + } + } else { + if ( fileName == null ) { + // remove serial port device if device file name is not set + device.remove(); + } else { + // set type and source of existing serial port device + device.setType( Type.DEV ); + device.setSource( fileName ); + } + } + } + + @Override + public void filter( Domain config, CommandLineArgs args ) throws FilterException + { + this.filterSerialDevice( config, args.getVmDeviceSerial0(), 0 ); + + // remove all additional serial devices + final ArrayList devices = this.getSerialDevDevices( config ); + for ( int i = 1; i < devices.size(); i++ ) { + devices.get( i ).remove(); + } + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/virtualization/LibvirtHypervisorQemu.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/virtualization/LibvirtHypervisorQemu.java new file mode 100644 index 00000000..260c3f4e --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/virtualization/LibvirtHypervisorQemu.java @@ -0,0 +1,39 @@ +package org.openslx.runvirt.plugin.qemu.virtualization; + +import org.openslx.runvirt.virtualization.LibvirtHypervisor; +import org.openslx.runvirt.virtualization.LibvirtHypervisorException; + +public class LibvirtHypervisorQemu extends LibvirtHypervisor +{ + public LibvirtHypervisorQemu( QemuSessionType type ) throws LibvirtHypervisorException + { + super( type.getConnectionUri() ); + } + + public enum QemuSessionType + { + // @formatter:off + LOCAL_SYSTEM_SESSION( "qemu:///system" ), + LOCAL_USER_SESSION ( "qemu:///session" ); + // @formatter:on + + private final String connectionUri; + + QemuSessionType( String connectionUri ) + { + this.connectionUri = connectionUri; + } + + public String getConnectionUri() + { + return this.connectionUri; + } + + // TODO: + // Implement capabilities -> get host architecture => decision whether to emulate or use KVM? -> change domain of XML + // fill in given HDD file, CDROM, ... + // GPU-Passthrough: patch XML with hypervisor disable bit, ..., to get Nvidia driver working + // Add hostdev für GPU passthrough -> add PCI ID arguments to cmdln parser + // + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtHypervisor.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtHypervisor.java new file mode 100644 index 00000000..345900ab --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtHypervisor.java @@ -0,0 +1,99 @@ +package org.openslx.runvirt.virtualization; + +import java.io.Closeable; + +import org.libvirt.Connect; +import org.libvirt.LibvirtException; +import org.openslx.libvirt.capabilities.Capabilities; +import org.openslx.libvirt.xml.LibvirtXmlDocumentException; +import org.openslx.libvirt.xml.LibvirtXmlSerializationException; +import org.openslx.libvirt.xml.LibvirtXmlValidationException; + +public abstract class LibvirtHypervisor implements Closeable +{ + protected Connect hypervisor = null; + + public LibvirtHypervisor( String connectionUri ) throws LibvirtHypervisorException + { + this.connect( connectionUri ); + } + + protected void connect( String connectionUri ) throws LibvirtHypervisorException + { + try { + this.hypervisor = new Connect( connectionUri ); + } catch ( LibvirtException e ) { + throw new LibvirtHypervisorException( e.getLocalizedMessage() ); + } + } + + public Capabilities getCapabilites() throws LibvirtHypervisorException + { + Capabilities hypervisorCapabilities = null; + + try { + final String hypervisorCapabilitiesString = this.hypervisor.getCapabilities(); + hypervisorCapabilities = new Capabilities( hypervisorCapabilitiesString ); + } catch ( LibvirtException | LibvirtXmlDocumentException | LibvirtXmlSerializationException + | LibvirtXmlValidationException e ) { + throw new LibvirtHypervisorException( e.getLocalizedMessage() ); + } + + return hypervisorCapabilities; + } + + public int getVersion() throws LibvirtHypervisorException + { + int hypervisorVersion = 0; + + try { + final long hypervisorVersionLong = this.hypervisor.getVersion(); + hypervisorVersion = Long.valueOf( hypervisorVersionLong ).intValue(); + } catch ( LibvirtException e ) { + throw new LibvirtHypervisorException( e.getLocalizedMessage() ); + } + + return hypervisorVersion; + } + + public LibvirtVirtualMachine registerVm( org.openslx.libvirt.domain.Domain vmConfiguration ) + throws LibvirtHypervisorException + { + final String xmlVmConfiguration = vmConfiguration.toString(); + org.libvirt.Domain libvirtDomain = null; + + try { + libvirtDomain = this.hypervisor.domainDefineXML( xmlVmConfiguration ); + } catch ( LibvirtException e ) { + throw new LibvirtHypervisorException( e.getLocalizedMessage() ); + } + + return new LibvirtVirtualMachine( libvirtDomain ); + } + + public void deregisterVm( LibvirtVirtualMachine vm ) + throws LibvirtHypervisorException, LibvirtVirtualMachineException + { + // stop virtual machine if machine is running + if ( vm.isRunning() ) { + vm.stop(); + } + + // deregister and remove virtual machine from hypervisor + try { + vm.getLibvirtDomain().undefine(); + } catch ( LibvirtException e ) { + throw new LibvirtHypervisorException( e.getLocalizedMessage() ); + } + } + + @Override + public void close() + { + try { + this.hypervisor.close(); + } catch ( LibvirtException e ) { + e.printStackTrace(); + } + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtHypervisorException.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtHypervisorException.java new file mode 100644 index 00000000..acf640e1 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtHypervisorException.java @@ -0,0 +1,14 @@ +package org.openslx.runvirt.virtualization; + +public class LibvirtHypervisorException extends Exception +{ + /** + * Version for serialization. + */ + private static final long serialVersionUID = -3631452625806770209L; + + LibvirtHypervisorException( String errorMsg ) + { + super( errorMsg ); + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtVirtualMachine.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtVirtualMachine.java new file mode 100644 index 00000000..781bd938 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtVirtualMachine.java @@ -0,0 +1,81 @@ +package org.openslx.runvirt.virtualization; + +import org.libvirt.Domain; +import org.libvirt.LibvirtException; + +public class LibvirtVirtualMachine +{ + private Domain domain; + + LibvirtVirtualMachine( Domain vm ) + { + this.domain = vm; + } + + public Domain getLibvirtDomain() + { + return this.domain; + } + + public boolean isRunning() throws LibvirtVirtualMachineException + { + int state = 0; + + try { + state = this.domain.isActive(); + } catch ( LibvirtException e ) { + throw new LibvirtVirtualMachineException( e.getLocalizedMessage() ); + } + + return ( state == 0 ) ? false : true; + } + + public void start() throws LibvirtVirtualMachineException + { + if ( !this.isRunning() ) { + try { + this.domain.create(); + } catch ( LibvirtException e ) { + throw new LibvirtVirtualMachineException( e.getLocalizedMessage() ); + } + } + } + + public void stop() throws LibvirtVirtualMachineException + { + if ( this.isRunning() ) { + try { + this.domain.shutdown(); + } catch ( LibvirtException e ) { + throw new LibvirtVirtualMachineException( e.getLocalizedMessage() ); + } + } + } + + public void suspend() throws LibvirtVirtualMachineException + { + try { + this.domain.suspend(); + } catch ( LibvirtException e ) { + throw new LibvirtVirtualMachineException( e.getLocalizedMessage() ); + } + } + + public void resume() throws LibvirtVirtualMachineException + { + try { + this.domain.resume(); + } catch ( LibvirtException e ) { + throw new LibvirtVirtualMachineException( e.getLocalizedMessage() ); + } + } + + public void reboot() throws LibvirtVirtualMachineException + { + try { + this.domain.reboot( 0 ); + } catch ( LibvirtException e ) { + throw new LibvirtVirtualMachineException( e.getLocalizedMessage() ); + } + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtVirtualMachineException.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtVirtualMachineException.java new file mode 100644 index 00000000..4e8ee1ba --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/virtualization/LibvirtVirtualMachineException.java @@ -0,0 +1,14 @@ +package org.openslx.runvirt.virtualization; + +public class LibvirtVirtualMachineException extends Exception +{ + /** + * Version for serialization. + */ + private static final long serialVersionUID = -5371327391243047616L; + + public LibvirtVirtualMachineException( String errorMsg ) + { + super( errorMsg ); + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/AppTest.java b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/AppTest.java index 126fd26d..9f8f925f 100644 --- a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/AppTest.java +++ b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/AppTest.java @@ -63,7 +63,7 @@ public class AppTest assertTrue( shortHelpOptionCorrectOutput.contains( App.APP_DESC ) ); // test that no error was logged and output is available - assertEquals( 1641, shortHelpOptionCorrectOutput.length() ); + assertEquals( 2026, shortHelpOptionCorrectOutput.length() ); assertEquals( 0, shortHelpOptionCorrectErrOutput.length() ); } @@ -91,7 +91,7 @@ public class AppTest assertTrue( longHelpOptionCorrectOutput.contains( App.APP_DESC ) ); // test that no error was logged and output is available - assertEquals( 1641, longHelpOptionCorrectOutput.length() ); + assertEquals( 2026, longHelpOptionCorrectOutput.length() ); assertEquals( 0, longHelpOptionCorrectErrOutput.length() ); } @@ -119,7 +119,7 @@ public class AppTest assertTrue( shortHelpOptionIncorrectOutput.contains( App.APP_DESC ) ); // test that error was logged and output is available - assertEquals( 1641, shortHelpOptionIncorrectOutput.length() ); + assertEquals( 2026, shortHelpOptionIncorrectOutput.length() ); assertEquals( 0, shortHelpOptionIncorrectErrOutput.length() ); } @@ -147,7 +147,7 @@ public class AppTest assertTrue( longHelpOptionIncorrectOutput.contains( App.APP_DESC ) ); // test that error was logged and output is available - assertEquals( 1641, longHelpOptionIncorrectOutput.length() ); + assertEquals( 2026, longHelpOptionIncorrectOutput.length() ); assertEquals( 0, longHelpOptionIncorrectErrOutput.length() ); } diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgsTest.java b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgsTest.java index 1399f9a4..ee3e0d1d 100644 --- a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgsTest.java +++ b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/cmdln/CommandLineArgsTest.java @@ -13,8 +13,8 @@ import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs.CmdLnOption; public class CommandLineArgsTest { // @formatter:off - private static final String CMDLN_PREFIX_OPTION_SHORT = "-"; - private static final String CMDLN_PREFIX_OPTION_LONG = "--"; + public static final String CMDLN_PREFIX_OPTION_SHORT = "-"; + public static final String CMDLN_PREFIX_OPTION_LONG = "--"; private static final String CMDLN_TEST_NAME = "test"; private static final String CMDLN_TEST_FILENAME = System.getProperty( "user.dir" ) + File.separator + CMDLN_TEST_NAME; @@ -25,7 +25,6 @@ public class CommandLineArgsTest private static final String CMDLN_TEST_PARPORT = "/dev/parport0"; private static final String CMDLN_TEST_SERPORT = "/dev/ttyS0"; private static final String CMDLN_TEST_MAC = "02:42:8e:77:1b:e6"; - private static final String CMDLN_TEST_AUDIO_MODEL = "sb16"; // @formatter:on @Test @@ -519,30 +518,114 @@ public class CommandLineArgsTest } @Test - @DisplayName( "Test the parsing of the VM first sound card type command line option (short version)" ) - public void testCmdlnOptionVmAudio0Short() throws CommandLineArgsException + @DisplayName( "Test the parsing of the VM first file system source command line option (short version)" ) + public void testCmdlnOptionVmFsSrc0Short() throws CommandLineArgsException { final String[] args = { - CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.VM_AUDIO0.getShortOption(), - CMDLN_TEST_AUDIO_MODEL + CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.VM_FSSRC0.getShortOption(), + CMDLN_TEST_FILENAME + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_FILENAME, cmdLn.getVmFsSrc0() ); + } + + @Test + @DisplayName( "Test the parsing of the VM first file system source command line option (long version)" ) + public void testCmdlnOptionVmFsSrc0Long() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_FSSRC0.getLongOption(), + CMDLN_TEST_FILENAME + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_FILENAME, cmdLn.getVmFsSrc0() ); + } + + @Test + @DisplayName( "Test the parsing of the VM first file system target command line option (short version)" ) + public void testCmdlnOptionVmFsTgt0Short() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.VM_FSTGT0.getShortOption(), + CMDLN_TEST_NAME + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_NAME, cmdLn.getVmFsTgt0() ); + } + + @Test + @DisplayName( "Test the parsing of the VM first file system target command line option (long version)" ) + public void testCmdlnOptionVmFsTgt0Long() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_FSTGT0.getLongOption(), + CMDLN_TEST_NAME }; CommandLineArgs cmdLn = new CommandLineArgs( args ); - assertEquals( CMDLN_TEST_AUDIO_MODEL, cmdLn.getVmModelSoundCard0() ); + assertEquals( CMDLN_TEST_NAME, cmdLn.getVmFsTgt0() ); } @Test - @DisplayName( "Test the parsing of the VM first sound card type command line option (long version)" ) - public void testCmdlnOptionVmAudio0Long() throws CommandLineArgsException + @DisplayName( "Test the parsing of the VM second file system source command line option (short version)" ) + public void testCmdlnOptionVmFsSrc1Short() throws CommandLineArgsException { final String[] args = { - CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_AUDIO0.getLongOption(), - CMDLN_TEST_AUDIO_MODEL + CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.VM_FSSRC1.getShortOption(), + CMDLN_TEST_FILENAME + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_FILENAME, cmdLn.getVmFsSrc1() ); + } + + @Test + @DisplayName( "Test the parsing of the VM second file system source command line option (long version)" ) + public void testCmdlnOptionVmFsSrc1Long() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_FSSRC1.getLongOption(), + CMDLN_TEST_FILENAME + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_FILENAME, cmdLn.getVmFsSrc1() ); + } + + @Test + @DisplayName( "Test the parsing of the VM second file system target command line option (short version)" ) + public void testCmdlnOptionVmFsTgt1Short() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_SHORT + CmdLnOption.VM_FSTGT1.getShortOption(), + CMDLN_TEST_NAME + }; + + CommandLineArgs cmdLn = new CommandLineArgs( args ); + + assertEquals( CMDLN_TEST_NAME, cmdLn.getVmFsTgt1() ); + } + + @Test + @DisplayName( "Test the parsing of the VM second file system target command line option (long version)" ) + public void testCmdlnOptionVmFsTgt1Long() throws CommandLineArgsException + { + final String[] args = { + CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_FSTGT1.getLongOption(), + CMDLN_TEST_NAME }; CommandLineArgs cmdLn = new CommandLineArgs( args ); - assertEquals( CMDLN_TEST_AUDIO_MODEL, cmdLn.getVmModelSoundCard0() ); + assertEquals( CMDLN_TEST_NAME, cmdLn.getVmFsTgt1() ); } } diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericCpuTest.java b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericCpuTest.java new file mode 100644 index 00000000..3814bfb6 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericCpuTest.java @@ -0,0 +1,34 @@ +package org.openslx.runvirt.plugin.qemu.configuration; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.openslx.libvirt.domain.Domain; +import org.openslx.libvirt.domain.Domain.CpuCheck; +import org.openslx.libvirt.domain.Domain.CpuMode; +import org.openslx.runvirt.configuration.FilterException; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs; + +public class FilterGenericCpuTest +{ + @Test + @DisplayName( "Test filtering of VM CPU configuration" ) + public void testFilterGenericCpu() throws FilterException + { + final FilterGenericCpu filter = new FilterGenericCpu(); + final Domain config = FilterTestUtils.getDefaultDomain(); + final CommandLineArgs args = FilterTestUtils.getDefaultCmdLnArgs(); + + assertNotEquals( Integer.parseInt( FilterTestUtils.DEFAULT_VM_NCPUS ), config.getVCpu() ); + assertNotEquals( CpuMode.HOST_PASSTHROUGH, config.getCpuMode() ); + assertEquals( CpuCheck.PARTIAL, config.getCpuCheck() ); + + filter.filter( config, args ); + + assertEquals( Integer.parseInt( FilterTestUtils.DEFAULT_VM_NCPUS ), config.getVCpu() ); + assertEquals( CpuMode.HOST_PASSTHROUGH, config.getCpuMode() ); + assertEquals( CpuCheck.PARTIAL, config.getCpuCheck() ); + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericDiskStorageDevicesTest.java b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericDiskStorageDevicesTest.java new file mode 100644 index 00000000..93282e78 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericDiskStorageDevicesTest.java @@ -0,0 +1,61 @@ +package org.openslx.runvirt.plugin.qemu.configuration; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +import java.util.ArrayList; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.openslx.libvirt.domain.Domain; +import org.openslx.libvirt.domain.device.Disk.StorageType; +import org.openslx.libvirt.domain.device.DiskStorage; +import org.openslx.runvirt.configuration.FilterException; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs; + +public class FilterGenericDiskStorageDevicesTest +{ + @Test + @DisplayName( "Test filtering of VM disk storage devices configuration with specified input data" ) + public void testFilterGenericDiskStorageDevices() throws FilterException + { + final FilterGenericDiskStorageDevices filter = new FilterGenericDiskStorageDevices(); + final Domain config = FilterTestUtils.getDefaultDomain(); + final CommandLineArgs args = FilterTestUtils.getDefaultCmdLnArgs(); + + final ArrayList devicesBeforeFiltering = config.getDiskStorageDevices(); + assertEquals( 1, devicesBeforeFiltering.size() ); + assertNotEquals( StorageType.FILE, devicesBeforeFiltering.get( 0 ).getStorageType() ); + assertNotEquals( FilterTestUtils.DEFAULT_VM_HDD0, devicesBeforeFiltering.get( 0 ).getStorageSource() ); + + filter.filter( config, args ); + + final ArrayList devicesAfterFiltering = config.getDiskStorageDevices(); + assertEquals( 1, devicesAfterFiltering.size() ); + assertEquals( StorageType.FILE, devicesAfterFiltering.get( 0 ).getStorageType() ); + assertEquals( FilterTestUtils.DEFAULT_VM_HDD0, devicesAfterFiltering.get( 0 ).getStorageSource() ); + } + + @Test + @DisplayName( "Test filtering of VM disk storage devices configuration with unspecified input data" ) + public void testFilterGenericDiskStorageDevicesNoData() throws FilterException + { + final FilterGenericDiskStorageDevices filter = new FilterGenericDiskStorageDevices(); + final Domain config = FilterTestUtils.getDefaultDomain(); + final CommandLineArgs args = FilterTestUtils.getEmptyCmdLnArgs(); + + final ArrayList devicesBeforeFiltering = config.getDiskStorageDevices(); + assertEquals( 1, devicesBeforeFiltering.size() ); + + filter.filter( config, args ); + + final ArrayList devicesAfterFiltering = config.getDiskStorageDevices(); + assertEquals( 0, devicesAfterFiltering.size() ); + } + + public static void main( String[] args ) throws FilterException + { + FilterGenericDiskStorageDevicesTest test = new FilterGenericDiskStorageDevicesTest(); + test.testFilterGenericDiskStorageDevicesNoData(); + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericMemoryTest.java b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericMemoryTest.java new file mode 100644 index 00000000..794e251c --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericMemoryTest.java @@ -0,0 +1,35 @@ +package org.openslx.runvirt.plugin.qemu.configuration; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +import java.math.BigInteger; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.openslx.libvirt.domain.Domain; +import org.openslx.libvirt.domain.DomainUtils; +import org.openslx.runvirt.configuration.FilterException; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs; + +public class FilterGenericMemoryTest +{ + @Test + @DisplayName( "Test filtering of VM memory configuration" ) + public void testFilterGenericMemory() throws FilterException + { + final FilterGenericMemory filter = new FilterGenericMemory(); + final Domain config = FilterTestUtils.getDefaultDomain(); + final CommandLineArgs args = FilterTestUtils.getDefaultCmdLnArgs(); + + final BigInteger defaultMemory = DomainUtils.decodeMemory( FilterTestUtils.DEFAULT_VM_MEM, "MiB" ); + + assertNotEquals( defaultMemory.toString(), config.getMemory().toString() ); + assertNotEquals( defaultMemory.toString(), config.getCurrentMemory().toString() ); + + filter.filter( config, args ); + + assertEquals( defaultMemory.toString(), config.getMemory().toString() ); + assertEquals( defaultMemory.toString(), config.getCurrentMemory().toString() ); + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericNameTest.java b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericNameTest.java new file mode 100644 index 00000000..93224702 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericNameTest.java @@ -0,0 +1,30 @@ +package org.openslx.runvirt.plugin.qemu.configuration; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.openslx.libvirt.domain.Domain; +import org.openslx.runvirt.configuration.FilterException; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs; + +public class FilterGenericNameTest +{ + @Test + @DisplayName( "Test filtering of VM (display) name configuration" ) + public void testFilterGenericName() throws FilterException + { + final FilterGenericName filter = new FilterGenericName(); + final Domain config = FilterTestUtils.getDefaultDomain(); + final CommandLineArgs args = FilterTestUtils.getDefaultCmdLnArgs(); + + assertNotEquals( FilterTestUtils.DEFAULT_VM_NAME, config.getName() ); + assertNotEquals( FilterTestUtils.DEFAULT_VM_DSPLNAME, config.getTitle() ); + + filter.filter( config, args ); + + assertEquals( FilterTestUtils.DEFAULT_VM_NAME, config.getName() ); + assertEquals( FilterTestUtils.DEFAULT_VM_DSPLNAME, config.getTitle() ); + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericUuidTest.java b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericUuidTest.java new file mode 100644 index 00000000..c206b0e9 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterGenericUuidTest.java @@ -0,0 +1,28 @@ +package org.openslx.runvirt.plugin.qemu.configuration; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.openslx.libvirt.domain.Domain; +import org.openslx.runvirt.configuration.FilterException; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs; + +public class FilterGenericUuidTest +{ + @Test + @DisplayName( "Test filtering of VM UUID configuration" ) + public void testFilterGenericUuid() throws FilterException + { + final FilterGenericUuid filter = new FilterGenericUuid(); + final Domain config = FilterTestUtils.getDefaultDomain(); + final CommandLineArgs args = FilterTestUtils.getDefaultCmdLnArgs(); + + assertNotEquals( FilterTestUtils.DEFAULT_VM_UUID, config.getUuid() ); + + filter.filter( config, args ); + + assertEquals( FilterTestUtils.DEFAULT_VM_UUID, config.getUuid() ); + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterTestResources.java b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterTestResources.java new file mode 100644 index 00000000..80fa2636 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterTestResources.java @@ -0,0 +1,17 @@ +package org.openslx.runvirt.plugin.qemu.configuration; + +import java.io.File; +import java.net.URL; + +public class FilterTestResources +{ + private static final String LIBVIRT_PREFIX_PATH = File.separator + "libvirt"; + private static final String LIBVIRT_PREFIX_PATH_XML = LIBVIRT_PREFIX_PATH + File.separator + "xml"; + + public static File getLibvirtXmlFile( String libvirtXmlFileName ) + { + String libvirtXmlPath = FilterTestResources.LIBVIRT_PREFIX_PATH_XML + File.separator + libvirtXmlFileName; + URL libvirtXml = FilterTestResources.class.getResource( libvirtXmlPath ); + return new File( libvirtXml.getFile() ); + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterTestUtils.java b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterTestUtils.java new file mode 100644 index 00000000..45abb025 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/FilterTestUtils.java @@ -0,0 +1,112 @@ +package org.openslx.runvirt.plugin.qemu.configuration; + +import static org.junit.jupiter.api.Assertions.fail; + +import org.openslx.libvirt.domain.Domain; +import org.openslx.libvirt.xml.LibvirtXmlDocumentException; +import org.openslx.libvirt.xml.LibvirtXmlSerializationException; +import org.openslx.libvirt.xml.LibvirtXmlValidationException; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs.CmdLnOption; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgsException; +import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgsTest; + +public class FilterTestUtils +{ + // @formatter:off + public static final String DEFAULT_VM_NAME = "archlinux"; + public static final String DEFAULT_VM_UUID = "4ec504d5-5eac-482f-a344-dbf1dd4956c8"; + public static final String DEFAULT_VM_DSPLNAME = "Archlinux"; + public static final String DEFAULT_VM_OS = "Windows 10 (x64)"; + public static final String DEFAULT_VM_NCPUS = "16"; + public static final String DEFAULT_VM_MEM = "1024"; + public static final String DEFAULT_VM_HDD0 = "/mnt/vm/windows.qcow2"; + public static final String DEFAULT_VM_FLOPPY0 = "/mnt/vm/floppy0.qcow2"; + public static final String DEFAULT_VM_FLOPPY1 = "/mnt/vm/floppy1.qcow2"; + public static final String DEFAULT_VM_CDROM0 = "/dev/sr0"; + public static final String DEFAULT_VM_CDROM1 = "/mnt/vm/cdrom1.qcow2"; + public static final String DEFAULT_VM_PARALLEL0 = "/dev/parport0"; + public static final String DEFAULT_VM_SERIAL0 = "/dev/ttyS0"; + public static final String DEFAULT_VM_MAC0 = "ca:06:29:84:f0:6d"; + public static final String DEFAULT_VM_FSSRC0 = "/mnt/shared/folder0"; + public static final String DEFAULT_VM_FSTGT0 = "folder0"; + public static final String DEFAULT_VM_FSSRC1 = "/mnt/shared/folder1"; + public static final String DEFAULT_VM_FSTGT1 = "folder1"; + // @formatter:on + + private static final String[] DEFAULT_CMDLN_ARGS = { + CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_NAME.getLongOption(), + FilterTestUtils.DEFAULT_VM_NAME, + CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_UUID.getLongOption(), + FilterTestUtils.DEFAULT_VM_UUID, + CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_DSPLNAME.getLongOption(), + FilterTestUtils.DEFAULT_VM_DSPLNAME, + CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_OS.getLongOption(), + FilterTestUtils.DEFAULT_VM_OS, + CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_NCPUS.getLongOption(), + FilterTestUtils.DEFAULT_VM_NCPUS, + CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_MEM.getLongOption(), + FilterTestUtils.DEFAULT_VM_MEM, + CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_HDD0.getLongOption(), + FilterTestUtils.DEFAULT_VM_HDD0, + CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_FLOPPY0.getLongOption(), + FilterTestUtils.DEFAULT_VM_FLOPPY0, + CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_FLOPPY1.getLongOption(), + FilterTestUtils.DEFAULT_VM_FLOPPY1, + CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_CDROM0.getLongOption(), + FilterTestUtils.DEFAULT_VM_CDROM0, + CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_CDROM1.getLongOption(), + FilterTestUtils.DEFAULT_VM_CDROM1, + CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_PARALLEL0.getLongOption(), + FilterTestUtils.DEFAULT_VM_PARALLEL0, + CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_SERIAL0.getLongOption(), + FilterTestUtils.DEFAULT_VM_SERIAL0, + CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_MAC0.getLongOption(), + FilterTestUtils.DEFAULT_VM_MAC0, + CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_FSSRC0.getLongOption(), + FilterTestUtils.DEFAULT_VM_FSSRC0, + CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_FSTGT0.getLongOption(), + FilterTestUtils.DEFAULT_VM_FSTGT0, + CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_FSSRC1.getLongOption(), + FilterTestUtils.DEFAULT_VM_FSSRC1, + CommandLineArgsTest.CMDLN_PREFIX_OPTION_LONG + CmdLnOption.VM_FSTGT1.getLongOption(), + FilterTestUtils.DEFAULT_VM_FSTGT1 + }; + + private static CommandLineArgs getCmdLnArgs( String[] args ) + { + final CommandLineArgs cmdLnArgs = new CommandLineArgs(); + + try { + cmdLnArgs.parseCmdLnArgs( args ); + } catch ( CommandLineArgsException e ) { + fail( e.getLocalizedMessage() ); + } + + return cmdLnArgs; + } + + public static CommandLineArgs getDefaultCmdLnArgs() + { + return FilterTestUtils.getCmdLnArgs( FilterTestUtils.DEFAULT_CMDLN_ARGS ); + } + + public static CommandLineArgs getEmptyCmdLnArgs() + { + return FilterTestUtils.getCmdLnArgs( new String[] {} ); + } + + public static Domain getDefaultDomain() + { + Domain domain = null; + + try { + domain = new Domain( FilterTestResources.getLibvirtXmlFile( "qemu-kvm_default-ubuntu-20-04-vm.xml" ) ); + } catch ( LibvirtXmlDocumentException | LibvirtXmlSerializationException | LibvirtXmlValidationException e ) { + fail( "Cannot prepare requested Libvirt domain XML file from the resources folder: " + + e.getLocalizedMessage() ); + } + + return domain; + } +} diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/resources/libvirt/xml/qemu-kvm_capabilities_default.xml b/core/modules/qemu/runvirt-plugin-qemu/src/test/resources/libvirt/xml/qemu-kvm_capabilities_default.xml new file mode 100644 index 00000000..4f2a94f2 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/test/resources/libvirt/xml/qemu-kvm_capabilities_default.xml @@ -0,0 +1,986 @@ + + + + 9b2f12af-1fba-444c-b72b-9cbc43fb3ca5 + + x86_64 + Skylake-Client-IBRS + Intel + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + tcp + rdma + + + + + + 16161320 + 4040330 + 0 + 0 + + + + + + + + + + + + + + + + + none + 0 + + + + + hvm + + 64 + /usr/bin/qemu-system-alpha + clipper + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-arm + integratorcp + ast2600-evb + borzoi + spitz + virt-2.7 + nuri + mcimx7d-sabre + romulus-bmc + virt-3.0 + virt-5.0 + npcm750-evb + virt-2.10 + musca-b1 + virt-2.8 + realview-pbx-a9 + versatileab + kzm + musca-a + virt-3.1 + mcimx6ul-evk + virt-5.1 + smdkc210 + sx1 + virt-2.11 + imx25-pdk + virt-2.9 + orangepi-pc + z2 + virt-5.2 + virt + xilinx-zynq-a9 + tosa + mps2-an500 + virt-2.12 + mps2-an521 + sabrelite + mps2-an511 + canon-a1100 + realview-eb + emcraft-sf2 + realview-pb-a8 + virt-4.0 + raspi1ap + palmetto-bmc + sx1-v1 + n810 + tacoma-bmc + n800 + virt-4.1 + quanta-gsj + versatilepb + terrier + mainstone + realview-eb-mpcore + supermicrox11-bmc + virt-4.2 + witherspoon-bmc + swift-bmc + vexpress-a9 + midway + musicpal + lm3s811evb + lm3s6965evb + microbit + mps2-an505 + mps2-an385 + cubieboard + verdex + netduino2 + mps2-an386 + raspi2b + raspi2 + vexpress-a15 + sonorapass-bmc + cheetah + virt-2.6 + ast2500-evb + highbank + akita + connex + netduinoplus2 + collie + raspi0 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-arm + integratorcp + ast2600-evb + borzoi + spitz + virt-2.7 + nuri + mcimx7d-sabre + romulus-bmc + virt-3.0 + virt-5.0 + npcm750-evb + virt-2.10 + musca-b1 + virt-2.8 + realview-pbx-a9 + versatileab + kzm + musca-a + virt-3.1 + mcimx6ul-evk + virt-5.1 + smdkc210 + sx1 + virt-2.11 + imx25-pdk + virt-2.9 + orangepi-pc + z2 + virt-5.2 + virt + xilinx-zynq-a9 + tosa + mps2-an500 + virt-2.12 + mps2-an521 + sabrelite + mps2-an511 + canon-a1100 + realview-eb + emcraft-sf2 + realview-pb-a8 + virt-4.0 + raspi1ap + palmetto-bmc + sx1-v1 + n810 + tacoma-bmc + n800 + virt-4.1 + quanta-gsj + versatilepb + terrier + mainstone + realview-eb-mpcore + supermicrox11-bmc + virt-4.2 + witherspoon-bmc + swift-bmc + vexpress-a9 + midway + musicpal + lm3s811evb + lm3s6965evb + microbit + mps2-an505 + mps2-an385 + cubieboard + verdex + netduino2 + mps2-an386 + raspi2b + raspi2 + vexpress-a15 + sonorapass-bmc + cheetah + virt-2.6 + ast2500-evb + highbank + akita + connex + netduinoplus2 + collie + raspi0 + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-aarch64 + integratorcp + ast2600-evb + borzoi + spitz + virt-2.7 + nuri + mcimx7d-sabre + romulus-bmc + virt-3.0 + virt-5.0 + npcm750-evb + virt-2.10 + musca-b1 + virt-2.8 + realview-pbx-a9 + versatileab + kzm + musca-a + virt-3.1 + mcimx6ul-evk + virt-5.1 + smdkc210 + sx1 + virt-2.11 + imx25-pdk + virt-2.9 + orangepi-pc + z2 + virt-5.2 + virt + xilinx-zynq-a9 + xlnx-zcu102 + tosa + mps2-an500 + virt-2.12 + mps2-an521 + sabrelite + mps2-an511 + canon-a1100 + realview-eb + emcraft-sf2 + realview-pb-a8 + sbsa-ref + virt-4.0 + raspi1ap + palmetto-bmc + sx1-v1 + n810 + tacoma-bmc + n800 + virt-4.1 + quanta-gsj + versatilepb + terrier + mainstone + realview-eb-mpcore + supermicrox11-bmc + virt-4.2 + witherspoon-bmc + swift-bmc + vexpress-a9 + midway + musicpal + lm3s811evb + lm3s6965evb + microbit + mps2-an505 + mps2-an385 + raspi3ap + cubieboard + verdex + netduino2 + xlnx-versal-virt + mps2-an386 + raspi3b + raspi3 + raspi2b + raspi2 + vexpress-a15 + sonorapass-bmc + cheetah + virt-2.6 + ast2500-evb + highbank + akita + connex + netduinoplus2 + collie + raspi0 + + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-cris + axis-dev88 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-i386 + pc-i440fx-5.2 + pc + pc-q35-5.2 + q35 + pc-i440fx-2.12 + pc-i440fx-2.0 + pc-q35-4.2 + pc-i440fx-2.5 + pc-i440fx-4.2 + pc-i440fx-1.5 + pc-q35-2.7 + pc-i440fx-2.2 + pc-1.1 + pc-i440fx-2.7 + pc-q35-2.4 + pc-q35-2.10 + pc-i440fx-1.7 + pc-q35-5.1 + pc-q35-2.9 + pc-i440fx-2.11 + pc-q35-3.1 + pc-q35-4.1 + pc-i440fx-2.4 + pc-1.3 + pc-i440fx-4.1 + pc-i440fx-5.1 + pc-i440fx-2.9 + isapc + pc-i440fx-1.4 + pc-q35-2.6 + pc-i440fx-3.1 + pc-q35-2.12 + pc-i440fx-2.1 + pc-1.0 + pc-i440fx-2.6 + pc-q35-4.0.1 + pc-i440fx-1.6 + pc-q35-5.0 + pc-q35-2.8 + pc-i440fx-2.10 + pc-q35-3.0 + pc-q35-4.0 + microvm + pc-i440fx-2.3 + pc-1.2 + pc-i440fx-4.0 + pc-i440fx-5.0 + pc-i440fx-2.8 + pc-q35-2.5 + pc-i440fx-3.0 + pc-q35-2.11 + + + + + + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-m68k + mcf5208evb + an5206 + q800 + next-cube + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-microblaze + petalogix-s3adsp1800 + petalogix-ml605 + xlnx-zynqmp-pmu + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-microblazeel + petalogix-s3adsp1800 + petalogix-ml605 + xlnx-zynqmp-pmu + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-mips + malta + mipssim + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-mipsel + malta + mipssim + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-mips64 + malta + pica61 + mipssim + magnum + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-mips64el + malta + mipssim + pica61 + magnum + boston + fuloong2e + fulong2e + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-ppc + g3beige + virtex-ml507 + mac99 + ppce500 + sam460ex + bamboo + 40p + ref405ep + mpc8544ds + taihu + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-ppc64 + pseries-5.2 + pseries + powernv9 + powernv + taihu + pseries-4.1 + mpc8544ds + pseries-2.5 + powernv10 + pseries-4.2 + pseries-2.6 + ppce500 + pseries-2.7 + pseries-3.0 + pseries-5.0 + 40p + pseries-2.8 + pseries-3.1 + pseries-5.1 + pseries-2.9 + bamboo + g3beige + pseries-2.12-sxxm + pseries-2.10 + virtex-ml507 + pseries-2.11 + pseries-2.1 + pseries-2.12 + pseries-2.2 + mac99 + sam460ex + ref405ep + pseries-2.3 + powernv8 + pseries-4.0 + pseries-2.4 + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-ppc64 + pseries-5.2 + pseries + powernv9 + powernv + taihu + pseries-4.1 + mpc8544ds + pseries-2.5 + powernv10 + pseries-4.2 + pseries-2.6 + ppce500 + pseries-2.7 + pseries-3.0 + pseries-5.0 + 40p + pseries-2.8 + pseries-3.1 + pseries-5.1 + pseries-2.9 + bamboo + g3beige + pseries-2.12-sxxm + pseries-2.10 + virtex-ml507 + pseries-2.11 + pseries-2.1 + pseries-2.12 + pseries-2.2 + mac99 + sam460ex + ref405ep + pseries-2.3 + powernv8 + pseries-4.0 + pseries-2.4 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-riscv32 + spike + virt + opentitan + sifive_e + sifive_u + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-riscv64 + spike + virt + sifive_e + sifive_u + microchip-icicle-kit + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-s390x + s390-ccw-virtio-5.2 + s390-ccw-virtio + s390-ccw-virtio-4.0 + s390-ccw-virtio-3.1 + s390-ccw-virtio-2.6 + s390-ccw-virtio-2.12 + s390-ccw-virtio-2.9 + s390-ccw-virtio-5.1 + s390-ccw-virtio-3.0 + s390-ccw-virtio-4.2 + s390-ccw-virtio-2.5 + s390-ccw-virtio-2.11 + s390-ccw-virtio-2.8 + s390-ccw-virtio-5.0 + s390-ccw-virtio-4.1 + s390-ccw-virtio-2.4 + s390-ccw-virtio-2.10 + s390-ccw-virtio-2.7 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-sh4 + shix + r2d + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-sh4eb + shix + r2d + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-sparc + SS-5 + SS-20 + LX + SPARCClassic + leon3_generic + SPARCbook + SS-4 + SS-600MP + SS-10 + Voyager + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-sparc64 + sun4u + niagara + sun4v + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-x86_64 + pc-i440fx-5.2 + pc + pc-q35-5.2 + q35 + pc-i440fx-2.12 + pc-i440fx-2.0 + pc-q35-4.2 + pc-i440fx-2.5 + pc-i440fx-4.2 + pc-i440fx-1.5 + pc-q35-2.7 + pc-i440fx-2.2 + pc-1.1 + pc-i440fx-2.7 + pc-q35-2.4 + pc-q35-2.10 + pc-i440fx-1.7 + pc-q35-5.1 + pc-q35-2.9 + pc-i440fx-2.11 + pc-q35-3.1 + pc-q35-4.1 + pc-i440fx-2.4 + pc-1.3 + pc-i440fx-4.1 + pc-i440fx-5.1 + pc-i440fx-2.9 + isapc + pc-i440fx-1.4 + pc-q35-2.6 + pc-i440fx-3.1 + pc-q35-2.12 + pc-i440fx-2.1 + pc-1.0 + pc-i440fx-2.6 + pc-q35-4.0.1 + pc-i440fx-1.6 + pc-q35-5.0 + pc-q35-2.8 + pc-i440fx-2.10 + pc-q35-3.0 + pc-q35-4.0 + microvm + pc-i440fx-2.3 + pc-1.2 + pc-i440fx-4.0 + pc-i440fx-5.0 + pc-i440fx-2.8 + pc-q35-2.5 + pc-i440fx-3.0 + pc-q35-2.11 + + + + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-xtensa + sim + kc705 + ml605 + ml605-nommu + virt + lx60-nommu + lx200 + lx200-nommu + lx60 + kc705-nommu + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-xtensaeb + sim + kc705 + ml605 + ml605-nommu + virt + lx60-nommu + lx200 + lx200-nommu + lx60 + kc705-nommu + + + + + + + + + + + + diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/resources/libvirt/xml/qemu-kvm_default-ubuntu-20-04-vm.xml b/core/modules/qemu/runvirt-plugin-qemu/src/test/resources/libvirt/xml/qemu-kvm_default-ubuntu-20-04-vm.xml new file mode 100644 index 00000000..241a6807 --- /dev/null +++ b/core/modules/qemu/runvirt-plugin-qemu/src/test/resources/libvirt/xml/qemu-kvm_default-ubuntu-20-04-vm.xml @@ -0,0 +1,164 @@ + + ubuntu-20-04 + 8dc5433c-0228-49e4-b019-fa2b606aa544 + Ubuntu 20.04 + Ubuntu 20.04 desktop installation + + + + + + 4194304 + 4194304 + 2 + + hvm + + + + + + + + + + + + + + destroy + restart + destroy + + + + + + /usr/bin/qemu-system-x86_64 + + + + +
+ + + + + +
+ + + + +
+ + +
+ + + +
+ + + +
+ + + +
+ + +
+ + + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + +
+ + +
+ + + + + + +
+ + + + + + + + + + + +
+ + + +
+ + +
+ + + + + + + + +
+ +