3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
16 echo -e "usage: $0 (OPTIONS)"
17 echo -e "Replaces original host IP address (typically saved at /home/vagrant/oldIPaddress.txt) where VCA listens in OSM configuration by a new one. Also used by docker swarm."
19 echo -e " -n <new_ip_addr>: new host ip address (default: current IP address)"
20 echo -e " -o <old_ip_addr>: old host ip address during initial install (default: content of /etc/osm/oldIPaddress.txt)"
21 echo -e " -h / --help: print this help"
24 while getopts ":n:o:-:h" o
; do
27 CURRENT_IP_ADDRESS
="${OPTARG}"
30 OLD_IP_ADDRESS
="${OPTARG}"
33 [ "${OPTARG}" == "help" ] && usage
&& exit 0
36 echo "Option -$OPTARG ip address required" >&2
40 echo -e "Invalid option: '-$OPTARG'\n" >&2
52 if [ -z "$CURRENT_IP_ADDRESS" ]
54 DEFAULT_IF
=$
(route
-n |
awk '$1~/^0.0.0.0/ {print $8}')
55 CURRENT_IP_ADDRESS
=$
(ip
-o -4 a |
grep ${DEFAULT_IF}|
awk '{split($4,a,"/"); print a[1]}')
57 [ -z "$OLD_IP_ADDRESS" ] && OLD_IP_ADDRESS
=$
(cat /etc
/osm
/oldIPaddress.txt
)
59 VCA_HOST
=$
(cat /etc
/osm
/docker
/lcm.env |
grep OSMLCM_VCA_HOST | cut
-f2 -d=)
61 sudo
sed -i "s/$OLD_IP_ADDRESS/$CURRENT_IP_ADDRESS/g" /etc
/osm
/docker
/lcm.env
62 sudo
sed -i "s/$OLD_IP_ADDRESS/$CURRENT_IP_ADDRESS/g" /etc
/osm
/docker
/mon.env
66 # Clean previous ip address info from Docker Swarm and reinitialize
67 docker swarm leave
--force
68 docker swarm init
--advertise-addr $CURRENT_IP_ADDRESS
69 sudo systemctl restart docker
70 docker network create
--driver=overlay
--attachable --opt com.docker.network.driver.mtu
=1500 netosm
73 source /etc
/osm
/docker
/osm_ports.sh
74 docker stack deploy
-c /etc
/osm
/docker
/docker-compose.yaml osm
76 sudo iptables
-t nat
-D PREROUTING
-p tcp
-m tcp
-d $OLD_IP_ADDRESS --dport 17070 -j DNAT
--to-destination $VCA_HOST
77 sudo iptables
-t nat
-A PREROUTING
-p tcp
-m tcp
-d $CURRENT_IP_ADDRESS --dport 17070 -j DNAT
--to-destination $VCA_HOST