[184] | 1 | #!/bin/bash |
---|
| 2 | # Program: |
---|
| 3 | # Path DRBL evironment to support Xen/KVM |
---|
| 4 | # Author: |
---|
| 5 | # Jazz, Rock {jazz, rock}@nchc.org.tw |
---|
| 6 | # Version: |
---|
| 7 | # 1.0 |
---|
| 8 | # History: |
---|
| 9 | # 2010/07/20 Rock First release (1.0) |
---|
| 10 | |
---|
| 11 | # [Source] |
---|
| 12 | source /opt/drbl-virt/conf/drbl-virt.conf |
---|
| 13 | source $Work_Path/functions_drbl_virt |
---|
| 14 | |
---|
| 15 | # [Main] |
---|
| 16 | |
---|
[185] | 17 | # = 1. Variables setup = |
---|
[184] | 18 | # == Get DRBL eth == |
---|
| 19 | eths="" |
---|
| 20 | declare -i eth_nu="" |
---|
| 21 | get_DRBL_eth |
---|
| 22 | |
---|
| 23 | if [ $eth_nu -gt "1" ]; then |
---|
| 24 | echo "" |
---|
| 25 | echo "DRBL environment has muiltpule netwrok card(NIC)." |
---|
| 26 | fi |
---|
[190] | 27 | |
---|
| 28 | # backup IP_HOST_TABLE |
---|
| 29 | if [ -e /etc/drbl/IP_HOST_TABLE.drbl-virt_bak ]; then |
---|
| 30 | cp /etc/drbl/IP_HOST_TABLE /etc/drbl/IP_HOST_TABLE.$(date +%Y-%m-%d-%H-%M-%S).drbl-virt_bak |
---|
| 31 | cp -f /etc/drbl/IP_HOST_TABLE.drbl-virt_bak /etc/drbl/IP_HOST_TABLE |
---|
[195] | 32 | cp -f /etc/drbl/IP_HOST_TABLE.drbl-virt_bak /opt/drbl-virt/etc/IP_HOST_TABLE |
---|
[190] | 33 | else |
---|
| 34 | cp /etc/drbl/IP_HOST_TABLE /etc/drbl/IP_HOST_TABLE.drbl-virt_bak |
---|
[195] | 35 | cp /etc/drbl/IP_HOST_TABLE /opt/drbl-virt/etc/IP_HOST_TABLE |
---|
[190] | 36 | fi |
---|
| 37 | |
---|
[200] | 38 | # back mac address file |
---|
| 39 | cp /etc/drbl/macadr*eth*[0-9].txt /opt/drbl-virt/etc/ |
---|
| 40 | |
---|
[184] | 41 | for eth in $eths |
---|
| 42 | do |
---|
| 43 | |
---|
| 44 | # == Get Host IP range/number == |
---|
| 45 | Host_first_IP="" |
---|
| 46 | Host_last_IP="" |
---|
| 47 | # get eth network |
---|
| 48 | eth_address=$(/opt/drbl/bin/drbl-get-ipadd $eth) |
---|
| 49 | eth_netmask=$(/opt/drbl/bin/drbl-get-netmask $eth) |
---|
| 50 | eth_network=$(/opt/drbl/bin/drbl-get-network $eth_address $eth_netmask) |
---|
| 51 | get_Host_IP_range |
---|
| 52 | |
---|
| 53 | # == Get VM number, IP range & prefix name == |
---|
| 54 | declare -i VM_IP_range="" |
---|
| 55 | declare -i Host_last_IP_4="" |
---|
| 56 | declare -i VM_Host_totoal_nu="" |
---|
| 57 | VM_first_IP="" |
---|
| 58 | VM_last_IP="" |
---|
| 59 | VM_prefix_name="" |
---|
[190] | 60 | |
---|
[184] | 61 | get_VM_IP_range_and_prefix_name |
---|
| 62 | create_VM_IP_table |
---|
| 63 | |
---|
| 64 | # == Generate MAC address == |
---|
| 65 | # MAC address [00:16:3e:xx:xx:xx] is for Xen use |
---|
| 66 | generate_Xen_MAC_address |
---|
| 67 | |
---|
[185] | 68 | # == Add VM IP to /etc/drbl/IP_HOST_TABLE == |
---|
[184] | 69 | VM_IPs=$(cat /opt/drbl-virt/etc/IP_VM_$eth | awk '{print $1}') |
---|
[185] | 70 | VM_IPs_nu=$(cat /opt/drbl-virt/etc/IP_VM_eth1 | awk '{print $1}' | wc -w) |
---|
[184] | 71 | VM_hosts=$(cat /opt/drbl-virt/etc/IP_VM_$eth | awk '{print $2}') |
---|
| 72 | VM_MACs=$(cat /opt/drbl-virt/etc/macadr-VM-$eth.txt) |
---|
[185] | 73 | |
---|
| 74 | # == Add Mac address to macadr-ethX.txt == |
---|
| 75 | if [ -e /etc/drbl/macadr-$eth.txt ]; then |
---|
[189] | 76 | delete_duplicating_MAC |
---|
[185] | 77 | fi |
---|
[187] | 78 | cat /opt/drbl-virt/etc/macadr-VM-$eth.txt >> /etc/drbl/macadr-$eth.txt |
---|
[184] | 79 | done |
---|
| 80 | |
---|
[185] | 81 | |
---|
| 82 | # = 2. Re-deploy drbl client = |
---|
| 83 | # == Cheange Xen Kernel == |
---|
[188] | 84 | Xen_Kernel=$(cat $Work_Home/etc/Xen_Kernel) |
---|
[190] | 85 | #read -p "Xen_Kernel=$Xen_Kernel" |
---|
[185] | 86 | echo "/opt/drbl/sbin/drblsrv-offline -s $Xen_Kernel" |
---|
| 87 | /opt/drbl/sbin/drblsrv-offline -s $Xen_Kernel |
---|
| 88 | echo "" |
---|
| 89 | # == Re-delpoy drbl client == |
---|
| 90 | echo "Re-delpoy drbl client" |
---|
| 91 | echo "/opt/drbl/sbin/drblpush -c /etc/drbl/drblpush.conf" |
---|
| 92 | /opt/drbl/sbin/drblpush -c /etc/drbl/drblpush.conf |
---|
| 93 | echo "" |
---|