256d1bee305f68a3bfa687077d70cb1c3f3db545
[mirror/dsa-puppet.git] / 3rdparty / modules / neutron / manifests / agents / dhcp.pp
1 # == Class: neutron::agents::dhcp
2 #
3 # Setups Neutron DHCP agent.
4 #
5 # === Parameters
6 #
7 # [*package_ensure*]
8 #   (optional) Ensure state for package. Defaults to 'present'.
9 #
10 # [*enabled*]
11 #   (optional) Enable state for service. Defaults to 'true'.
12 #
13 # [*manage_service*]
14 #   (optional) Whether to start/stop the service
15 #   Defaults to true
16 #
17 # [*debug*]
18 #   (optional) Show debugging output in log. Defaults to false.
19 #
20 # [*state_path*]
21 #   (optional) Where to store dnsmasq state files. This directory must be
22 #   writable by the user executing the agent. Defaults to '/var/lib/neutron'.
23 #
24 # [*resync_interval*]
25 #   (optional) The DHCP agent will resync its state with Neutron to recover
26 #   from any transient notification or rpc errors. The interval is number of
27 #   seconds between attempts. Defaults to 30.
28 #
29 # [*interface_driver*]
30 #   (optional) Defaults to 'neutron.agent.linux.interface.OVSInterfaceDriver'.
31 #
32 # [*dhcp_driver*]
33 #   (optional) Defaults to 'neutron.agent.linux.dhcp.Dnsmasq'.
34 #
35 # [*root_helper*]
36 #   (optional) Defaults to 'sudo neutron-rootwrap /etc/neutron/rootwrap.conf'.
37 #   Addresses bug: https://bugs.launchpad.net/neutron/+bug/1182616
38 #   Note: This can safely be removed once the module only targets the Havana release.
39 #
40 # [*use_namespaces*]
41 #   (optional) Allow overlapping IP (Must have kernel build with
42 #   CONFIG_NET_NS=y and iproute2 package that supports namespaces).
43 #   Defaults to true.
44 #
45 # [*dnsmasq_config_file*]
46 #   (optional) Override the default dnsmasq settings with this file.
47 #   Defaults to undef
48 #
49 # [*dhcp_delete_namespaces*]
50 #   (optional) Delete namespace after removing a dhcp server
51 #   Defaults to false.
52 #
53 # [*enable_isolated_metadata*]
54 #   (optional) enable metadata support on isolated networks.
55 #   Defaults to false.
56 #
57 # [*enable_metadata_network*]
58 #   (optional) Allows for serving metadata requests coming from a dedicated metadata
59 #   access network whose cidr is 169.254.169.254/16 (or larger prefix), and is
60 #   connected to a Neutron router from which the VMs send metadata request.
61 #   This option requires enable_isolated_metadata = True
62 #   Defaults to false.
63 #
64 class neutron::agents::dhcp (
65   $package_ensure         = present,
66   $enabled                = true,
67   $manage_service         = true,
68   $debug                  = false,
69   $state_path             = '/var/lib/neutron',
70   $resync_interval        = 30,
71   $interface_driver       = 'neutron.agent.linux.interface.OVSInterfaceDriver',
72   $dhcp_driver            = 'neutron.agent.linux.dhcp.Dnsmasq',
73   $root_helper            = 'sudo neutron-rootwrap /etc/neutron/rootwrap.conf',
74   $use_namespaces         = true,
75   $dnsmasq_config_file    = undef,
76   $dhcp_delete_namespaces = false,
77   $enable_isolated_metadata = false,
78   $enable_metadata_network  = false
79 ) {
80
81   include neutron::params
82
83   Neutron_config<||>            ~> Service['neutron-dhcp-service']
84   Neutron_dhcp_agent_config<||> ~> Service['neutron-dhcp-service']
85
86   case $dhcp_driver {
87     /\.Dnsmasq/: {
88       Package[$::neutron::params::dnsmasq_packages] -> Package<| title == 'neutron-dhcp-agent' |>
89       ensure_packages($::neutron::params::dnsmasq_packages)
90     }
91     /^midonet.*/: {
92       ensure_packages($::neutron::params::midonet_server_package)
93     }
94     default: {
95       fail("Unsupported dhcp_driver ${dhcp_driver}")
96     }
97   }
98
99   if (! $enable_isolated_metadata) and $enable_metadata_network {
100     fail('enable_metadata_network to true requires enable_isolated_metadata also enabled.')
101   } else {
102     neutron_dhcp_agent_config {
103       'DEFAULT/enable_isolated_metadata': value => $enable_isolated_metadata;
104       'DEFAULT/enable_metadata_network':  value => $enable_metadata_network;
105     }
106   }
107
108   # The DHCP agent loads both neutron.ini and its own file.
109   # This only lists config specific to the agent.  neutron.ini supplies
110   # the rest.
111   neutron_dhcp_agent_config {
112     'DEFAULT/debug':                  value => $debug;
113     'DEFAULT/state_path':             value => $state_path;
114     'DEFAULT/resync_interval':        value => $resync_interval;
115     'DEFAULT/interface_driver':       value => $interface_driver;
116     'DEFAULT/dhcp_driver':            value => $dhcp_driver;
117     'DEFAULT/use_namespaces':         value => $use_namespaces;
118     'DEFAULT/root_helper':            value => $root_helper;
119     'DEFAULT/dhcp_delete_namespaces': value => $dhcp_delete_namespaces;
120   }
121
122   if $dnsmasq_config_file {
123     neutron_dhcp_agent_config {
124       'DEFAULT/dnsmasq_config_file':           value => $dnsmasq_config_file;
125     }
126   } else {
127     neutron_dhcp_agent_config {
128       'DEFAULT/dnsmasq_config_file':           ensure => absent;
129     }
130   }
131
132   if $::neutron::params::dhcp_agent_package {
133     Package['neutron']            -> Package['neutron-dhcp-agent']
134     Package['neutron-dhcp-agent'] -> Neutron_config<||>
135     Package['neutron-dhcp-agent'] -> Neutron_dhcp_agent_config<||>
136     package { 'neutron-dhcp-agent':
137       ensure  => $package_ensure,
138       name    => $::neutron::params::dhcp_agent_package,
139     }
140   } else {
141     # Some platforms (RedHat) do not provide a neutron DHCP agent package.
142     # The neutron DHCP agent config file is provided by the neutron package.
143     Package['neutron'] -> Neutron_dhcp_agent_config<||>
144   }
145
146   if $manage_service {
147     if $enabled {
148       $service_ensure = 'running'
149     } else {
150       $service_ensure = 'stopped'
151     }
152   }
153
154   service { 'neutron-dhcp-service':
155     ensure  => $service_ensure,
156     name    => $::neutron::params::dhcp_agent_service,
157     enable  => $enabled,
158     require => Class['neutron'],
159   }
160 }