#!/bin/bash # # Human Readable Backup dump for oVirt # O="${1:-vm.tab.txt}" echo "Output file: $O" read -s -p "oVirt admin password: " OVIPASS echo . # write temporary home for configfile OVIHTMP=`mktemp -d` chmod 700 $OVIHTMP trap "rm -rf $OVIHTMP" INT TERM EXIT # dbg: for cache #OVIHTMP=/tmp/ovishtmp #mkdir -p $OVIHTMP cat >"$OVIHTMP/.ovirtshellrc" < "$OVIHTMP/vms.tab" wc -l "$OVIHTMP/vms.tab" | sed 's/ .*$/ in total/' echo -n "Discovering networks ... " ovish list networks | stab > "$OVIHTMP/nets.tab" wc -l "$OVIHTMP/nets.tab" | sed 's/ .*$/ in total/' printf "=====================================================================================================================\n" >"$O" printf "| V I R T U A L M A C H I N E P R O P S | A T T A C H E D D I S K S | N E T W O R K S |\n" >>"$O" printf "|===================================================================================================================|\n" >>"$O" while IFS='|' read VM_GUID VM_NAME VM_DESC do echo "Processing VM $VM_NAME ... " ovish show vm $VM_GUID | atab >"$OVIHTMP/vm.$VM_GUID.tab" DISKS= ovish list disks --vm-identifier $VM_GUID | stab > "$OVIHTMP/vm.$VM_GUID.disks.tab" while IFS='|' read DISK_GUID DISK_NAME DISK_OTHER do ovish show disk $DISK_GUID --vm-identifier $VM_GUID | atab >"$OVIHTMP/vm.$VM_GUID.disk.$DISK_GUID.tab" DISKS="$DISKS $DISK_GUID" done < "$OVIHTMP/vm.$VM_GUID.disks.tab" NICS= ovish list nics --vm-identifier $VM_GUID | stab > "$OVIHTMP/vm.$VM_GUID.nics.tab" while IFS='|' read NIC_GUID NIC_NAME NIC_OTHER do ovish show nic $NIC_GUID --vm-identifier $VM_GUID | atab >"$OVIHTMP/vm.$VM_GUID.nic.$NIC_GUID.tab" NICS="$NICS $NIC_GUID" done < "$OVIHTMP/vm.$VM_GUID.nics.tab" VCPU_CORES=`afield "$OVIHTMP/vm.$VM_GUID.tab" cpu-topology-cores` VCPU_SOCKETS=`afield "$OVIHTMP/vm.$VM_GUID.tab" cpu-topology-sockets` VM_VCPUS=$(( VCPU_CORES * VCPU_SOCKETS )) VM_MEM=`afield "$OVIHTMP/vm.$VM_GUID.tab" memory` VM_BAL=`afield "$OVIHTMP/vm.$VM_GUID.tab" memory_policy-guaranteed` VM_MEM=$(( VM_MEM / 1024 / 1024 )) VM_BAL=$(( VM_BAL / 1024 / 1024 )) VM_OSTYPE="`afield "$OVIHTMP/vm.$VM_GUID.tab" os-type`" unset DISK{1,2,3}_{NAME,INTF,LUN,IMG,TYPE} unset NIC{1,2,3}_{NAME,MAC,INTF,NETID,NET} d=0 for DISK_GUID in $DISKS do let d++ DISK_NAME=`afield "$OVIHTMP/vm.$VM_GUID.disk.$DISK_GUID.tab" name` DISK_INTF=`afield "$OVIHTMP/vm.$VM_GUID.disk.$DISK_GUID.tab" interface` DISK_LUN=`afield "$OVIHTMP/vm.$VM_GUID.disk.$DISK_GUID.tab" lun_storage-id` DISK_IMG=`afield "$OVIHTMP/vm.$VM_GUID.disk.$DISK_GUID.tab" image_id` [ -z "$DISK_LUN" ] && DISK_TYPE="LVM LV" || DISK_TYPE="Direct LUN" eval "DISK${d}_NAME=\"$DISK_NAME\"" eval "DISK${d}_INTF=\"$DISK_INTF\"" eval "DISK${d}_TYPE=\"$DISK_TYPE\"" eval "DISK${d}_ID=\"${DISK_LUN}${DISK_IMG}\"" done n=0 for NIC_GUID in $NICS do let n++ NIC_NAME=`afield "$OVIHTMP/vm.$VM_GUID.nic.$NIC_GUID.tab" name` NIC_MAC=`afield "$OVIHTMP/vm.$VM_GUID.nic.$NIC_GUID.tab" mac-address` NIC_INTF=`afield "$OVIHTMP/vm.$VM_GUID.nic.$NIC_GUID.tab" interface` NIC_NETID=`afield "$OVIHTMP/vm.$VM_GUID.nic.$NIC_GUID.tab" network-id` NIC_NET=`afield "$OVIHTMP/nets.tab" $NIC_NETID` eval "NIC${n}_NAME=\"$NIC_NAME\"" eval "NIC${n}_MAC=\"$NIC_MAC\"" eval "NIC${n}_INTF=\"$NIC_INTF\"" eval "NIC${n}_NET=\"$NIC_NET\"" done printf "| %-40s | %d vCPU | %-36s | %-10s %9s |\n" "$VM_NAME" $VM_VCPUS "$DISK1_NAME" "$NIC1_NAME" "$NIC1_INTF" >>"$O" printf "| %-40s | %dc x %ds | %-20s %15s | %-20s |\n" "$VM_DESC" $VCPU_CORES $VCPU_SOCKETS "$DISK1_TYPE" "$DISK1_INTF" "$NIC1_MAC" >>"$O" printf "|------------------------------------------| %4d GiB | %-36s | %-20s |\n" $VM_MEM "$DISK1_ID" "$NIC1_NET" >>"$O" printf "| %-25s | Balloon %3d%% : %4d GiB | %-36s | %-20s |\n" "$VM_OSTYPE" $(( VM_BAL * 100 / VM_MEM )) $VM_BAL "" "" >>"$O" if [ $d -gt 1 -o $n -gt 1 ] then printf "|-----------------------------------------------------|--------------------------------------|----------------------|\n" >>"$O" printf "| %-51s | %-36s | %-10s %9s |\n" "$d disks" "$DISK2_NAME" "$NIC2_NAME" "$NIC2_INTF" >>"$O" printf "| %-51s | %-20s %15s | %-20s |\n" "$n NICs" "$DISK2_TYPE" "$DISK2_INTF" "$NIC2_MAC" >>"$O" printf "| %-51s | %-36s | %-20s |\n" "" "$DISK2_ID" "$NIC2_NET" >>"$O" printf "| %-51s | %-36s | %-20s |\n" "" "" "" >>"$O" fi if [ $d -gt 2 -o $n -gt 2 ] then printf "| |--------------------------------------|----------------------|\n" >>"$O" printf "| %-51s | %-36s | %-10s %9s |\n" "" "$DISK3_NAME" "$NIC3_NAME" "$NIC3_INTF" >>"$O" printf "| %-51s | %-20s %15s | %-20s |\n" "" "$DISK3_TYPE" "$DISK3_INTF" "$NIC3_MAC" >>"$O" printf "| %-51s | %-36s | %-20s |\n" "" "$DISK3_ID" "$NIC3_NET" >>"$O" printf "| %-51s | %-36s | %-20s |\n" "" "" "" >>"$O" fi printf "|===================================================================================================================|\n" >>"$O" done < "$OVIHTMP/vms.tab"