try again, with puppetforge modules, correctly included now
[mirror/dsa-puppet.git] / 3rdparty / modules / neutron / manifests / agents / n1kv_vem.pp
1 # == Class: n1kv_vem
2 #
3 # Deploy N1KV VEM on compute and network nodes.
4 # Support exists and tested for RedHat.
5 # (For Ubuntu/Debian platforms few changes and testing pending.)
6 #
7 # === Parameters
8 # [*n1kv_vsm_ip*]
9 #   (required) N1KV VSM(Virtual Supervisor Module) VM's IP.
10 #   Defaults to 127.0.0.1
11 #
12 # [*n1kv_vsm_domainid*]
13 #   (required) N1KV VSM DomainID.
14 #   Defaults to 1000
15 #
16 # [*host_mgmt_intf*]
17 #   (required) Management Interface of node where VEM will be installed.
18 #   Defaults to eth1
19 #
20 # [*uplink_profile*]
21 #   (optional) Uplink Interfaces that will be managed by VEM. The uplink
22 #      port-profile that configures these interfaces should also be specified.
23 #   (format)
24 #    $uplink_profile = { 'eth1' => 'profile1',
25 #                        'eth2' => 'profile2'
26 #                       },
27 #   Defaults to empty
28 #
29 # [*vtep_config*]
30 #   (optional) Virtual tunnel interface configuration.
31 #              Eg:VxLAN tunnel end-points.
32 #   (format)
33 #   $vtep_config = { 'vtep1' => { 'profile' => 'virtprof1',
34 #                                 'ipmode'  => 'dhcp'
35 #                               },
36 #                    'vtep2' => { 'profile'   => 'virtprof2',
37 #                                 'ipmode'    => 'static',
38 #                                 'ipaddress' => '192.168.1.1',
39 #                                 'netmask'   => '255.255.255.0'
40 #                               }
41 #                  },
42 #   Defaults to empty
43 #
44 # [*node_type*]
45 #   (optional). Specify the type of node: 'compute' (or) 'network'.
46 #   Defaults to 'compute'
47 #
48 # All the above parameter values will be used in the config file: n1kv.conf
49 #
50 # [*vteps_in_same_subnet*]
51 #   (optional)
52 #   The VXLAN tunnel interfaces created on VEM can belong to same IP-subnet.
53 #   In such case, set this parameter to true. This results in below
54 #   'sysctl:ipv4' values to be modified.
55 #     rp_filter (reverse path filtering) set to 2(Loose).Default is 1(Strict)
56 #     arp_ignore (arp reply mode) set to 1:reply only if target ip matches
57 #                                that of incoming interface. Default is 0
58 #     arp_announce (arp announce mode) set to 1. Default is 0
59 #   Please refer Linux Documentation for detailed description
60 #   http://lxr.free-electrons.com/source/Documentation/networking/ip-sysctl.txt
61 #
62 #   If the tunnel interfaces are not in same subnet set this parameter to false.
63 #   Note that setting to false causes no change in the sysctl settings and does
64 #   not revert the changes made if it was originally set to true on a previous
65 #   catalog run.
66 #
67 #   Defaults to false
68 #
69 # [*n1kv_source*]
70 #   (optional)
71 #     n1kv_source ==> VEM package location. One of below
72 #       A)URL of yum repository that hosts VEM package.
73 #       B)VEM RPM/DPKG file name, If present locally in 'files' folder
74 #       C)If not specified, assumes that VEM image is available in
75 #         default enabled repositories.
76 #   Defaults to empty
77 #
78 # [*n1kv_version*]
79 #   (optional). Specify VEM package version to be installed.
80 #       Not applicable if 'n1kv_source' is a file. (Option-B above)
81 #   Defaults to 'present'
82 #
83 # [*package_ensure*]
84 #   (optional) Ensure state for dependent packages: Openvswitch/libnl.
85 #   Defaults to 'present'.
86 #
87 # [*enable*]
88 #   (optional) Enable state for service. Defaults to 'true'.
89 #
90 # [*manage_service*]
91 #   (optional) Whether to start/stop the service
92 #   Defaults to true
93 #
94 # [*portdb*]
95 #   (optional) PortDB (ovs|vem)
96 #   Defaults to ovs
97 #
98 # [*fastpath_flood*]
99 #   (optional) Handle broadcast floods and unknown pkts in fastpath(KLM)
100 #   Defaults to disable
101 #
102 class neutron::agents::n1kv_vem (
103   $n1kv_vsm_ip          = '127.0.0.1',
104   $n1kv_vsm_domain_id   = 1000,
105   $host_mgmt_intf       = 'eth1',
106   $uplink_profile       = {},
107   $vtep_config          = {},
108   $node_type            = 'compute',
109   $vteps_in_same_subnet = false,
110   $n1kv_source          = '',
111   $n1kv_version         = 'present',
112   $package_ensure       = 'present',
113   $enable               = true,
114   $manage_service       = true,
115   $portdb               = 'ovs',
116   $fastpath_flood       = 'disable'
117 ) {
118
119   include neutron::params
120   require vswitch::ovs
121
122   Exec { path => [ '/bin/', '/sbin/' , '/usr/bin/', '/usr/sbin/' ] }
123
124   if($::osfamily != 'Redhat') {
125     #current support exists for Redhat family.
126     #Support for Debian will be added soon.
127     fail("Unsupported osfamily ${::osfamily}")
128   }
129
130   #Check source of n1kv-vem image:yum-repo (or) local file in 'files' directory
131   if $n1kv_source != '' {
132     if ($n1kv_source =~ /^http/) or ($n1kv_source =~ /^ftp/) {
133       $vemimage_uri = 'repo'
134     } else {
135       $vemimage_uri = 'file'
136       $vemtgtimg    = "/var/n1kv/${n1kv_source}"
137     }
138   } else {
139     $vemimage_uri = 'unspec'
140   }
141
142
143   package { 'libnl':
144     ensure => $package_ensure,
145     name   => $::neutron::params::libnl_package
146   }
147
148   file {
149     '/etc/n1kv':
150       ensure => directory,
151       owner  => 'root',
152       group  => 'root',
153       mode   => '0755';
154     '/var/n1kv':
155       ensure => directory,
156       owner  => 'root',
157       group  => 'root',
158       mode   => '0755',
159   }
160
161   #specify template corresponding to 'n1kv.conf'
162   file {'/etc/n1kv/n1kv.conf':
163     ensure  => present,
164     owner   => 'root',
165     group   => 'root',
166     mode    => '0664',
167     content => template('neutron/n1kv.conf.erb'),
168     require => File['/etc/n1kv'],
169   }
170
171   if $vemimage_uri == 'file' {
172     #specify location on target-host where image file will be downloaded to.
173     #Later vem package: 'nexus1000v' will be installed from this file.
174     file { $vemtgtimg:
175       owner   => 'root',
176       group   => 'root',
177       mode    => '0664',
178       source  => "puppet:///modules/neutron/${n1kv_source}",
179       require => File['/var/n1kv'],
180     }
181     package {'nexus1000v':
182       ensure   => $n1kv_version,
183       provider => $::neutron::params::package_provider,
184       source   => $vemtgtimg,
185       require  => File[$vemtgtimg]
186     }
187   } else {
188     if $vemimage_uri == 'repo' {
189       #vem package: 'nexus1000v' will be downloaded and installed
190       #from below repo.
191       yumrepo { 'cisco-vem-repo':
192         baseurl  => $n1kv_source,
193         descr    => 'Repo for VEM Image',
194         enabled  => 1,
195         gpgcheck => 1,
196         gpgkey   => "${n1kv_source}/RPM-GPG-KEY"
197         #proxy   => '_none_',
198       }
199     }
200     package {'nexus1000v':
201       ensure => $package_ensure
202     }
203   }
204
205   if $manage_service {
206     if $enable {
207       $service_ensure = 'running'
208     } else {
209       $service_ensure = 'stopped'
210     }
211   }
212
213   service { 'nexus1000v':
214     ensure    => $service_ensure,
215   }
216
217   #Upon config change in 'n1kv.conf' execute below 'vemcmd reread config'.
218   #No need to restart service.
219   exec { 'vemcmd reread config':
220     subscribe   => File['/etc/n1kv/n1kv.conf'],
221     refreshonly => true,
222     require     => Service['nexus1000v']
223   }
224
225   if $vteps_in_same_subnet == true {
226     $my_sysctl_settings = {
227       'net.ipv4.conf.default.rp_filter'    => { value => 2 },
228       'net.ipv4.conf.all.rp_filter'        => { value => 2 },
229       'net.ipv4.conf.default.arp_ignore'   => { value => 1 },
230       'net.ipv4.conf.all.arp_ignore'       => { value => 1 },
231       'net.ipv4.conf.all.arp_announce'     => { value => 2 },
232       'net.ipv4.conf.default.arp_announce' => { value => 2 },
233     }
234     create_resources(sysctl::value,$my_sysctl_settings)
235   }
236
237   Package['libnl']            -> Package['nexus1000v']
238   Service['openvswitch']      ~> Package['nexus1000v']
239   File['/etc/n1kv/n1kv.conf'] -> Package['nexus1000v']
240   Package['nexus1000v']       ~> Service['nexus1000v']
241 }