meta data for this page
  •  

Fizikai diszkek tömeges mappelése VM(ek)hez

Input fájl szintaxis:

#VM_NÉV   DISZK_NÉV
ovm_map_phys_disks.sh
#!/bin/bash
. ovm_functions.sh
kulcs_ellenorzes
 
trap ctrl_c INT
 
function ctrl_c() {
        echo -e $end
        exit
}
 
[[ -e $1 ]] || { echo "Add meg a konfig fajlt parameterkent."; exit 1; }
while read LINE; do
    VDISK_NAME=$(echo $LINE | cut -d' ' -f 1)
    VM_NAMES=$(echo $LINE | cut -d' ' -f 2 | sed 's/,/ /g')
    echo "$(env printf '\u250F') A(z) ${yel}$VDISK_NAME${end} hozzarendelese a..."
    for VM_NAME in $VM_NAMES; do
        VM_ID=$(ovm_exec "show vm name=\"$VM_NAME\"" "Id")
        SLOT=$(ovm_cli "show vm id=\"$VM_ID\"" | grep -oP "VmDiskMapping.*(?==)" | awk 'END{print $NF}')
        echo -e "$(env printf '\u2523')$(env printf '\u2501')> ${grn}$VM_NAME${end} VM ${grn}$SLOT${end}. slotjahoz"
        printf "$(env printf '\u2503') Ha ez nem stimmel, nyomj egy CTRL+C -t 10mp-en belül!${red}"
        countdown
        echo -e $end
        VDISK_MAP1=$(ovm_exec "create VmDiskMapping slot=$SLOT physicalDisk=\"$VDISK_NAME\" name=\"${VDISK_NAME}_to_${VM_NAME}\" on Vm id=\"$VM_ID\"" "Status")
        [[ "$VDISK_MAP1" == 'Success' ]] && color="${grn}" || color="${red}"
        [[ -z $VDISK_MAP1 ]] && { echo -e "$(env printf '\u2503') ${red}create VmDiskMapping HIBA!${end}"; continue; } || echo "$(env printf '\u2503') Vdisk mapping: ${color}$VDISK_MAP1 ${end}"
 
        echo "$(env printf '\u2517') A $VM_NAME kesz."
    done
done <<< "`cat $1 | grep -v '^#' | sed 's/[[:space:]]\+/ /g' | tr -s '[:blank:]'`"