@@ -32,15 +32,42 @@ usage() {
3232
3333# set -x
3434
35- # check if gateway domain is up and running
36- check_gw () {
37- ping -c 1 -n -q $1 > /dev/null
38- if [ $? -gt 0 ]
35+ # ensure that the nic has the public ip we are load balancing on
36+ ip_entry () {
37+ local added=$1
38+ local removed=$2
39+
40+ if [ " $added " == " none" ]
3941 then
40- sleep 1
41- ping -c 1 -n -q $1 > /dev/null
42+ added=" "
4243 fi
43- return $? ;
44+
45+ if [ " $removed " == " none" ]
46+ then
47+ removed=" "
48+ fi
49+
50+ local a=$( echo $added | cut -d, -f1- --output-delimiter=" " )
51+ local r=$( echo $removed | cut -d, -f1- --output-delimiter=" " )
52+
53+ for i in $a
54+ do
55+ local pubIp=$( echo $i | cut -d: -f1)
56+ for vif in $VIF_LIST ; do
57+ ip addr add dev $vif $pubIp /32
58+ # ignore error since it is because the ip is already there
59+ done
60+ done
61+
62+ for i in $r
63+ do
64+ local pubIp=$( echo $i | cut -d: -f1)
65+ for vif in $VIF_LIST ; do
66+ ip addr del $pubIp /32 dev $vif
67+ done
68+ done
69+
70+ return 0
4471}
4572
4673# firewall entry to ensure that haproxy can receive on specified port
@@ -117,6 +144,10 @@ get_vif_list() {
117144 vif_list=" $vif_list $vif " ;
118145 fi
119146 done
147+ if [ " $vif_list " == " " ]
148+ then
149+ vif_list=" eth0"
150+ fi
120151
121152 echo $vif_list
122153}
148179 esac
149180done
150181
151- VIF_LIST= $( get_vif_list )
152-
153- # hot reconfigure haproxy
154- reconfig_lb $cfgfile
182+ if [ " $addedIps " == " " ]
183+ then
184+ addedIps= " none "
185+ fi
155186
156- if [ $? -gt 0 ]
187+ if [ " $removedIps " == " " ]
157188then
158- printf " Reconfiguring loadbalancer failed\n"
159- exit 1
189+ removedIps=" none"
160190fi
161191
192+ VIF_LIST=$( get_vif_list)
193+
194+
162195if [ " $addedIps " == " " ]
163196then
164197 addedIps=" none"
@@ -169,6 +202,27 @@ then
169202 removedIps=" none"
170203fi
171204
205+ # FIXME: make this explicit via check on vm type or passed in flag
206+ if [ " $VIF_LIST " == " eth0" ]
207+ then
208+ ip_entry $addedIps $removedIps
209+ fi
210+
211+
212+ # hot reconfigure haproxy
213+ reconfig_lb $cfgfile
214+
215+ if [ $? -gt 0 ]
216+ then
217+ printf " Reconfiguring loadbalancer failed\n"
218+ # FIXME: make this explicit via check on vm type or passed in flag
219+ if [ " $VIF_LIST " == " eth0" ]
220+ then
221+ ip_entry $removedIps $addedIps
222+ fi
223+ exit 1
224+ fi
225+
172226# iptables entry to ensure that haproxy receives traffic
173227fw_entry $addedIps $removedIps
174228
@@ -180,6 +234,12 @@ then
180234 # Revert iptables rules on DomR, with addedIps and removedIps swapped
181235 fw_entry $removedIps $addedIps
182236
237+ # FIXME: make this explicit via check on vm type or passed in flag
238+ if [ " $VIF_LIST " == " eth0" ]
239+ then
240+ ip_entry $removedIps $addedIps
241+ fi
242+
183243 exit 1
184244fi
185245
0 commit comments