new vm location: /lmn/vm
This commit is contained in:
parent
bdbd4f8ce5
commit
8eb9748f93
4 changed files with 43 additions and 41 deletions
|
@ -3,7 +3,7 @@
|
|||
|
||||
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" >&2
|
||||
echo "Usage: $0 vm_name_orig vm_name_clone" >&2
|
||||
exit 1
|
||||
|
@ -11,16 +11,16 @@ fi
|
|||
|
||||
VM_NAME=$1
|
||||
VM_CLONE=$2
|
||||
VM_DIR="/tmp/${UID}/vmimages"
|
||||
VM_DIR="/tmp/${UID}/vm"
|
||||
|
||||
# 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
|
||||
|
||||
# change to image-directory
|
||||
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
|
||||
exit 1
|
||||
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"
|
||||
# copy machine-definition-file
|
||||
if [[ -f "xml/${VM_NAME}.xml" ]]; then
|
||||
cp "xml/${VM_NAME}.xml" "xml/${VM_NAME}-${VM_CLONE}.xml"
|
||||
elif [[ -f "/var/lib/libvirt/images/xml/${VM_NAME}.xml" ]]; then
|
||||
cp "/var/lib/libvirt/images/xml/${VM_NAME}.xml" "xml/${VM_NAME}-${VM_CLONE}.xml"
|
||||
if [[ -f "${VM_NAME}.xml" ]]; then
|
||||
cp "${VM_NAME}.xml" "${VM_NAME}-${VM_CLONE}.xml"
|
||||
elif [[ -f "/lmn/vm/${VM_NAME}.xml" ]]; then
|
||||
cp "/lmn/vm/${VM_NAME}.xml" "${VM_NAME}-${VM_CLONE}.xml"
|
||||
else
|
||||
echo "no machine definition file found" >&2
|
||||
exit 1
|
||||
|
@ -41,8 +41,8 @@ fi
|
|||
|
||||
# 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 "${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)
|
||||
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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue