af00f203e26139218afa1827a8baf2870791f296
[genesis.git] / common / puppet-opnfv / manifests / external_net_setup.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_setup {
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   #find public NIC
28   $public_nic = get_nic_from_network("$public_network")
29   $public_nic_ip = get_ip_from_nic("$public_nic")
30   $public_nic_netmask = get_netmask_from_nic("$public_nic")
31
32   Anchor[ 'neutron configuration anchor end' ]
33   ->
34   #update bridge-mappings to physnet1
35   file_line { 'ovs':
36     ensure  => present,
37     path    => '/etc/neutron/plugin.ini',
38     line    => '[ovs]',
39   }
40   ->
41   #update bridge-mappings to physnet1
42   file_line { 'bridge_mapping':
43     ensure  => present,
44     path    => '/etc/neutron/plugin.ini',
45     line    => 'bridge_mappings = physnet1:br-ex',
46   }
47   ->
48   Exec["pcs-neutron-server-set-up"]
49
50 ##this way we only let controller1 create the neutron resources
51 ##controller1 should be the active neutron-server at provisioining time
52
53  if $hostname == $controllers_hostnames_array[0] {
54   Exec["all-neutron-nodes-are-up"]
55   ->
56   neutron_network { 'provider_network':
57     ensure                    => present,
58     name                      => 'provider_network',
59     admin_state_up            => true,
60     provider_network_type     => flat,
61     provider_physical_network => 'physnet1',
62     router_external           => true,
63     tenant_name               => 'admin',
64   }
65   ->
66   neutron_subnet { 'provider_subnet':
67     ensure            => present,
68     name              => provider_subnet,
69     cidr              => $public_subnet,
70     gateway_ip        => $public_gateway,
71     allocation_pools  => [ "start=${public_allocation_start},end=${public_allocation_end}" ],
72     dns_nameservers   => $public_dns,
73     network_name      => 'provider_network',
74     tenant_name       => 'admin',
75   }
76   ->
77   neutron_router { 'provider_router':
78     ensure               => present,
79     name                 => 'provider_router',
80     admin_state_up       => true,
81     gateway_network_name => 'provider_network',
82     tenant_name          => 'admin',
83   }
84  }
85 }