Ignore:
Timestamp:
Aug 20, 2010, 12:00:37 PM (14 years ago)
Author:
rock
Message:

Add Function Code: generate Xen MAC address

File:
1 edited

Legend:

Unmodified
Added
Removed
  • drbl-virt/sbin/functions_drbl_virt

    r182 r183  
    236236#/etc/drbl-virt/etc/IP_VM_eth
    237237VM_prefix_eth=$(echo $eth |  sed 's/eth//g')
    238 declare -i VM_Host_totoal_nu=$((${Host_last_IP_4}-1+${VM_IP_range}))
     238VM_Host_totoal_nu=$((${Host_last_IP_4}-1+${VM_IP_range}))
    239239if [ -e /opt/drbl-virt/etc/IP_VM_$eth ]; then
    240240    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
     
    244244declare -i VM_IP_2=""
    245245declare -i VM_IP_3=""
    246 
    247246
    248247# 2 bit
     
    268267            VM_IP_3=$i
    269268            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
    270         elif [ $i -lt 100 ]; then
     269        elif [ $i -ge 10 ] && [ $i -lt 100 ]; then
    271270            VM_IP_1=0
    272271            VM_IP_2=$i
     
    282281}
    283282
    284 
    285 
    286 
     283function generate_Xen_MAC_address(){
     284echo "eth $eth"
     285echo "VM_Host_totoal_nu $VM_Host_totoal_nu"
     286echo "Host_last_IP_4 $Host_last_IP_4"
     287echo "VM_prefix_eth $VM_prefix_eth"
     288
     289# /opt/drbl-virt/etc/macadr-VM-ethX.txt
     290# MAC address [00:16:3e:xx:xx:xx] is for Xen use
     291declare -i Xen_MAC_1="0"
     292declare -i Xen_MAC_2="$VM_prefix_eth"
     293declare -i Xen_MAC_3="0"
     294declare -i Xen_MAC_4="0"
     295Xen_MAC_5=""
     296Xen_MAC_6=""
     297
     298# backup
     299mv /opt/drbl-virt/etc/macadr-VM-$eth.txt /opt/drbl-virt/etc/macadr-VM-$eth.txt.$(date +%Y-%m-%d-%H-%M-%S).drbl-virt_bak
     300
     301# generate MAC
     302for (( i=0 ; i<="$VM_Host_totoal_nu" ; i++ ))
     303do
     304    if [ $i -lt 10 ]; then
     305        Xen_MAC_5=0
     306        Xen_MAC_6=$i
     307        echo "00:16:3e:${Xen_MAC_1}${Xen_MAC_2}:${Xen_MAC_3}${Xen_MAC_4}:${Xen_MAC_5}${Xen_MAC_6}" >> /opt/drbl-virt/etc/macadr-VM-$eth.txt
     308    elif [ $i -ge 10 ] && [ $i -le 15 ] ; then
     309        Xen_MAC_5=0
     310        # translate 10(dec) to 16(hex)
     311        printf '%X\n' $i > /tmp/drbl-virt_MAC
     312        Xen_MAC_6=$(cat /tmp/drbl-virt_MAC)
     313        echo "00:16:3e:${Xen_MAC_1}${Xen_MAC_2}:${Xen_MAC_3}${Xen_MAC_4}:${Xen_MAC_5}${Xen_MAC_6}" >> /opt/drbl-virt/etc/macadr-VM-$eth.txt
     314    else
     315        printf '%X\n' $i > /tmp/drbl-virt_MAC
     316        Xen_MAC_5=$(cat /tmp/drbl-virt_MAC)
     317        echo "00:16:3e:${Xen_MAC_1}${Xen_MAC_2}:${Xen_MAC_3}${Xen_MAC_4}:${Xen_MAC_5}" >> /opt/drbl-virt/etc/macadr-VM-$eth.txt
     318    fi
     319done
     320
     321
     322}
     323
     324
Note: See TracChangeset for help on using the changeset viewer.