shell syntax optimized and more options for rebase-vm.sh
This commit is contained in:
parent
c1ff7319f4
commit
354075f530
7 changed files with 79 additions and 40 deletions
|
@ -2,10 +2,8 @@
|
|||
# create 1st level-Clones
|
||||
|
||||
set -eu
|
||||
|
||||
# if less than two arguments supplied, display usage
|
||||
if [ $# -ne 2 ]
|
||||
then
|
||||
if [[ $# -ne 2 ]]; then
|
||||
echo "This script takes as input the name of the VM to clone"
|
||||
echo "Usage: $0 vm_name_orig vm_name_clone"
|
||||
exit 1
|
||||
|
@ -14,21 +12,24 @@ fi
|
|||
VM_NAME=$1
|
||||
VM_CLONE=$2
|
||||
|
||||
if [ ! -f "xml/$VM_NAME.xml" -a -f "$VM_NAME.gcow2" ]; then
|
||||
# change to image-directory
|
||||
cd /var/lib/libvirt/images
|
||||
|
||||
if [[ ! -f "xml/${VM_NAME}.xml" ]] || [[ ! -f "${VM_NAME}.gcow2" ]]; then
|
||||
echo "xml or qcow2 File does not exists."
|
||||
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
|
||||
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
|
||||
cp xml/$VM_NAME.xml xml/$VM_NAME-$VM_CLONE.xml
|
||||
# virsh --connect=qemu:///system dumpxml "${VM_NAME}" > "xml/${VM_NAME}-${VM_CLONE}.xml"
|
||||
cp "xml/${VM_NAME}.xml" "xml/${VM_NAME}-${VM_CLONE}.xml"
|
||||
|
||||
# hardware addresses need to be removed, libvirt will assign
|
||||
# new addresses automatically
|
||||
sed -i /uuid/d xml/$VM_NAME-$VM_CLONE.xml
|
||||
sed -i '/mac address/d' xml/$VM_NAME-$VM_CLONE.xml
|
||||
sed -i /uuid/d "xml/${VM_NAME}-${VM_CLONE}.xml"
|
||||
sed -i '/mac address/d' "xml/${VM_NAME}-${VM_CLONE}.xml"
|
||||
|
||||
# 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}/" "xml/${VM_NAME}-${VM_CLONE}.xml"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue