e936e6056b4b6dd92f5c7abb202d1f57aec7ac0d
[apex-tripleo-heat-templates.git] / firstboot / install_vrouter_kmod.yaml
1 heat_template_version: ocata
2
3 parameters:
4   ContrailRepo:
5     type: string
6     default: http://192.168.24.1/contrail
7   VrouterPhysicalInterface:
8     default: 'eth0'
9     description: vRouter physical interface
10     type: string
11
12 description: >
13   Prepares vhost0 interface to be used by os-net-config
14
15 resources:
16   userdata:
17     type: OS::Heat::MultipartMime
18     properties:
19       parts:
20       - config: {get_resource: vrouter_module_config}
21
22   vrouter_module_config:
23     type: OS::Heat::SoftwareConfig
24     properties:
25       config:
26         str_replace:
27           template: |
28             #!/bin/bash
29             sed -i '/\[main\]/a \ \ \ \ \parser = future' /etc/puppet/puppet.conf
30             cat <<EOF > /etc/yum.repos.d/contrail.repo
31             [Contrail]
32             name=Contrail Repo
33             baseurl=$contrail_repo
34             enabled=1
35             gpgcheck=0
36             protect=1
37             EOF
38             if [[ `hostname |awk -F"-" '{print $2}'` == "novacompute" || `hostname |awk -F"-" '{print $2}'` == "contrailtsn" ]]; then 
39               yum install -y contrail-vrouter-utils
40               function pkt_setup () {
41                   for f in /sys/class/net/$1/queues/rx-*
42                   do
43                       q="$(echo $f | cut -d '-' -f2)"
44                       r=$(($q%32))
45                       s=$(($q/32))
46                       ((mask=1<<$r))
47                       str=(`printf "%x" $mask`)
48                       if [ $s -gt 0 ]; then
49                           for ((i=0; i < $s; i++))
50                           do
51                               str+=,00000000
52                           done
53                       fi
54                       echo $str > $f/rps_cpus
55                   done
56                   ifconfig $1 up
57               }
58               function insert_vrouter() {
59                   insmod /tmp/vrouter.ko
60                   if [ -f /sys/class/net/pkt1/queues/rx-0/rps_cpus ]; then
61                       pkt_setup pkt1
62                   fi
63                   if [ -f /sys/class/net/pkt2/queues/rx-0/rps_cpus ]; then
64                       pkt_setup pkt2
65                   fi
66                   if [ -f /sys/class/net/pkt3/queues/rx-0/rps_cpus ]; then
67                       pkt_setup pkt3
68                   fi
69                   DEV_MAC=$(cat /sys/class/net/$phy_int/address)
70                   vif --create vhost0 --mac $DEV_MAC
71                   vif --add $phy_int --mac $DEV_MAC --vrf 0 --vhost-phys --type physical
72                   vif --add vhost0 --mac $DEV_MAC --vrf 0 --type vhost --xconnect $phy_int
73                   ip link set vhost0 up
74                   return 0
75               }
76               yumdownloader contrail-vrouter --destdir /tmp
77               cd /tmp
78               rpm2cpio /tmp/contrail-vrouter*.rpm | cpio -idmv
79               cp `find /tmp/lib/modules -name vrouter.ko |tail -1` /tmp
80               insert_vrouter
81               if [[ `ifconfig $dev |grep "inet "` ]]; then
82                 def_gw=''
83                 if [[ `ip route show |grep default|grep $dev` ]]; then
84                   def_gw=`ip route show |grep default|grep $dev|awk '{print $3}'`
85                 fi
86                 ip=`ifconfig $dev |grep "inet "|awk '{print $2}'`
87                 mask=`ifconfig $dev |grep "inet "|awk '{print $4}'`
88                 ip address delete $ip/$mask dev $dev
89                 ip address add $ip/$mask dev vhost0
90                 if [[ $def_gw ]]; then
91                   ip route add default via $def_gw
92                 fi
93               fi
94             fi
95           params:
96             $phy_int: {get_param: VrouterPhysicalInterface}
97             $contrail_repo: {get_param: ContrailRepo}
98
99 outputs:
100   # This means get_resource from the parent template will get the userdata, see:
101   # http://docs.openstack.org/developer/heat/template_guide/composition.html#making-your-template-resource-more-transparent
102   # Note this is new-for-kilo, an alternative is returning a value then using
103   # get_attr in the parent template instead.
104   OS::stack_id:
105     value: {get_resource: userdata}