meta data for this page
  •  

Fizikai diszkeket átnevező szkript

ovm_rename_phys_disk.sh
#!/bin/bash
## bemeneti fajl szintaxis:
# DISK_UUID  DISK_NAME  SHAREABLE
# 6005076802820058A000000000000000        diszk_név  No [host1,host2,host3 - opcionális]
. ovm_functions.sh
kulcs_ellenorzes
TMP_FILE=/tmp/ovm_rename_phys_disks.tmp
LOGFILE="ovm_rename_phys_disks.log"
 
 
>$TMP_FILE
[[ -e $1 ]] || { echo "Add meg a konfig fajlt parameterkent."; exit 1; }
ovm_cli "list PhysicalDisk" | awk -F' ' '/:/{print $2}' | sed 's/id://' | while read SOR; do
#ovm_cli "list PhysicalDisk" | awk -F' ' '/ \([0-9]/{print $2}' | sed 's/id://' | while read SOR; do
        echo "$SOR;$(ovm_exec "show PhysicalDisk id=$SOR" "User-Friendly Name" | tr '[:lower:]' '[:upper:]')" >>$TMP_FILE
done
date | tee -a $LOGFILE
while read LINE; do
        DISK_UUID=$(echo $LINE | cut -d' ' -f 1 | tr '[:lower:]' '[:upper:]')
        DISK_NAME=$(echo $LINE | cut -d' ' -f 2)
        DISK_SHARED=$(echo $LINE | cut -d' ' -f 3)
        VM_NAMES=$(echo $LINE | cut -d' ' -f 4 | sed 's/,/ /g')
        DISK_ID=$(awk -F';' "/$DISK_UUID/"'{print $1}' $TMP_FILE)
        echo -e "$(env printf '\u250F') A(z) $DISK_UUID UUID diszk atnevezese" | tee -a $LOGFILE
        echo -e "$(env printf '\u2523')$(env printf '\u2501')> UUID: ${grn}${DISK_UUID}${end}, Nev: ${grn}${DISK_NAME}${end}, Shared: ${grn}${DISK_SHARED}${end}, VM(ek): ${grn}${VM_NAMES}${end}" | tee -a $LOGFILE
        printf "$(env printf '\u2503') Ha ez nem stimmel, nyomj egy CTRL+C -t 10mp-en belül!${red}"
        countdown
        echo -e $end
        echo "OVM> edit PhysicalDisk id=$DISK_ID name=$DISK_NAME shared=$DISK_SHARED" | tee -a $LOGFILE
        RES=$(ovm_exec "edit PhysicalDisk id=$DISK_ID name=$DISK_NAME shareable=$DISK_SHARED" "Status")
        [[ -z $RES ]] && { echo -e "$(env printf '\u2503') ${red}edit PhysicalDisk HIBA!${end}" | tee -a $LOGFILE; continue; } || echo "$(env printf '\u2503') ${grn}${RES}${end}" | tee -a $LOGFILE
 
        echo "$(env printf '\u250F') A(z) ${yel}$VDISK_NAME${end} hozzarendelese a..." | tee -a $LOGFILE
        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" | tee -a $LOGFILE
                printf "$(env printf '\u2503') Ha ez nem stimmel, nyomj egy CTRL+C -t 10mp-en belül!${red}" | tee -a $LOGFILE
                countdown
                echo -e $end | tee -a $LOGFILE
                VDISK_MAP1=$(ovm_exec "create VmDiskMapping slot=$SLOT physicalDisk=\"$DISK_NAME\" name=\"${DISK_NAME}_to_${VM_NAME}\" on Vm id=\"$VM_ID\"" "Status")
                [[ -z $VDISK_MAP1 ]] && { echo -e "$(env printf '\u2503') ${red}create VmDiskMapping HIBA!${end}"; continue; } || echo "$(env printf '\u2503') Vdisk mapping: ${grn}$VDISK_MAP1 ${end}" | tee -a $LOGFILE
                echo "$(env printf '\u2523') A $VM_NAME kesz." | tee -a $LOGFILE
        done
        echo -e "$(env printf '\u2517') A(z) $DISK_UUID UUID diszk kesz." | tee -a $LOGFILE
        echo | tee -a $LOGFILE
done <<< "`cat $1 | grep -v '^#' | sed 's/[[:space:]]\+/ /g' | tr -s '[:blank:]'`"
sed -i -e 's/\x1b\[[0-9;]*m//g' -e 's/^M//g' $LOGFILE