New scripts and sudo rules. Implement qemu session mode.

This commit is contained in:
Andreas B. Mundt 2023-04-04 13:29:00 +02:00
parent 91aab8e75b
commit 7871936a67
19 changed files with 176 additions and 67 deletions

View file

@ -4,8 +4,8 @@
set -eu
# if less than two arguments supplied, display usage
if [[ $# -ne 2 ]]; then
echo "This script takes as input the name of the VM to clone"
echo "Usage: $0 vm_name_orig vm_name_clone"
echo "This script takes as input the name of the VM to clone" >&2
echo "Usage: $0 vm_name_orig vm_name_clone" >&2
exit 1
fi
@ -13,10 +13,11 @@ VM_NAME=$1
VM_CLONE=$2
# change to image-directory
cd /var/lib/libvirt/images
VM_DIR="/tmp/${UID}/vmimages"
cd "${VM_DIR}"
if [[ ! -f "xml/${VM_NAME}.xml" ]] || [[ ! -f "${VM_NAME}.gcow2" ]]; then
echo "xml or qcow2 File does not exists."
if { [[ ! -f "xml/${VM_NAME}.xml" ]] && [[ ! -f "/var/lib/libvirt/images/xml/${VM_NAME}.xml" ]]; } || [[ ! -f "${VM_NAME}.qcow2" ]]; then
echo "xml or qcow2 File does not exists." >&2
exit 1
fi
@ -24,7 +25,15 @@ qemu-img create -f qcow2 -F qcow2 -b "${VM_NAME}.qcow2" "${VM_NAME}-${VM_CLONE}.
chmod a-w "${VM_NAME}-${VM_CLONE}.qcow2"
# virsh --connect=qemu:///system dumpxml "${VM_NAME}" > "xml/${VM_NAME}-${VM_CLONE}.xml"
cp "xml/${VM_NAME}.xml" "xml/${VM_NAME}-${VM_CLONE}.xml"
# copy machine-definition-file
if [[ -f "xml/${VM_NAME}.xml" ]]; then
cp "xml/${VM_NAME}.xml" "xml/${VM_NAME}-${VM_CLONE}.xml"
elif [[ -f "/var/lib/libvirt/images/xml/${VM_NAME}.xml" ]]; then
cp "/var/lib/libvirt/images/xml/${VM_NAME}.xml" "xml/${VM_NAME}-${VM_CLONE}.xml"
else
echo "no machine definition file found" >&2
exit 1
fi
# hardware addresses need to be removed, libvirt will assign
# new addresses automatically