Bump odlparent to 4.0.8
[netvirt.git] / resources / openstack / dsconf.sh
1 #!/bin/sh
2 #
3 # Copyright (C) 2013 Cisco Systems, Inc.
4 #
5 # This program and the accompanying materials are made available under the
6 # terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 # and is available at http://www.eclipse.org/legal/epl-v10.html
8 #
9 # Authors : Thomas Bachman
10
11 #
12 # Generate the local.conf, based on this machine's settings,
13 # and user input
14 #
15
16 odl_ip=""
17 odl_in_ds="y"
18 vm_personality="ODC"
19 active_ifs=""
20 service_host=""
21 service_host_name=""
22 odl_mgr_ip=""
23 host_ip=""
24 host_name=`hostname`
25 host_list=""
26
27 # Minimum memory requirements, in kB
28 od_mem=50000000
29 oc_mem=3000000
30 o_mem=2000000
31 odoc_mem=5000000
32 oco_mem=3000000
33
34
35
36 #
37 # personality-dependent services
38 #
39 ds_common_services="qpid neutron odl-compute n-cpu"
40 ds_compute_services="nova n-novnc"
41 ds_controller_services="n-cond q-svc q-dhcp q-l3 q-meta tempest"
42
43 #
44 # everyone gets these services
45 #
46 services=$ds_common_services
47
48 #
49 # services that are disabled
50 #
51 disabled_services="rabbit n-net"
52
53 header='''
54 LOGFILE=stack.sh.log\n
55 #SCREEN_LOGDIR=/opt/stack/data/log\n
56 #LOG_COLOR=False\n
57 OFFLINE=True\n
58 #RECLONE=yes\n
59 \n
60 '''
61
62 #
63 # single quoted to prevent variable substitutions
64 #
65 # add host info
66
67 footer='''
68 Q_HOST=$SERVICE_HOST\n
69 Q_PLUGIN=ml2\n
70 Q_ML2_PLUGIN_MECHANISM_DRIVERS=opendaylight,logger\n
71 ENABLE_TENANT_TUNNELS=True\n
72 ODL_BOOT_WAIT=70\n
73 \n
74 VNCSERVER_PROXYCLIENT_ADDRESS=${HOST_IP}\n
75 VNCSERVER_LISTEN=0.0.0.0\n
76 \n
77 #FLOATING_RANGE=192.168.210.0/24\n
78 #PUBLIC_NETWORK_GATEWAY=192.168.75.254\n
79 MYSQL_HOST=$SERVICE_HOST\n
80 RABBIT_HOST=$SERVICE_HOST\n
81 GLANCE_HOSTPORT=$SERVICE_HOST:9292\n
82 KEYSTONE_AUTH_HOST=$SERVICE_HOST\n
83 KEYSTONE_SERVICE_HOST=$SERVICE_HOST\n
84 \n
85 MYSQL_PASSWORD=mysql\n
86 RABBIT_PASSWORD=rabbit\n
87 QPID_PASSWORD=rabbit\n
88 SERVICE_TOKEN=service\n
89 SERVICE_PASSWORD=admin\n
90 ADMIN_PASSWORD=admin\n
91 \n
92 [[post-config|/etc/neutron/plugins/ml2/ml2_conf.ini]]\n
93 [agent]\n
94 minimize_polling=True\n
95 '''
96
97 #
98 # Create a list of active network interfaces
99 #
100 get_active_ifs()
101 {
102    all_ifs=`egrep 'ONBOOT' /etc/sysconfig/network-scripts/ifcfg-*`
103    for interface in $all_ifs
104    do
105        active=`echo $interface | awk 'BEGIN {FS="="} {print $2}'`
106        if [ "$active" == "yes" ]; then
107            file=`echo $interface | awk 'BEGIN {FS=":"} {print $1}'`
108            intf=`basename $file | awk 'BEGIN {FS="-"} {print $2}'`
109            active_ifs=`echo "$active_ifs $intf"`
110        fi
111    done
112 }
113
114 #
115 # Have the user select the IP address to use
116 #
117 select_host_ip()
118 {
119     get_active_ifs
120     echo "Your system has the following IP addresses: "
121     count=0
122     if_index="0"
123     for interface in $active_ifs
124     do
125         if [ "$interface" == "lo" ]; then
126             continue;
127         fi
128         exists=`ifconfig | grep $interface`
129         if [ "$exists" == "" ]; then
130             continue;
131         fi
132         ip=`ifconfig $interface | grep 'inet ' | awk 'BEGIN {FS=" "} {print $2}'`
133         echo "    [$count] $interface: $ip"
134         let "count+=1";
135     done
136
137     entry=$if_index
138     if [ $count == 0 ]; then
139         echo "No active interfaces: please reconfigure /etc/sysconfig/network-scripts/ifcfg-<interface> and re-run"
140         exit
141     elif [ $count > 1 ]; then
142         echo -n "Select which interface to use [$entry]: "
143         read -a entry
144         if [ "$entry" > "$count" ]; then
145             let "maxcnt=count-1"
146             echo "Invalid entry, must be less than $maxcnt"
147             exit
148         elif [ "$entry" == "" ]; then
149             entry=$if_index
150         else
151             $if_index=$entry
152         fi
153     fi
154
155     count=0
156     for interface in $active_ifs
157     do
158         if [ $count == $if_index ]; then
159             #echo "foo"
160             host_ip=`ifconfig $interface | grep 'inet ' | awk 'BEGIN {FS=" "} {print $2}'`
161             break;
162         fi
163         let "count+=1"
164     done
165 }
166
167 #
168 #  Verify the memory is sufficient for the configuration
169 #
170 check_mem()
171 {
172     memory=`cat /proc/meminfo  | grep MemTotal | awk 'BEGIN {FS=" "} {print $2}'`
173     if [ "$vm_personality" == "O" ]; then
174         mem_needed=$od_mem
175     elif [ "$vm_personality" == "DC" ]; then
176         mem_needed=$oc_mem
177     elif [ "$vm_personality" == "D" ]; then
178         mem_needed=$o_mem
179     elif [ "$vm_personality" == "ODC" ]; then
180         mem_needed=$odoc_mem
181     elif [ "$vm_personality" == "DCD" ]; then
182         mem_needed=$oco_mem
183     fi
184     if [ "$memory" -lt "$mem_needed" ]; then
185         echo """
186              $vm_personality configurations require at least $mem_needed (have $memory).
187              Please shutdown the VM and reconfigure its memory
188              """
189         exit
190     fi
191 }
192
193 echo """
194    This script configures the local.conf for the
195    VM, based on the desired configuration.  The
196    VM can take on any of the following roles:
197
198        O:    OpenDaylight Controller.
199                In this role, the VM is only responsible
200                for running the OpenDaylight Controller
201
202        DC:   DevStack Controller.
203                In this role, the VM is only responsible
204                for running the DevStack controller.
205
206        D:    DevStack Compute. In this role,
207                the VM is only responsible for
208                running the DevStack compute.
209
210        ODC:  OpenDaylight Controller with DevStack Controller.
211                In this role, the VM runs both the OpenDaylight
212                controller and the DevStack controller. The
213                OpenDaylight controller is launched by DevStack.
214
215        DCD:  DevStack Controller with DevStack Compute.
216                In this role, the VM acts as both an DevStack
217                controller and compute node.
218 """
219
220 echo -n "Enter VM's personality [$vm_personality]: "
221 read -a entry
222 if [ "$entry" == "" ]; then
223     entry=$vm_personality
224 else
225     vm_personality=$entry
226 fi
227 if [ "$vm_personality" != "O" ] &&
228    [ "$vm_personality" != "DC" ] &&
229    [ "$vm_personality" != "D" ]  &&
230    [ "$vm_personality" != "ODC" ]  &&
231    [ "$vm_personality" != "DCD" ]; then
232     echo "$vm_personality is invalid"
233     exit;
234 fi
235
236 # For all nodes, run the memory check to make
237 # sure they've allocated enough memory to
238 # run the system.
239 check_mem
240
241 # Get the right IP
242 select_host_ip
243
244 service_host=$host_ip
245 service_host_name=$host_name
246
247 # For a combined ODL/DS coontroller, we still need
248 # to add in the services
249 if [ "$vm_personality" == "ODC" ]; then
250    services="$services $ds_controller_services odl-server"
251 fi
252
253 # For all pure DS nodes (no ODL -- DS controller, compute, or both),
254 # we need to point it to the ODL Controller
255 if [ "$vm_personality" == "D" ] ||
256    [ "$vm_personality" == "DC" ] ||
257    [ "$vm_personality" == "DCD" ]; then
258    if [ "$vm_personality" == "D" ]; then
259       services="$services $ds_compute_services"
260    else
261       services="$services $ds_controller_services"
262    fi
263    service_host=$host_ip
264    service_host_name=$host_name
265    echo """
266            DevStack nodes need to point to the OpenDaylight Controller.
267            Please provide the IP address of the OpenDaylight Controller.
268         """
269    echo -n "OpenDaylight Controller IP: "
270    read -a odl_ip
271 fi
272
273
274 #
275 # For DS Compute Only, we need to point it to
276 # the DS Controller and update the DS services
277 if [ "$vm_personality" == "D" ]; then
278    services="$services $ds_compute_services"
279    echo """
280            DevStack Compute nodes need to point to the DevStack
281            Controller. Please provide the IP address and hostname
282            of the DevStack Controller
283         """
284    echo -n "DevStack Controller IP: "
285    read -a service_host
286    echo -n "DevStack Controller hostname: "
287    read -a service_host_name
288    if [ "$service_host_name" == "$host_name" ]; then
289        echo """
290                Note: You have configured the DevStack controller's
291                      with the same name as this host. If this host
292                      requires a name change, run the set_hostname.sh
293                      script before running this one.
294             """
295    fi
296    echo """
297            DevStack Compute nodes also need to point to the
298            OpenDaylight Controller. Please provide the IP address
299            of the OpenDaylight Controller
300         """
301
302    # for DS compute, keep track of service host
303    host_list=$service_host_name
304 fi
305
306 ######
307 # Generate local.conf, using parameters
308 ######
309 echo "[[local|localrc]]" > local.conf
310
311 #
312 #  Header
313 #
314 echo -e $header | while read -r line
315 do
316     echo -e $line >> local.conf
317 done
318
319 #
320 # Services
321 #
322 # disable all services for compute only nodes
323 if [ "$vm_personality" == "D" ]; then
324    echo "disable_all_services" >> local.conf
325 fi
326
327 for line in $disabled_services
328 do
329    echo "disable_service $line" >> local.conf
330 done
331
332 for line in $services
333 do
334    echo -e "enable_service $line" >> local.conf
335 done
336 echo -e "\n" >> local.conf
337
338
339
340 #
341 # Add in VM-specific parameters
342 #
343 echo "HOST_IP=$host_ip" >> local.conf
344 echo "HOST_NAME=$host_name" >> local.conf
345 echo "SERVICE_HOST=$service_host" >> local.conf
346 echo "SERVICE_HOST_NAME=$service_host_name" >> local.conf
347 if [ "$vm_personality" != "O" ] &&
348    [ "$vm_personality" != "ODC" ]; then
349     echo "ODL_MGR_IP=$odl_ip" >> local.conf
350 fi
351
352
353 #
354 # Footer
355 #
356 echo -e $footer | while read -r line
357 do
358     echo -e $line >> local.conf
359 done
360
361
362 if [ "$host_list" != "" ]; then
363     echo "*********************************************************"
364     echo "===========>>>> Be sure to add $host_list to /etc/hosts!"
365     echo "*********************************************************"
366 fi
367
368