new vm location: /lmn/vm
This commit is contained in:
parent
bdbd4f8ce5
commit
8eb9748f93
4 changed files with 43 additions and 41 deletions
|
@ -11,16 +11,16 @@ fi
|
||||||
|
|
||||||
VM_NAME=$1
|
VM_NAME=$1
|
||||||
VM_CLONE=$2
|
VM_CLONE=$2
|
||||||
VM_DIR="/tmp/${UID}/vmimages"
|
VM_DIR="/tmp/${UID}/vm"
|
||||||
|
|
||||||
# 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}" ]] || mkdir -p "${VM_DIR}"
|
||||||
sudo /usr/local/bin/link-images.sh
|
sudo /usr/local/bin/link-images.sh
|
||||||
|
|
||||||
# change to image-directory
|
# change to image-directory
|
||||||
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 "${VM_NAME}.xml" ]] && [[ ! -f "/lmn/vm/${VM_NAME}.xml" ]]; } || [[ ! -f "${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
|
||||||
|
@ -30,10 +30,10 @@ chmod a-w "${VM_NAME}-${VM_CLONE}.qcow2"
|
||||||
|
|
||||||
# virsh --connect=qemu:///system dumpxml "${VM_NAME}" > "xml/${VM_NAME}-${VM_CLONE}.xml"
|
# virsh --connect=qemu:///system dumpxml "${VM_NAME}" > "xml/${VM_NAME}-${VM_CLONE}.xml"
|
||||||
# copy machine-definition-file
|
# copy machine-definition-file
|
||||||
if [[ -f "xml/${VM_NAME}.xml" ]]; then
|
if [[ -f "${VM_NAME}.xml" ]]; then
|
||||||
cp "xml/${VM_NAME}.xml" "xml/${VM_NAME}-${VM_CLONE}.xml"
|
cp "${VM_NAME}.xml" "${VM_NAME}-${VM_CLONE}.xml"
|
||||||
elif [[ -f "/var/lib/libvirt/images/xml/${VM_NAME}.xml" ]]; then
|
elif [[ -f "/lmn/vm/${VM_NAME}.xml" ]]; then
|
||||||
cp "/var/lib/libvirt/images/xml/${VM_NAME}.xml" "xml/${VM_NAME}-${VM_CLONE}.xml"
|
cp "/lmn/vm/${VM_NAME}.xml" "${VM_NAME}-${VM_CLONE}.xml"
|
||||||
else
|
else
|
||||||
echo "no machine definition file found" >&2
|
echo "no machine definition file found" >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -41,8 +41,8 @@ fi
|
||||||
|
|
||||||
# hardware addresses need to be removed, libvirt will assign
|
# hardware addresses need to be removed, libvirt will assign
|
||||||
# new addresses automatically
|
# new addresses automatically
|
||||||
sed -i /uuid/d "xml/${VM_NAME}-${VM_CLONE}.xml"
|
sed -i /uuid/d "${VM_NAME}-${VM_CLONE}.xml"
|
||||||
sed -i '/mac address/d' "xml/${VM_NAME}-${VM_CLONE}.xml"
|
sed -i '/mac address/d' "${VM_NAME}-${VM_CLONE}.xml"
|
||||||
|
|
||||||
# and actually rename the vm: (this also updates the storage path)
|
# and actually rename the vm: (this also updates the storage path)
|
||||||
sed -i "s/${VM_NAME}/${VM_NAME}-${VM_CLONE}/" "xml/${VM_NAME}-${VM_CLONE}.xml"
|
sed -i "s/${VM_NAME}/${VM_NAME}-${VM_CLONE}/" "${VM_NAME}-${VM_CLONE}.xml"
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#!/usr/bin/bash
|
#!/usr/bin/bash
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
share="/srv/samba/schools/default-school/share/"
|
|
||||||
home="$(getent passwd "$SUDO_UID" | cut -d : -f 6 | sed 's|/srv/samba/schools/default-school/||')"
|
home="$(getent passwd "$SUDO_UID" | cut -d : -f 6 | sed 's|/srv/samba/schools/default-school/||')"
|
||||||
|
|
||||||
exit_script() {
|
exit_script() {
|
||||||
|
|
|
@ -31,7 +31,7 @@ if [[ $# -ne 1 ]]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# change to Images directory
|
# change to Images directory
|
||||||
VM_DIR="/tmp/${UID}/vmimages"
|
VM_DIR="/tmp/${UID}/vm"
|
||||||
cd "${VM_DIR}"
|
cd "${VM_DIR}"
|
||||||
|
|
||||||
VM_NAME="$1"
|
VM_NAME="$1"
|
||||||
|
@ -68,15 +68,15 @@ qemu-img rebase -f qcow2 -b "${NEWBASE}" -F qcow2 "${VM_NAME}.qcow2"
|
||||||
if [[ -v NEWNAME ]]; then
|
if [[ -v NEWNAME ]]; then
|
||||||
# copy and adapt machine definition file
|
# copy and adapt machine definition file
|
||||||
CURRENTNAME="${CURRENTBASE/.qcow2/}"
|
CURRENTNAME="${CURRENTBASE/.qcow2/}"
|
||||||
if [[ -f "xml/${CURRENTNAME}.xml" ]]; then
|
if [[ -f "${CURRENTNAME}.xml" ]]; then
|
||||||
cp "xml/${CURRENTNAME}.xml" "xml/${NEWNAME}.xml"
|
cp "${CURRENTNAME}.xml" "${NEWNAME}.xml"
|
||||||
elif [[ -f "/var/lib/libvirt/images/xml/${CURRENTNAME}.xml" ]]; then
|
elif [[ -f "/lmn/vm/${CURRENTNAME}.xml" ]]; then
|
||||||
cp "/var/lib/libvirt/images/xml/${CURRENTNAME}.xml" "xml/${NEWNAME}.xml"
|
cp "/lmn/vm/${CURRENTNAME}.xml" "${NEWNAME}.xml"
|
||||||
else
|
else
|
||||||
echo "no machine definition file found" >&2
|
echo "no machine definition file found" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
sed -i "s/${CURRENTNAME}/${NEWNAME}/" "xml/${NEWNAME}.xml"
|
sed -i "s/${CURRENTNAME}/${NEWNAME}/" "${NEWNAME}.xml"
|
||||||
NEWNAME="${NEWNAME}.qcow2"
|
NEWNAME="${NEWNAME}.qcow2"
|
||||||
else
|
else
|
||||||
rm "${CURRENTBASE}"
|
rm "${CURRENTBASE}"
|
||||||
|
|
|
@ -9,43 +9,46 @@ Create torrent and upload disk, torrent and xml-VM-Definiton on server.
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
VM_DIR="/tmp/${SUDO_UID}/vmimages"
|
VM_DIR="/tmp/${SUDO_UID}/vm"
|
||||||
|
|
||||||
upload_image() {
|
upload_image() {
|
||||||
# check if VM-Diskimage exists
|
# check if VM-Diskimage exists
|
||||||
if [[ ! (-f "/var/lib/libvirt/images/${VM_NAME}.qcow2" || -f "${VM_DIR}/${VM_NAME}.qcow2") ]]; then
|
if [[ ! (-f "/lmn/vm/${VM_NAME}.qcow2" || -f "${VM_DIR}/${VM_NAME}.qcow2") ]]; then
|
||||||
echo "File not found ${VM_NAME}.qcow2" >&2
|
echo "File not found ${VM_NAME}.qcow2" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
# link private VM-Diskimage to system-Dir
|
|
||||||
if [[ -f "${VM_DIR}/${VM_NAME}.qcow2" \
|
|
||||||
&& ( -f "/var/lib/libvirt/images/${VM_NAME}.qcow2" && ("${VM_DIR}/${VM_NAME}.qcow2" -nt "/var/lib/libvirt/images/${VM_NAME}.qcow2") \
|
|
||||||
|| ! -f "/var/lib/libvirt/images/${VM_NAME}.qcow2") ]]; then
|
|
||||||
echo "copy private VM-Diskimage to system-dir"
|
|
||||||
ln -f "${VM_DIR}/${VM_NAME}.qcow2" "/var/lib/libvirt/images/${VM_NAME}.qcow2"
|
|
||||||
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}.xml") ]]; then
|
if [[ ! (-f "/lmn/vm/${VM_NAME}.xml" || -f "${VM_DIR}/${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
|
||||||
# copy private VM-Maschine-Definition XML to system-Dir
|
sudo -u lmnsynci /usr/local/bin/vmimage-torrent stop "${VM_NAME}.qcow2"
|
||||||
if [[ -f "${VM_DIR}/xml/${VM_NAME}.xml" \
|
# link private VM-Diskimage to system-Dir
|
||||||
&& ( -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") \
|
if [[ -f "${VM_DIR}/${VM_NAME}.qcow2" \
|
||||||
|| ! -f "/var/lib/libvirt/images/xml/${VM_NAME}.xml") ]]; then
|
&& ( -f "/lmn/vm/${VM_NAME}.qcow2" && ("${VM_DIR}/${VM_NAME}.qcow2" -nt "/lmn/vm/${VM_NAME}.qcow2") \
|
||||||
echo "copy private VM-Maschine-Definition XML to system-dir"
|
|| ! -f "/lmn/vm/${VM_NAME}.qcow2") ]]; then
|
||||||
cp "${VM_DIR}/xml/${VM_NAME}.xml" "/var/lib/libvirt/images/xml/"
|
echo "copy private VM-Diskimage to system-dir"
|
||||||
|
chown lmnsynci:lmnsynci "${VM_DIR}/${VM_NAME}.qcow2"
|
||||||
|
ln -f "${VM_DIR}/${VM_NAME}.qcow2" "/lmn/vm/${VM_NAME}.qcow2"
|
||||||
fi
|
fi
|
||||||
cd /var/lib/libvirt/images
|
# copy private VM-Maschine-Definition XML to system-Dir
|
||||||
|
if [[ -f "${VM_DIR}/${VM_NAME}.xml" \
|
||||||
|
&& ( -f "/lmn/vm/${VM_NAME}.xml" && $(cmp -s "${VM_DIR}/${VM_NAME}.xml" "/lmn/vm/${VM_NAME}.xml") \
|
||||||
|
|| ! -f "/lmn/vm/${VM_NAME}.xml") ]]; then
|
||||||
|
echo "copy private VM-Maschine-Definition XML to system-dir"
|
||||||
|
chown lmnsynci:lmnsynci "${VM_DIR}/${VM_NAME}.xml"
|
||||||
|
cp -a "${VM_DIR}/${VM_NAME}.xml" "/lmn/vm/"
|
||||||
|
fi
|
||||||
|
cd /lmn/vm
|
||||||
# (re-) create torrent file
|
# (re-) create torrent file
|
||||||
/usr/local/bin/vmimage-torrent create "${VM_NAME}.qcow2"
|
sudo -u lmnsynci /usr/local/bin/vmimage-torrent create "${VM_NAME}.qcow2"
|
||||||
# Upload Torrent, qcow2 and machine-definition-XML
|
# Upload Torrent, qcow2 and machine-definition-XML
|
||||||
[[ -f "/var/lib/libvirt/images/${VM_NAME}.qcow2.torrent" ]] && rsync -av --password-file=/etc/rsync.secret \
|
[[ -f "/lmn/vm/${VM_NAME}.qcow2.torrent" ]] && rsync -av --password-file=/etc/rsync.secret \
|
||||||
"/var/lib/libvirt/images/${VM_NAME}.qcow2.torrent" rsync://vmuser@server:/vmimages-upload/
|
"/lmn/vm/${VM_NAME}.qcow2.torrent" rsync://vmuser@server:/vmimages-upload/
|
||||||
rsync -av --password-file=/etc/rsync.secret "/var/lib/libvirt/images/${VM_NAME}.qcow2" \
|
rsync -av --password-file=/etc/rsync.secret "/lmn/vm/${VM_NAME}.qcow2" \
|
||||||
|
rsync://vmuser@server:/vmimages-upload/
|
||||||
|
rsync -av --password-file=/etc/rsync.secret "/lmn/vm/${VM_NAME}.xml" \
|
||||||
rsync://vmuser@server:/vmimages-upload/
|
rsync://vmuser@server:/vmimages-upload/
|
||||||
rsync -av --password-file=/etc/rsync.secret "/var/lib/libvirt/images/xml/${VM_NAME}.xml" \
|
|
||||||
rsync://vmuser@server:/vmimages-upload/xml/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# if less than one arguments supplied, display usage
|
# if less than one arguments supplied, display usage
|
||||||
|
|
Loading…
Add table
Reference in a new issue