Removed opendaylight build capabilities as a preparation toward Arno SR1
[genesis.git] / fuel / build / f_odl_docker / puppet / modules / opnfv / scripts / config_net_odl.sh
1 #!/bin/bash
2 #
3 # Author: Daniel Smith (Ericsson)
4 #
5 # Script to update neutron configuration for OVSDB/ODL integratino
6 #
7 #  Usage - Set / pass CONTROL_HOST to your needs
8 #
9 ### SET THIS VALUE TO MATCH YOUR SYSTEM
10 CONTROL_HOST=192.168.0.2
11 BR_EX_IP=172.30.9.70
12
13 # ENV
14 source ~/openrc
15 # VARS
16 ML2_CONF=/etc/neutron/plugins/ml2/ml2_conf.ini
17 MODE=0
18
19
20 # FUNCTIONS
21 # Update ml2_conf.ini
22 function update_ml2conf {
23         echo "Backing up and modifying ml2_conf.ini"
24         cp $ML2_CONF $ML2_CONF.bak
25         sed -i -e 's/mechanism_drivers =openvswitch/mechanism_drivers = opendaylight/g' $ML2_CONF
26         sed -i -e 's/tenant_network_types = flat,vlan,gre,vxlan/tenant_network_types = vxlan/g' $ML2_CONF
27         sed -i -e 's/bridge_mappings=physnet2:br-prv/bridge_mappings=physnet1:br-ex/g' $ML2_CONF
28         echo "[ml2_odl]" >> $ML2_CONF
29         echo "password = admin" >> $ML2_CONF
30         echo "username = admin" >> $ML2_CONF
31         echo "url = http://${CONTROL_HOST}:8080/controller/nb/v2/neutron" >> $ML2_CONF
32 }
33
34 function reset_neutrondb {
35         echo "Reseting DB"
36         mysql -e "drop database if exists neutron_ml2;"
37         mysql -e "create database neutron_ml2 character set utf8;"
38         mysql -e "grant all on neutron_ml2.* to 'neutron'@'%';"
39         neutron-db-manage --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugin.ini upgrade head
40 }
41
42 function restart_neutron {
43         echo "Restarting Neutron Server"
44         service neutron-server restart
45         echo "Should see Neutron runing now"
46         service neutron-server status
47         echo "Shouldnt be any nets, but should work (return empty)"
48         neutron net-list
49 }
50
51 function stop_neutron {
52         echo "Stopping Neutron / OVS components"
53         service  neutron-plugin-openvswitch-agent stop
54         if [ $MODE == "0" ]
55         then
56                 service neutron-server stop
57         fi
58 }
59
60 function disable_agent {
61         echo "Disabling Neutron Plugin Agents from running"
62         service neutron-plugin-openvswitch-agent stop
63         echo 'manual' > /etc/init/neutron-plugin-openvswitch-agent.override
64 }
65
66
67
68 function verify_ML2_working {
69         echo "checking that we can talk via ML2 properly"
70         curl -u admin:admin http://${CONTROL_HOST}:8080/controller/nb/v2/neutron/networks > /tmp/check_ml2
71         if grep "network" /tmp/check_ml2
72         then
73                 echo "Success - ML2 to ODL is working"
74         else
75                 echo "im sorry Jim, but its dead"
76         fi
77
78 }
79
80
81 function set_mode {
82         if [ -d "/var/lib/glance/images" ]
83         then
84                 echo "Controller Mode"
85                 MODE=0
86         else
87                 echo "Compute Mode"
88                 MODE=1
89         fi
90 }
91
92 function stop_ovs {
93         echo "Stopping OpenVSwitch"
94         service openvswitch-switch stop
95
96 }
97
98 function start_ovs {
99         echo "Starting OVS"
100         service openvswitch-vswitch start
101         ovs-vsctl show
102 }
103
104
105 function control_setup {
106         echo "Modifying Controller"
107         stop_neutron
108         stop_ovs
109         disable_agent
110         rm -rf /var/log/openvswitch/*
111         mkdir -p /opt/opnfv/odl/ovs_back
112         mv /etc/openvswitch/conf.db /opt/opnfv/odl/ovs_back/.
113         mv /etc/openvswitch/.conf*lock* /opt/opnfv/odl/ovs_back/.
114         rm -rf /etc/openvswitch/conf.db
115         rm -rf /etc/openvswitch/.conf*
116         service openvswitch-switch start
117         ovs-vsctl add-br br-ex
118         ovs-vsctl add-port br-ex eth0
119         ovs-vsctl set interface br-ex type=external
120         ifconfig br-ex 172.30.9.70/24 up
121         service neutron-server restart
122
123         echo "setting up networks"
124         ip link add link eth1 name br-mgmt type vlan id 300
125         ifconfig br-mgmt `grep address /etc/network/interfaces.d/ifcfg-br-mgmt | awk -F" " '{print $2}'`/24 up arp
126         ip link add link eth1 name br-storage type vlan id 301
127         ip link add link eth1 name br-prv type vlan id 1000
128         ifconfig br-storage `grep address /etc/network/interfaces.d/ifcfg-br-storage | awk -F" " '{print $2}'`/24 up arp
129         ifconfig eth1 `grep address /etc/network/interfaces.d/ifcfg-br-fw-admin | awk -F" " '{print $2}'`/24 up arp
130
131         echo "Setting ODL Manager IP"
132         ovs-vsctl set-manager tcp:192.168.0.2:6640
133
134         echo "Verifying ODL ML2 plugin is working"
135         verify_ML2_working
136
137         # BAD HACK - Should be parameterized - this is to catch up 
138         route add default gw 172.30.9.1
139
140 }
141
142 function clean_ovs {
143         echo "cleaning OVS DB"
144         stop_ovs
145         rm -rf /var/log/openvswitch/*
146         mkdir -p /opt/opnfv/odl/ovs_back
147         cp -pr /etc/openvswitch/* /opt/opnfv/odl/ovs_back/.
148         rm -rf /etc/openvswitch/conf.db
149         echo "restarting OVS - you should see Nothing there"
150         start_ovs
151 }
152
153 function compute_setup {
154         echo "Modifying Compute"
155         echo "Disabling neutron openvswitch plugin"
156         stop_neutron
157         disable_agent
158         ip link add link eth1 name br-mgmt type vlan id 300
159         ifconfig br-mgmt `grep address /etc/network/interfaces.d/ifcfg-br-mgmt | awk -F" " '{print $2}'`/24 up arp
160         ip link add link eth1 name br-storage type vlan id 301
161         ip link add link eth1 name br-prv type vlan id 1000
162         ifconfig br-storage `grep address /etc/network/interfaces.d/ifcfg-br-storage | awk -F" " '{print $2}'`/24 up arp
163         ifconfig eth1 `grep address /etc/network/interfaces.d/ifcfg-br-fw-admin | awk -F" " '{print $2}'`/24 up arp
164
165         echo "set manager, and route for ODL controller"
166         ovs-vsctl set-manager tcp:192.168.0.2:6640
167         route add 172.17.0.1 gw 192.168.0.2
168         verify_ML2_working
169 }
170
171
172 # MAIN
173 echo "Starting to make call"
174 update_ml2conf
175 echo "Check Mode"
176 set_mode
177
178 if [ $MODE == "0" ];
179 then
180         echo "Calling control setup"
181         control_setup
182 elif [ $MODE == "1" ];
183 then
184         echo "Calling compute setup"
185         compute_setup
186
187 else
188         echo "Something is bad - call for help"
189         exit
190 fi
191
192