distribute VM-images with aria2 instead of ctorrent
This commit is contained in:
parent
e30a7032a5
commit
40962fd9de
23 changed files with 444 additions and 434 deletions
70
roles/lmn_vm/files/vm-upload
Executable file
70
roles/lmn_vm/files/vm-upload
Executable file
|
@ -0,0 +1,70 @@
|
|||
#!/usr/bin/bash
|
||||
# Push VM-Disk-Image on server
|
||||
set -eu
|
||||
|
||||
show_help() {
|
||||
cat << EOF >&2
|
||||
Usage: $(basename "$0") vmname"
|
||||
Create torrent and upload disk and xml-VM-Definiton on server.
|
||||
EOF
|
||||
}
|
||||
|
||||
|
||||
upload_image() {
|
||||
# check if VM-Diskimage exists
|
||||
if [[ ! (-f "${VM_SYSDIR}/${VM_NAME}.qcow2" || -f "${VM_DIR}/${VM_NAME}.qcow2") ]]; then
|
||||
echo "File not found ${VM_NAME}.qcow2" >&2
|
||||
exit 1
|
||||
fi
|
||||
# check if VM-Machine-Definition XML exists
|
||||
if [[ ! (-f "${VM_SYSDIR}/${VM_NAME}.xml" || -f "${VM_DIR}/${VM_NAME}.xml") ]]; then
|
||||
echo "File not found ${VM_NAME}.xml" >&2
|
||||
exit 1
|
||||
fi
|
||||
sudo vm-aria2 stop "${VM_NAME}" || echo "VMImage-torrent not running"
|
||||
# link private VM-Diskimage to system-Dir
|
||||
if [[ -f "${VM_DIR}/${VM_NAME}.qcow2" \
|
||||
&& ( -f "${VM_SYSDIR}/${VM_NAME}.qcow2" && ("${VM_DIR}/${VM_NAME}.qcow2" -nt "${VM_SYSDIR}/${VM_NAME}.qcow2") \
|
||||
|| ! -f "${VM_SYSDIR}/${VM_NAME}.qcow2") ]]; then
|
||||
echo "copy private VM-Diskimage to system-dir"
|
||||
chown lmnsynci:lmnsynci "${VM_DIR}/${VM_NAME}.qcow2"
|
||||
ln -f "${VM_DIR}/${VM_NAME}.qcow2" "${VM_SYSDIR}/${VM_NAME}.qcow2"
|
||||
fi
|
||||
# copy private VM-Maschine-Definition XML to system-Dir
|
||||
if [[ -f "${VM_DIR}/${VM_NAME}.xml" \
|
||||
&& ( -f "${VM_SYSDIR}/${VM_NAME}.xml" && $(cmp -s "${VM_DIR}/${VM_NAME}.xml" "${VM_SYSDIR}/${VM_NAME}.xml") \
|
||||
|| ! -f "${VM_SYSDIR}/${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" "${VM_SYSDIR}"
|
||||
fi
|
||||
cd "${VM_SYSDIR}"
|
||||
uploadseed --rpc-server "${SEEDBOX_HOST}:${SEEDBOX_RPC_PORT}" --dht-port "${SEEDBOX_PORT}" --rpc-secret insecure --no-cert "${VM_NAME}.qcow2"
|
||||
uploadseed --rpc-server "${SEEDBOX_HOST}:${SEEDBOX_RPC_PORT}" --dht-port "${SEEDBOX_PORT}" --rpc-secret insecure --no-cert "${VM_NAME}.xml"
|
||||
}
|
||||
|
||||
source /etc/lmn/vm.conf
|
||||
|
||||
while getopts ':p' OPTION; do
|
||||
case "$OPTION" in
|
||||
p)
|
||||
VM_DIR="${VM_DIR_PERSISTENT}"
|
||||
;;
|
||||
?)
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift "$((OPTIND -1))"
|
||||
|
||||
# if less than one arguments supplied, display usage
|
||||
if [[ $# -ne 1 ]] ; then
|
||||
show_help
|
||||
exit 1
|
||||
fi
|
||||
|
||||
VM_NAME=$1
|
||||
|
||||
upload_image
|
Loading…
Add table
Add a link
Reference in a new issue