Removed opendaylight build capabilities as a preparation toward Arno SR1
[genesis.git] / fuel / build / f_odl_docker / 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 CONTROL_HOST=172.30.9.70
10
11 # ENV
12 source ~/openrc
13
14 # VARS
15 ML2_CONF=/etc/neutron/plugins/ml2/ml2_conf.ini
16 MODE=0
17
18
19 # FUNCTIONS
20
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         cat "[ml2_odl]" >> $ML2_CONF
28         cat "password = admin" >> $ML2_CONF
29         cat "username = admin" >> $ML2_CONF
30         cat "url = http://${CONTROL_HOST}:8080/controller/nb/v2/neutron" >> $ML2_CONF
31 }
32
33 function reset_neutrondb {
34         echo "Reseting DB"
35         mysql -e "drop database if exists neutron_ml2;"
36         mysql -e "create database neutron_ml2 character set utf8;"
37         mysql -e "grant all on neutron_ml2.* to 'neutron'@'%';"
38         neutron-db-manage --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugin.ini upgrade head
39 }
40
41 function restart_neutron {
42         echo "Restarting Neutron Server"
43         service neutron-server restart
44         echo "Should see Neutron runing now"
45         service neutron-server status
46         echo "Shouldnt be any nets, but should work (return empty)"
47         neutron net-list
48 }
49
50 function stop_neutron {
51         echo "Stopping Neutron / OVS components"
52         service  neutron-plugin-openvswitch-agent stop
53         if [ $MODE == "0" ]
54         then
55                 service neutron-server stop
56         fi
57 }
58
59
60
61 function verify_ML2_working {
62         echo "checking that we can talk via ML2 properly"
63         curl -u admin:admin http://${CONTROL_HOST}:8080/controller/nb/v2/neutron/networks > /tmp/check_ml2
64         if grep "network" /tmp/check_ml2
65         then
66                 echo "Success - ML2 to ODL is working"
67         else
68                 echo "im sorry Jim, but its dead"
69         fi
70
71 }
72
73
74 function set_mode {
75         if ls -l /var/lib/glance/images
76         then
77                 echo "Controller Mode"
78                 MODE=0
79         else
80                 echo "Compute Mode"
81                 MODE=1
82         fi
83 }
84
85 function stop_ovs {
86         echo "Stopping OpenVSwitch"
87         service openvswitch-switch stop
88
89 }
90
91 function control_setup {
92         echo "Modifying Controller"
93         stop_neutron
94         stop_ovs
95         rm -rf /var/log/openvswitch/*
96         mkdir -p /opt/opnfv/odl/ovs_back
97         mv /etc/openvswitch/conf.db /opt/opnfv/odl/ovs_back/.
98         mv /etc/openvswitch/.conf*lock* /opt/opnfv/odl/ovs_back/.
99         service openvswitch-switch start
100         ovs-vsctl set-manager tcp:172.30.9.70:6640
101         ovs-vsctl add-br br-eth0
102         ovs-vsctl add-br br-ex
103         ovs-vsctl add-port br-eth0 eth0
104         ovs-vsctl add-port br-eth0 br-eth0--br-ex
105         ovs-vsctl add-port br-ex br-ex--br-eth0
106         ovs-vsctl set interface br-ex--br-eth0 type=patch
107         ovs-vsctl set interface br-eth0--br-ex type=patch
108         ovs-vsctl set interface br-ex--br-eth0 options:peer=br-eth0--br-ex
109         ovs-vsctl set interface br-eth0--br-ex options:peer=br-ex--br-eth0
110         ifconfig br-ex 172.30.9.70/24 up
111         service neutron-server restart
112
113         echo "setting up networks"
114         ip link add link eth1 name br-mgmt type vlan id 300
115         ip link add link eth1 name br-storage type vlan id 301
116         /etc/init.d/networking restart
117
118
119         echo "Reset Neutron DB"
120         #reset_neutrondb
121         echo "Restarting Neutron Components"
122         #restart_neutron
123         echo "Verifying ODL ML2 plugin is working"
124         verify_ML2_working
125
126 }
127
128 function compute_setup {
129         echo "do compute stuff here"
130         echo "stopping neutron openvswitch plugin"
131         stop_neutron
132         ip link add link eth1 name br-mgmt type vlan id 300
133         ifconfig br-mgmt `grep address /etc/network/interfaces.d/ifcfg-br-mgmt | awk -F" " '{print $2}'`/24
134         ip link add link eth1 name br-storage type vlan id 301
135         ifconfig br-storage `grep address /etc/network/interfaces.d/ifcfg-br-storage | awk -F" " '{print $2}'`/24
136         ifconfig eth1 `grep address /etc/network/interfaces.d/ifcfg-br-fw-mgmt | awk -F" " '{print $2}'`/24
137         echo "set manager, and route for ODL controller"
138         ovs-vsctl set-manager tcp:192.168.0.2:6640
139         route add 172.17.0.1 gw 192.168.0.2
140         verify_ML2_working
141 }
142
143
144 # MAIN
145 echo "Starting to make call"
146 update_ml2conf
147 echo "Check Mode"
148 set_mode
149
150 if [ $MODE == "0" ];
151 then
152         echo "Calling control setup"
153         control_setup
154 elif [ $MODE == "1" ];
155 then
156         echo "Calling compute setup"
157         compute_setup
158
159 else
160         echo "Something is bad - call for help"
161         exit
162 fi
163
164