-
Notifications
You must be signed in to change notification settings - Fork 7
/
coriolis_change_ip.sh
executable file
·60 lines (47 loc) · 1.33 KB
/
coriolis_change_ip.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
set -e
get_interface_ipv4 () {
local IFACE=$1
ip addr show $IFACE | sed -n 's/^\s*inet \([0-9.]*\)\/[0-9]*\s* brd [0-9.]*.*$/\1/p'
}
source /var/lib/coriolis/keystone_admin_rc
CONFIG_PATH=/var/lib/coriolis/coriolis.ini
OLD_IP=`crudini --get $CONFIG_PATH dhcp current_ip`
NEW_IP=$1
if [ -z "$OLD_IP" ]; then
echo "OLD_IP not set"
exit 1
fi
if [ -z "$NEW_IP" ]; then
PUBLIC_IFACE=`crudini --get $CONFIG_PATH dhcp interface`
if [ -z "$PUBLIC_IFACE" ]; then
echo "Interface not set"
exit 1
fi
NEW_IP=`get_interface_ipv4 $PUBLIC_IFACE`
if [ -z "$NEW_IP" ]; then
echo "Interface ip not set"
exit 1
fi
fi
if [ "$NEW_IP" == "$OLD_IP" ]; then
echo "NEW_IP equals OLD_IP, no action needed"
exit 0
fi
crudini --set /etc/barbican/barbican.conf DEFAULT host_href http://$NEW_IP:9311
L=`openstack endpoint list | grep $OLD_IP | awk '{print $2 " " $14}'`
if [ -z "$L" ]; then
echo "Could not get endpoint list"
exit 1
fi
IFS=$'\n'
for i in $L; do
unset IFS
read ID OLD_URL <<< $i
NEW_URL=`echo "$OLD_URL" | sed 's/'$OLD_IP'/'$NEW_IP'/g'`
echo openstack endpoint set $ID --url "$NEW_URL"
openstack endpoint set $ID --url "$NEW_URL"
done
service barbican-worker restart
service apache2 restart
crudini --set $CONFIG_PATH dhcp current_ip $NEW_IP