Changeset 181 for drbl-virt/sbin


Ignore:
Timestamp:
Aug 19, 2010, 6:03:54 PM (14 years ago)
Author:
rock
Message:

Modify: the same

Location:
drbl-virt/sbin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • drbl-virt/sbin/drbl_PXE_PV-VM_deploy.sh

    r180 r181  
    3131    Host_first_IP=""
    3232    Host_last_IP=""
    33     get_Host_IP_range $eth
     33    get_Host_IP_range
    3434    # == Get VM number & IP range  ==
    35     VM_IP_range=""
     35    declare -i VM_IP_range=""
     36    declare -i Host_last_IP_4=""
    3637    VM_first_IP=""
    3738    VM_last_IP=""
    38     get_VM_IP_range $eth
     39    get_VM_IP_range
    3940    # == Get VM IP prefix hostname  ==
    4041    VM_prefix_name=""
    41     get_VM_prefix_name $eth
     42    get_VM_prefix_name
    4243   
     44
    4345done
     46
    4447
    4548
  • drbl-virt/sbin/functions_drbl_virt

    r180 r181  
    157157
    158158function get_DRBL_eth(){
    159 eths=$(ls /etc/drbl | grep macadr-eth[0-9] | grep [0-9].txt | cut -d "-" -f2 | cut -d "." -f1)
     159eths=$(ls /etc/drbl | grep macadr-eth[0-9] | grep [0-9].txt$ | cut -d "-" -f2 | cut -d "." -f1)
    160160eths_nu=$(echo $eths | wc -l)
    161161
     
    170170
    171171# get eth network
    172 eth_address=$(/opt/drbl/bin/drbl-get-ipadd $1)
    173 eth_netmask=$(/opt/drbl/bin/drbl-get-netmask $1)
     172eth_address=$(/opt/drbl/bin/drbl-get-ipadd $eth)
     173eth_netmask=$(/opt/drbl/bin/drbl-get-netmask $eth)
    174174eth_network=$(/opt/drbl/bin/drbl-get-network $eth_address $eth_netmask)
    175175eth_network_f3=$(echo $eth_network | cut -d "." -f 1-3)
    176176
    177177IP_nu=$(cat /etc/drbl/IP_HOST_TABLE | grep $eth_network_f3 | wc -l)
    178 Host_first_IP=$(cat /etc/drbl/IP_HOST_TABLE | grep $eth_network_f3 | awk "NR==1 {print $1}" | awk '{print 1}')
     178Host_first_IP=$(cat /etc/drbl/IP_HOST_TABLE | grep $eth_network_f3 | awk "NR==1 {print $1}" | awk '{print $1}')
    179179Host_last_IP=$(cat /etc/drbl/IP_HOST_TABLE | grep $eth_network_f3 | awk "NR==$IP_nu {print $1}"| awk '{print $1}')
    180180
     
    183183function get_VM_IP_range(){
    184184echo ""
    185 echo "DRBL client IP range -> $1 [$Host_first_IP ~ $Host_last_IP]"
     185echo "DRBL client IP range -> $eth [$Host_first_IP ~ $Host_last_IP]"
    186186
    187187declare -i Host_last_IP_4=$(echo $Host_last_IP | cut -d "." -f4)
     
    195195do
    196196    echo ""
    197     echo "Input VM number/IP range in $1 (ex. 40)."
     197    echo "Input VM number/IP range in $eth (ex. 40)."
    198198    read -p "(If you have 10 PCs(4-core), suggestion is 30): " VM_IP_range
    199199    read -p "Is it correct? (yes/no): " jude
     
    209209do
    210210    echo ""
    211     read -p "Input Prefix name for VM in $1 (ex. drblvm): " VM_prefix_name
     211    read -p "Input Prefix name for VM in $eth (ex. drblvm): " VM_prefix_name
    212212    read -p "Is it correct? (yes/no): " jude
    213213done
     
    217217function create_VM_IP_table(){
    218218#/etc/drbl-virt/etc/IP_VM_eth
    219 
    220 }
    221 
    222 
    223 
    224 
     219VM_prefix_eth=$(echo $eth |  sed 's/eth//g')
     220declare -i VM_Host_totoal_nu=$((${Host_last_IP_4}-1+${VM_IP_range}))
     221if [ -e /opt/drbl-virt/etc/IP_VM_$eth ]; then
     222    mv /opt/drbl-virt/etc/IP_VM_$eth /opt/drbl-virt/etc/IP_VM_${eth}.$(date +%Y-%m-%d-%H-%M-%S).drbl-virt_bak
     223fi
     224declare -i VM_IP_0=$VM_prefix_eth
     225declare -i VM_IP_1=""
     226declare -i VM_IP_2=""
     227declare -i VM_IP_3=""
     228
     229
     230# 2 bit
     231if [ $VM_Host_totoal_nu -lt 100 ]; then
     232    for (( i=$Host_last_IP_4 ; i<="$VM_IP_range" ; i++ ))
     233    do
     234        if [ $i -lt 10 ]; then
     235            VM_IP_1=0
     236            VM_IP_2=$i
     237            echo "${eth_network_f3}.$VM_IP_2 ${VM_prefix_name}${VM_IP_0}${VM_IP_1}${VM_IP_2}" >> /opt/drbl-virt/etc/IP_VM_$eth
     238        else
     239            VM_IP_1=$i
     240            echo "${eth_network_f3}.$VM_IP_1 ${VM_prefix_name}${VM_IP_0}${VM_IP_1}" >> /opt/drbl-virt/etc/IP_VM_$et
     241        fi
     242    done
     243# 3 bit
     244elif [ $VM_Host_totoal_nu -ge 100 ] && [ $VM_Host_totoal_nu -lt 254 ]; then
     245    for (( i=$Host_last_IP_4 ; i<=$VM_IP_range ; i++ ))
     246    do
     247        if [ $i -lt 10 ]; then
     248            VM_IP_1=0
     249            VM_IP_2=0
     250            VM_IP_3=$i
     251            echo "${eth_network_f3}.${VM_IP_3} ${VM_prefix_name}${VM_IP_0}${VM_IP_1}${VM_IP_2}${VM_IP_3}" >> /opt/drbl-virt/etc/IP_VM_$eth
     252        elif [ $i -lt 100 ]; then
     253            VM_IP_1=0
     254            VM_IP_2=$i
     255            echo "${eth_network_f3}.${VM_IP_2} ${VM_prefix_name}${VM_IP_0}${VM_IP_1}${VM_IP_2}" >> /opt/drbl-virt/etc/IP_VM_$eth
     256        else
     257            VM_IP_1=$i
     258            echo "${eth_network_f3}.${VM_IP_1} ${VM_prefix_name}${VM_IP_0}${VM_IP_1}" >> /opt/drbl-virt/etc/IP_VM_$eth
     259        fi
     260
     261    done
     262
     263fi
     264}
     265
     266
     267
     268
Note: See TracChangeset for help on using the changeset viewer.