Implement VM configuration and deploy the images.
This commit is contained in:
parent
396a91fb40
commit
18928f2818
14 changed files with 315 additions and 9 deletions
44
roles/lmn_vm/files/rebase-vm.sh
Executable file
44
roles/lmn_vm/files/rebase-vm.sh
Executable file
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/bash
|
||||
|
||||
# Rebase one level down
|
||||
|
||||
set -eu
|
||||
|
||||
# if less than one arguments supplied, display usage
|
||||
if [ $# -ne 1 ]
|
||||
then
|
||||
echo "This script takes as input the name of the VM to rebase one level down"
|
||||
echo "Usage: $0 vm_name"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
VM_NAME=$1
|
||||
|
||||
if [ ! -f $VM_NAME.qcow2 ]
|
||||
then
|
||||
echo "File not found $VM_NAME.qcow2"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
shopt -s lastpipe
|
||||
qemu-img info --backing-chain $VM_NAME.qcow2 | grep image | wc -l | read NUMBASES
|
||||
qemu-img info --backing-chain $VM_NAME.qcow2 | grep image | head -n 3 | tail -n 1 | cut -d' ' -f2 | read NEWBASE
|
||||
qemu-img info --backing-chain $VM_NAME.qcow2 | grep image | head -n 2 | tail -n 1 | cut -d' ' -f2 | read CURRENTBASE
|
||||
|
||||
if [ ! $NUMBASES -ge 3 ]
|
||||
then
|
||||
echo "Image must have at least 2 backing-files"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f $NEWBASE -a -f $CURRENTBASE ]
|
||||
then
|
||||
echo "Backingfiles not found $CURRENTBASE, $NEWBASE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
qemu-img rebase -f qcow2 -b $NEWBASE -F qcow2 $VM_NAME.qcow2
|
||||
rm $CURRENTBASE
|
||||
mv $VM_NAME.qcow2 $CURRENTBASE
|
||||
chmod a-w $CURRENTBASE
|
||||
qemu-img create -f qcow2 -F qcow2 -b $CURRENTBASE $VM_NAME.qcow2
|
Loading…
Add table
Add a link
Reference in a new issue