Merge "Contrail network realignement + DPDK enablement"
[apex-tripleo-heat-templates.git] / extraconfig / pre_network / contrail / compute_pre_network.yaml
1 heat_template_version: pike
2
3 # NOTE: You don't need to pass the parameter explicitly from the
4 # parent template, it can be specified via the parameter_defaults
5 # in the resource_registry instead, if you want to override the default
6 # and/or share values with other templates in the tree.
7 parameters:
8   ContrailRepo:
9     type: string
10     default: ''
11   ContrailVrouterPhysicalInterface:
12     default: 'eth0'
13     description: vRouter physical interface
14     type: string
15   ContrailVlanParentInterface:
16     default: ''
17     description: Parent interface of vlan interface
18     type: string
19   ContrailBondInterface:
20     default: ''
21     description: Bond interface name
22     type: string
23   ContrailBondInterfaceMembers:
24     default: ''
25     description: Bond interface members
26     type: string
27   ContrailBondMode:
28     default: '4'
29     description: Bond Mode
30     type: string
31   ContrailBondPolicy:
32     default: '1'
33     description: Bond Policy
34     type: string
35   RoleParameters:
36     type: json
37     description: Role Specific parameters
38     default: {}
39   ServiceNames:
40     type: comma_delimited_list
41     default: []
42   server:
43     type: string
44
45 description: >
46   This template installs the Contrail kernel module  packages in order
47   to bring vhost0 interface up. Vhost0 interface must be up before
48   os-net-config takes over.
49
50 resources:
51
52   ContrailVrouterModuleDeployment:
53     type: OS::Heat::SoftwareDeployment
54     properties:
55       name: ContrailVrouterModuleDeployment
56       server:  {get_param: server}
57       config: {get_resource: ContrailVrouterModuleConfig}
58       input_values:
59         phy_int: {get_param: ContrailVrouterPhysicalInterface}
60         bond_int: {get_param: ContrailBondInterface}
61         bond_int_members: {get_param: ContrailBondInterfaceMembers}
62         vlan_parent: {get_param: ContrailVlanParentInterface}
63         contrail_repo: {get_param: ContrailRepo}
64         bond_mode: {get_param: ContrailBondMode}
65         bond_policy: {get_param: ContrailBondPolicy}
66       actions: ['CREATE'] # Only do this on CREATE
67
68   ContrailVrouterModuleConfig:
69     type: OS::Heat::SoftwareConfig
70     properties:
71       group: script
72       inputs:
73       - name: phy_int
74       - name: bond_int
75       - name: bond_int_members
76       - name: vlan_parent
77       - name: contrail_repo
78       - name: bond_mode
79       - name: bond_policy
80       config: |
81         #!/bin/bash
82         phy_int=$phy_int
83         bond_int=$bond_int
84         bond_int_members=$bond_int_members
85         bond_mode=$bond_mode
86         bond_policy=$bond_policy
87         vlan_parent=$vlan_parent
88         contrail_repo=$contrail_repo
89         if [[ ${contrail_repo} ]]; then
90           yum install -y contrail-vrouter-utils
91         fi
92         function pkt_setup () {
93             for f in /sys/class/net/$1/queues/rx-*
94             do
95                 q="$(echo $f | cut -d '-' -f2)"
96                 r=$(($q%32))
97                 s=$(($q/32))
98                 ((mask=1<<$r))
99                 str=(`printf "%x" $mask`)
100                 if [ $s -gt 0 ]; then
101                     for ((i=0; i < $s; i++))
102                     do
103                         str+=,00000000
104                     done
105                 fi
106                 echo $str > $f/rps_cpus
107             done
108             ifconfig $1 up
109         }
110         function insert_vrouter() {
111             if [ -f /sys/class/net/pkt1/queues/rx-0/rps_cpus ]; then
112                 pkt_setup pkt1
113             fi
114             if [ -f /sys/class/net/pkt2/queues/rx-0/rps_cpus ]; then
115                 pkt_setup pkt2
116             fi
117             if [ -f /sys/class/net/pkt3/queues/rx-0/rps_cpus ]; then
118                 pkt_setup pkt3
119             fi
120             DEV_MAC=$(cat /sys/class/net/${phy_int}/address)
121             vif --create vhost0 --mac $DEV_MAC
122             vif --add ${phy_int} --mac $DEV_MAC --vrf 0 --vhost-phys --type physical
123             vif --add vhost0 --mac $DEV_MAC --vrf 0 --type vhost --xconnect ${phy_int}
124             ip link set vhost0 up
125             return 0
126         }
127         if [[ ${bond_int} ]]; then
128            bond_int_member_list=$(echo ${bond_int_members} | tr "," "\n")
129            ip link add name ${bond_int} type bond
130            echo ${bond_mode} > /sys/class/net/${bond_int}/bonding/mode
131            echo ${bond_policy} > /sys/class/net/${bond_int}/bonding/xmit_hash_policy
132            for member in ${bond_int_member_list}; do
133                ip link set dev $member master ${bond_int}
134            done
135         fi
136         if [[ ${vlan_parent} ]]; then
137             vlanId=`echo ${phy_int} | awk -F"vlan" '{print $2}'`
138             ip link add name ${phy_int} link ${vlan_parent} type vlan id ${vlanId}
139         fi
140         if [[ ${contrail_repo} ]]; then
141           yumdownloader contrail-vrouter --destdir /tmp
142           cd /tmp
143           rpm2cpio /tmp/contrail-vrouter*.rpm | cpio -idmv
144           cp `find /tmp/lib/modules -name vrouter.ko |tail -1` /tmp
145           insmod /tmp/vrouter.ko
146         else
147           modprobe vrouter
148         fi
149         insert_vrouter
150         if [[ `ifconfig ${phy_int} |grep "inet "` ]]; then
151           def_gw=''
152           if [[ `ip route show |grep default|grep ${phy_int}` ]]; then
153             def_gw=`ip route show |grep default|grep ${phy_int}|awk '{print $3}'`
154           fi
155           ip=`ifconfig ${phy_int} |grep "inet "|awk '{print $2}'`
156           mask=`ifconfig ${phy_int} |grep "inet "|awk '{print $4}'`
157           ip address delete $ip/$mask dev ${phy_int}
158           ip address add $ip/$mask dev vhost0
159           if [[ $def_gw ]]; then
160             ip route add default via $def_gw
161           fi
162         fi