fixed bugs
This commit is contained in:
parent
4e5eebe367
commit
983e915090
4 changed files with 20 additions and 9 deletions
|
@ -14,15 +14,14 @@ fi
|
||||||
cd /var/lib/libvirt/images
|
cd /var/lib/libvirt/images
|
||||||
|
|
||||||
VM_NAME=$1
|
VM_NAME=$1
|
||||||
|
VM_DIR="/tmp/${UID}/vmimages"
|
||||||
|
VM_XML="${VM_DIR}/xml/${VM_NAME}-clone.xml"
|
||||||
|
|
||||||
if [[ ! -f "xml/${VM_NAME}.xml" ]] || [[ ! -f "${VM_NAME}.qcow2" ]]; then
|
if ! [[ -f "xml/${VM_NAME}.xml" && -f "${VM_NAME}.qcow2" ]] && ! [[ -f "${VM_DIR}/xml/${VM_NAME}.xml" && -f "${VM_DIR}/${VM_NAME}.qcow2" ]]; then
|
||||||
echo "xml or qcow2 File does not exists." >&2
|
echo "xml or qcow2 File does not exists." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
VM_DIR="/tmp/${UID}/vmimages"
|
|
||||||
VM_XML="${VM_DIR}/xml/${VM_NAME}-clone.xml"
|
|
||||||
|
|
||||||
# Create User-VM-Dir and link system VM-Images
|
# Create User-VM-Dir and link system VM-Images
|
||||||
[[ -d "${VM_DIR}/xml" ]] || mkdir -p "${VM_DIR}/xml"
|
[[ -d "${VM_DIR}/xml" ]] || mkdir -p "${VM_DIR}/xml"
|
||||||
sudo /usr/local/bin/link-images.sh
|
sudo /usr/local/bin/link-images.sh
|
||||||
|
@ -32,7 +31,7 @@ cd "${VM_DIR}"
|
||||||
qemu-img create -f qcow2 -F qcow2 -b "${VM_NAME}.qcow2" "${VM_NAME}-clone.qcow2"
|
qemu-img create -f qcow2 -F qcow2 -b "${VM_NAME}.qcow2" "${VM_NAME}-clone.qcow2"
|
||||||
|
|
||||||
# Create machine-definition-file
|
# Create machine-definition-file
|
||||||
cp "/var/lib/libvirt/images/xml/${VM_NAME}.xml" "${VM_XML}"
|
cp "${VM_DIR}/xml/${VM_NAME}.xml" "${VM_XML}"
|
||||||
|
|
||||||
# set VM_DIR:
|
# set VM_DIR:
|
||||||
sed -i "s:VMIMAGEDIR:${VM_DIR}:" "${VM_XML}"
|
sed -i "s:VMIMAGEDIR:${VM_DIR}:" "${VM_XML}"
|
||||||
|
|
|
@ -11,9 +11,13 @@ fi
|
||||||
|
|
||||||
VM_NAME=$1
|
VM_NAME=$1
|
||||||
VM_CLONE=$2
|
VM_CLONE=$2
|
||||||
|
VM_DIR="/tmp/${UID}/vmimages"
|
||||||
|
|
||||||
|
# Create User-VM-Dir and link system VM-Images
|
||||||
|
[[ -d "${VM_DIR}/xml" ]] || mkdir -p "${VM_DIR}/xml"
|
||||||
|
sudo /usr/local/bin/link-images.sh
|
||||||
|
|
||||||
# change to image-directory
|
# change to image-directory
|
||||||
VM_DIR="/tmp/${UID}/vmimages"
|
|
||||||
cd "${VM_DIR}"
|
cd "${VM_DIR}"
|
||||||
|
|
||||||
if { [[ ! -f "xml/${VM_NAME}.xml" ]] && [[ ! -f "/var/lib/libvirt/images/xml/${VM_NAME}.xml" ]]; } || [[ ! -f "${VM_NAME}.qcow2" ]]; then
|
if { [[ ! -f "xml/${VM_NAME}.xml" ]] && [[ ! -f "/var/lib/libvirt/images/xml/${VM_NAME}.xml" ]]; } || [[ ! -f "${VM_NAME}.qcow2" ]]; then
|
||||||
|
|
|
@ -12,3 +12,11 @@ VM_DIR="/tmp/${SUDO_UID}/vmimages"
|
||||||
for i in *.qcow2; do
|
for i in *.qcow2; do
|
||||||
[[ -f "${VM_DIR}/${i}" ]] || ln "${i}" "${VM_DIR}/${i}"
|
[[ -f "${VM_DIR}/${i}" ]] || ln "${i}" "${VM_DIR}/${i}"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# change to image-directory
|
||||||
|
cd /var/lib/libvirt/images/xml
|
||||||
|
|
||||||
|
# link system-VM-Machine-Definitions to User VM Directory
|
||||||
|
for i in *.xml; do
|
||||||
|
[[ -f "${VM_DIR}/xml/${i}" ]] || ln "${i}" "${VM_DIR}/xml/${i}"
|
||||||
|
done
|
||||||
|
|
|
@ -27,7 +27,7 @@ upload_image() {
|
||||||
ln -f "${VM_DIR}/${VM_NAME}.qcow2" "/var/lib/libvirt/images/${VM_NAME}.qcow2"
|
ln -f "${VM_DIR}/${VM_NAME}.qcow2" "/var/lib/libvirt/images/${VM_NAME}.qcow2"
|
||||||
fi
|
fi
|
||||||
# check if VM-Machine-Definition XML exists
|
# check if VM-Machine-Definition XML exists
|
||||||
if [[ ! (-f "/var/lib/libvirt/images/xml/${VM_NAME}.xml" || -f "${VM_DIR}/xml/${VM_NAME}") ]]; then
|
if [[ ! (-f "/var/lib/libvirt/images/xml/${VM_NAME}.xml" || -f "${VM_DIR}/xml/${VM_NAME}.xml") ]]; then
|
||||||
echo "File not found ${VM_NAME}.xml" >&2
|
echo "File not found ${VM_NAME}.xml" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -36,7 +36,7 @@ upload_image() {
|
||||||
&& ( -f "/var/lib/libvirt/images/xml/${VM_NAME}.xml" && $(cmp -s "${VM_DIR}/xml/${VM_NAME}.xml" "/var/lib/libvirt/images/xml/${VM_NAME}.xml") \
|
&& ( -f "/var/lib/libvirt/images/xml/${VM_NAME}.xml" && $(cmp -s "${VM_DIR}/xml/${VM_NAME}.xml" "/var/lib/libvirt/images/xml/${VM_NAME}.xml") \
|
||||||
|| ! -f "/var/lib/libvirt/images/xml/${VM_NAME}.xml") ]]; then
|
|| ! -f "/var/lib/libvirt/images/xml/${VM_NAME}.xml") ]]; then
|
||||||
echo "copy private VM-Maschine-Definition XML to system-dir"
|
echo "copy private VM-Maschine-Definition XML to system-dir"
|
||||||
cp "${VM_DIR}/${VM_NAME}.xml" "/var/lib/libvirt/images/${VM_NAME}.xml"
|
cp "${VM_DIR}/xml/${VM_NAME}.xml" "/var/lib/libvirt/images/xml/"
|
||||||
fi
|
fi
|
||||||
# (re-) create torrent file
|
# (re-) create torrent file
|
||||||
/usr/local/bin/vmimage-torrent create "${VM_NAME}.qcow2"
|
/usr/local/bin/vmimage-torrent create "${VM_NAME}.qcow2"
|
||||||
|
|
Loading…
Add table
Reference in a new issue