f52b9038988b5b5a9e65818e7d1c5c9aea5bf272
[genesis.git] / common / puppet-opnfv / manifests / external_net_presetup.pp
1 #Copyright 2015 Open Platform for NFV Project, Inc. and its contributors
2 #
3 #   Licensed under the Apache License, Version 2.0 (the "License");
4 #   you may not use this file except in compliance with the License.
5 #   You may obtain a copy of the License at
6 #
7 #       http://www.apache.org/licenses/LICENSE-2.0
8 #
9 #   Unless required by applicable law or agreed to in writing, software
10 #   distributed under the License is distributed on an "AS IS" BASIS,
11 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 #   See the License for the specific language governing permissions and
13 #   limitations under the License.
14
15 class opnfv::external_net_presetup {
16
17   if $public_gateway == '' { fail('public_gateway is empty') }
18   if $public_dns == '' { fail('public_dns is empty') }
19   if $public_network == '' { fail('public_network is empty') }
20   if $public_subnet == '' { fail('public_subnet is empty') }
21   if $public_allocation_start == '' { fail('public_allocation_start is empty') }
22   if $public_allocation_end == '' { fail('public_allocation_end is empty') }
23   if !$controllers_hostnames_array { fail('controllers_hostnames_array is empty') }
24   $controllers_hostnames_array_str = $controllers_hostnames_array
25   $controllers_hostnames_array = split($controllers_hostnames_array, ',')
26
27   if ($admin_network != '') and ($admin_network != 'false') {
28     $admin_nic = get_nic_from_network("$admin_network")
29     if $admin_nic == '' { fail('admin_nic was not found') }
30     #Disable defalute route on Admin network
31     file_line { 'disable-defroute-admin':
32       path => "/etc/sysconfig/network-scripts/ifcfg-$admin_nic",
33       line  => 'DEFROUTE=no',
34       match => '^DEFROUTE',
35     }
36   }
37
38   #find public NIC
39   $public_nic = get_nic_from_network("$public_network")
40   $public_nic_ip = get_ip_from_nic("$public_nic")
41   $public_nic_netmask = get_netmask_from_nic("$public_nic")
42
43  if ($public_nic == '') or ($public_nic_ip == '') or ($public_nic == "br-ex") or ($public_nic == "br_ex") {
44   notify {"Skipping augeas, public_nic ${public_nic}, public_nic_ip ${public_nic_ip}":}
45
46   exec {'ovs-vsctl -t 10 -- --may-exist add-br br-ex':
47        path         => ["/usr/sbin/", "/usr/bin/"],
48        unless       => 'ip addr show br-ex | grep "inet "',
49        before       => Exec['restart-network-public-nic-ip'],
50   }
51   ~>
52   exec {'systemctl restart network':
53        path         => ["/usr/sbin/", "/usr/bin/"],
54        refreshonly  => 'true',
55   }
56
57   exec {'restart-network-public-nic-ip':
58        command      => 'systemctl restart network',
59        path         => ["/usr/sbin/", "/usr/bin/"],
60        onlyif       => 'ip addr show | grep $(ip addr show br-ex | grep -Eo "inet [\.0-9]+" | cut -d " " -f2) | grep -v br-ex',
61   }
62
63  } else {
64   #reconfigure public interface to be ovsport
65   augeas { "main-$public_nic":
66         context => "/files/etc/sysconfig/network-scripts/ifcfg-$public_nic",
67         changes => [
68                 "rm IPADDR",
69                 "rm NETMASK",
70                 "rm GATEWAY",
71                 "rm DNS1",
72                 "rm BOOTPROTO",
73                 "rm DEFROUTE",
74                 "rm IPV6_DEFROUTE",
75                 "rm IPV6_PEERDNS",
76                 "rm IPV6_PEERROUTES",
77                 "rm PEERROUTES",
78                 "set PEERDNS no",
79                 "set BOOTPROTO static",
80                 "set IPV6INIT no",
81                 "set IPV6_AUTOCONF no",
82                 "set ONBOOT yes",
83                 "set TYPE OVSPort",
84                 "set OVS_BRIDGE br-ex",
85                 "set PROMISC yes"
86
87         ],
88         before  => Class["quickstack::pacemaker::params"],
89         require => Service["openvswitch"],
90   }
91
92   ->
93   #create br-ex interface
94   file { 'external_bridge':
95         path => '/etc/sysconfig/network-scripts/ifcfg-br-ex',
96         owner   => 'root',
97         group   => 'root',
98         mode    => '0644',
99         content => template('opnfv/br_ex.erb'),
100         before  => Class["quickstack::pacemaker::params"],
101   }
102   ->
103   exec {'ovs-vsctl -t 10 -- --may-exist add-br br-ex':
104        path         => ["/usr/sbin/", "/usr/bin/"],
105   }
106   ~>
107   exec {'systemctl restart network':
108        path         => ["/usr/sbin/", "/usr/bin/"],
109        refreshonly  => 'true',
110   }
111
112  }
113 }