create VMs without xml machine file

This commit is contained in:
Raphael Dannecker 2024-01-24 10:02:03 +01:00
parent 5a2ae0d33c
commit b5bb3c9fa6
5 changed files with 102 additions and 97 deletions

View file

@ -38,29 +38,10 @@ fi
# change to image-directory
cd "${VM_DIR}"
if { [[ ! -f "${VM_NAME}.xml" ]] && [[ ! -f "${VM_SYSDIR}/${VM_NAME}.xml" ]]; } || [[ ! -f "${VM_NAME}.qcow2" ]]; then
echo "xml or qcow2 File does not exists." >&2
if [[ ! -f "${VM_NAME}.qcow2" ]]; then
echo "qcow2 File does not exists." >&2
exit 1
fi
qemu-img create -f qcow2 -F qcow2 -b "${VM_NAME}.qcow2" "${VM_NAME}-${VM_CLONE}.qcow2"
chmod a-w "${VM_NAME}-${VM_CLONE}.qcow2"
# virsh --connect=qemu:///system dumpxml "${VM_NAME}" > "xml/${VM_NAME}-${VM_CLONE}.xml"
# copy machine-definition-file
if [[ -f "${VM_NAME}.xml" ]]; then
cp "${VM_NAME}.xml" "${VM_NAME}-${VM_CLONE}.xml"
elif [[ -f "${VM_SYSDIR}/${VM_NAME}.xml" ]]; then
cp "${VM_SYSDIR}/${VM_NAME}.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
# and actually rename the vm: (this also updates the storage path)
sed -i -E \
-e '/<uuid>.+<\/uuid>/d' \
-e '/.+mac address.+[[:xdigit:]:]{17}.+/d' \
-e "s/${VM_NAME}/${VM_NAME}-${VM_CLONE}/" "${VM_NAME}-${VM_CLONE}.xml"