blob: 10a971c9587cff8089a2ddf2ce007b1df31b0dac [file] [log] [blame]
AyumuUeha76a01bc2017-05-18 13:34:13 +09001#!/bin/bash
2#************************************************************/
3#** File: vsg_respin_vcpeproxy_docker.sh */
4#** Contents: Contains shell script to setup dnsmasq , */
5#** CP plane path,etc and respin the vcpe */
6#** docker instance created by XOS. */
7#** */
8#** This script should be executed as super-user */
9#************************************************************/
10
11echo "vsg_respin_vcpeproxy_docker.sh Execution: Begin"
12function setup_cp_path_in_docker (){
13# Set up cp networking in docker using pipework
14 echo "Executing setup_cp_path_in_docker...."
15#
16# TODO: FOr some reason, MAC address argument seems to throw pipework off
17# balance. Use auto-generated MAC address
18#
19# docker exec $VCPEPROXY_NAME ifconfig $VCPEPROXY_CP_IFACE>> /dev/null || pipework $VSG_CP_IFACE -i $VCPEPROXY_CP_IFACE $VCPEPROXY_NAME $VCPEPROXY_CP_IP/$VCPEGW_NETMASK_BITS@$VCPEPROXY_BRIDGE_IP
20 docker exec $VCPEPROXY_NAME ifconfig $VCPEPROXY_CP_IFACE>> /dev/null || pipework $VSG_CP_IFACE -i $VCPEPROXY_CP_IFACE $VCPEPROXY_NAME $VCPEPROXY_CP_IP/$VCPEGW_NETMASK_BITS
21 sleep 1
22 echo "waiting for $VCPEPROXY_CP_IFACE"
23 pipework --wait -i $VCPEPROXY_CP_IFACE
24 sleep 1
25 echo "$VCPEPROXY_CP_IFACE interface in container is UP"
26 docker exec $VCPEPROXY_NAME ifconfig $VCPEPROXY_CP_IFACE
27 docker exec $VCPEPROXY_NAME route add -net 10.6.1.0 netmask 255.255.255.0 gw 10.6.1.129 dev eth0
28}
29
30#
31## Prepare container volume files to be mounted to the docker instance
32#
33
34function update_mounted_files() {
35 sed -i "s/@@VCPEPROXY_DHCP_LISTEN_ADDRESS@@/${VCPEPROXY_DHCP_LISTEN_ADDRESS}/g" ${DNSMASQ_VCPE_CONF}
36 sed -i "s/@@VCPEPROXY_DHCP_LOW@@/${VCPEPROXY_DHCP_LOW}/g" ${DNSMASQ_VCPE_CONF}
37 sleep 1
38 sed -i "s/@@VCPEPROXY_DHCP_HIGH@@/${VCPEPROXY_DHCP_HIGH}/g" ${DNSMASQ_VCPE_CONF}
39
40#
41# Update rc.local file
42#
43 sed -i "s/@@VCPEPROXY_SUBNET@@/${VCPEPROXY_SUBNET}/g" ${RC_LOCAL}
44}
45
46function assign_addresses_to_vcpeproxy() {
47 MAC_3OCT=$(( STAG % 256 ))
48 MAC_2OCT=$(( CTAG % 256 ))
49 MAC_1OCT=$(( VCPE_PROXY_ID % 256 ))
50 HEX_MAC_3OCT=$( printf "%02x" $MAC_3OCT )
51 HEX_MAC_2OCT=$( printf "%02x" $MAC_2OCT )
52 HEX_MAC_1OCT=$( printf "%02x" $MAC_1OCT )
53 VCPEPROXY_CP_MAC=`echo $VCPEPROXY_CP_MAC_PREFIX:$HEX_MAC_3OCT:$HEX_MAC_2OCT:$HEX_MAC_1OCT`
54 echo "VCPEPROXY_CP_MAC .....$VCPEPROXY_CP_MAC"
55 export VCPEPROXY_CP_MAC
56#
57#
58# vcpe_gwbr_ip is computed in nova_vsg_setup.sh script.
59#
60 VCPEPROXY_BRIDGE_IP=`echo $vcpe_gwbr_ip`
61 export VCPEPROXY_BRIDGE_IP
62 echo "VCPE_BRIDGE_IP.......$VCPEPROXY_BRIDGE_IP"
63#
64# D-octet of the VCPEPROXY_CP_IP address is
65# calculated under the assumption each VCPE_PROXY is assigned
66# 4 (NUM_HOSTS value) additional WAN address one for each AP.
67#
68 echo "CP_IP_PREFIX = $VCPEPROXY_CP_IP_PREFIX"
69 VCPEPROXY_CP_IP_CVAL=$(( VSG_ID % 256 ))
70 VCPEPROXY_CP_IP_DVAL=$(( (VCPE_PROXY_ID-1)*(NUM_HOSTS+1) +1 ))
71 VCPEPROXY_CP_IP=`echo $VCPEPROXY_CP_IP_PREFIX.$VCPEPROXY_CP_IP_CVAL.$VCPEPROXY_CP_IP_DVAL`
72 export VCPEPROXY_CP_IP
73 echo "VCPEPROXY_CP_IP..... $VCPEPROXY_CP_IP"
74
75 VCPEPROXY_DHCP_LISTEN_ADDRESS=$VCPEPROXY_LOCAL_IP
76 export VCPEPROXY_DHCP_LISTEN_ADDRESS
77 echo "VCPEPROXY_DHCP_LISTEN_ADDRESS $VCPEPROXY_DHCP_LISTEN_ADDRESS"
78
79 VCPEPROXY_DHCP_LOW=`echo $VCPEPROXY_LOCAL_IP_PREFIX.$VCPEPROXY_DHCP_LOW`
80 export VCPEPROXY_DHCP_LOW
81 echo "VCPEPROXY_AP_DHCP_LOW $VCPEPROXY_DHCP_LOW"
82 VCPEPROXY_DHCP_HIGH=`echo $VCPEPROXY_LOCAL_IP_PREFIX.$VCPEPROXY_DHCP_HIGH`
83 export VCPEPROXY_DHCP_HIGH
84 echo "VCPEPROXY_DHCP_HIGH $VCPEPROXY_DHCP_HIGH"
85
86 VCPEPROXY_SUBNET=`echo $VCPEPROXY_LOCAL_IP_PREFIX.0`
87 export VCPEPROXY_SUBNET
88 echo "VCPEPROXY_SUBNET $VCPEPROXY_SUBNET"
89}
90
91function pause_and_update_container_volume() {
92 echo "Entering pause_and_update_container_volume"
93#
94# Docker containers created by XOS run in auto-start mode.
95# So, just pause the container instance and restart it to
96# pickup DHCP changes.
97#
98 echo "Pausing the container $VCPEPROXY_NAME"
99 if docker ps |grep $VCPEPROXY_NAME ; then
100 docker pause $VCPEPROXY_NAME
101 sleep 2
102 docker ps -a
103 fi
104 echo "Checking container directory"
105 if [ -d $CONTAINER_DIR ]; then
106 echo "$CONTAINER_DIR exists...Just replace vcpe.conf and rc.local with template files"
107 cp $HOME_DIR/docker_mounts/etc/dnsmasq.d/vcpe.conf $DNSMASQ_VCPE_CONF
108 cp $HOME_DIR/docker_mounts/mount/rc.local $RC_LOCAL
109 else
110 echo "$CONATAINER_DIR does not exist..create it first"
111 echo "Creating container directory"
112 mkdir $CONTAINER_DIR
113 echo "Copying container volumes"
114 cp -r $HOME_DIR/docker_mounts/* $CONTAINER_DIR
115 fi
116}
117
118function unpause_and_respin_docker() {
119 echo "Spinning up the stopped container"
120 docker unpause $VCPEPROXY_NAME
121 sleep 1
122 docker restart $VCPEPROXY_NAME
123 sleep 5
124 if docker ps -a |grep $VCPEPROXY_NAME |grep Up ; then
125 echo "Docker instance is up and running.."
126 else
127 echo "Error:...Docker instance $VCPEPROXY_NAME is not Up..."
128 fi
129 echo "Stopping ufw firewall in docker"
130 docker exec $VCPEPROXY_NAME ufw disable
131 docker exec $VCPEPROXY_NAME ufw status
132}
133
134echo "Begin: Starting execution of $0 script"
135
136if [ -z $vsg_home_dir ]; then
137 echo "WARNING...HOME Directory may not be setup properly"
138 vsg_home_dir=`pwd`
139fi
140echo "Dump environment variables"
141env >/tmp/vsg_env.out
142
143echo "Trying to respin $VCPEPROXY_NAME: [$STAG] [$CTAG]"
144docker inspect $VCPEPROXY_NAME > /dev/null 2>&1
145
146if [ "$?" == 1 ]; then
147 echo "$VCPEPROXY_NAME is not running!!!"
148 exit 1
149fi
150if [ -z $VCPE_PROXY_ID ]; then
151 echo "WARNING****VCPE_PROXY_ID is not set.."
152 exit 1
153fi
154if [ -z $CONTAINER_VOLUMES ];then
155 echo "WARNING**** CONTAINER_VOLUMES not set.."
156 CONTAINER_VOLUMES=/var/container_volumes; export CONTAINER_VOLUMES
157fi
158if [ -z DOCKER_SPINUP_DIR ]; then
159 echo "WARNING***** DOCKER SPINUP directory not set..."
160 DOCKER_SPINUP_DIR=/usr/local/sbin; export DOCKER_SPINUP_DIR
161fi
162HOME_DIR=$vsg_home_dir; export HOME_DIR
163CONTAINER_DIR=$CONTAINER_VOLUMES/$VCPEPROXY_NAME
164
165VCPEPROXY_DHCP_HIGH=$(( VCPEPROXY_DHCP_LOW + VCPEPROXY_NUM_HOSTS ))
166
167DNSMASQ_VCPE_CONF=$CONTAINER_DIR/etc/dnsmasq.d/vcpe.conf;export DNSMASQ_VCPE_CONF
168RC_LOCAL=$CONTAINER_DIR/mount/rc.local;export RC_LOCAL
169
170echo "Pausing the docker container $VCPEPROXY_NAME"
171pause_and_update_container_volume
172echo "Assign addresses for vcpe_proxy"
173assign_addresses_to_vcpeproxy
174echo "Updating container volumes"
175update_mounted_files
176unpause_and_respin_docker
177echo "Setting up vcpeproxy control plane path.."
178setup_cp_path_in_docker
179
180echo "Execution of vsg_respin_vcpeproxy_docker.sh script is complete: End"
181