memcached (openstack) is no longer in use
[mirror/dsa-puppet.git] / 3rdparty / modules / nova / manifests / compute / libvirt.pp
1 # == Class: nova::compute::libvirt
2 #
3 # Install and manage nova-compute guests managed
4 # by libvirt
5 #
6 # === Parameters:
7 #
8 # [*libvirt_virt_type*]
9 #   (optional) Libvirt domain type. Options are: kvm, lxc, qemu, uml, xen
10 #   Replaces libvirt_type
11 #   Defaults to 'kvm'
12 #
13 # [*vncserver_listen*]
14 #   (optional) IP address on which instance vncservers should listen
15 #   Defaults to '127.0.0.1'
16 #
17 # [*migration_support*]
18 #   (optional) Whether to support virtual machine migration
19 #   Defaults to false
20 #
21 # [*libvirt_cpu_mode*]
22 #   (optional) The libvirt CPU mode to configure.  Possible values
23 #   include custom, host-model, none, host-passthrough.
24 #   Defaults to 'host-model' if libvirt_virt_type is set to either
25 #   kvm or qemu, otherwise defaults to 'none'.
26 #
27 # [*libvirt_disk_cachemodes*]
28 #   (optional) A list of cachemodes for different disk types, e.g.
29 #   ["file=directsync", "block=none"]
30 #   If an empty list is specified, the disk_cachemodes directive
31 #   will be removed from nova.conf completely.
32 #   Defaults to an empty list
33 #
34 # [*libvirt_inject_password*]
35 #   (optional) Inject the admin password at boot time, without an agent.
36 #   Defaults to false
37 #
38 # [*libvirt_inject_key*]
39 #   (optional) Inject the ssh public key at boot time.
40 #   Defaults to false
41 #
42 # [*libvirt_inject_partition*]
43 #   (optional) The partition to inject to : -2 => disable, -1 => inspect
44 #   (libguestfs only), 0 => not partitioned, >0 => partition
45 #   number (integer value)
46 #   Defaults to -2
47 #
48 # [*remove_unused_base_images*]
49 #   (optional) Should unused base images be removed?
50 #   If undef is specified, remove the line in nova.conf
51 #   otherwise, use a boolean to remove or not the base images.
52 #   Defaults to undef
53 #
54 # [*remove_unused_kernels*]
55 #   (optional) Should unused kernel images be removed?
56 #   This is only safe to enable if all compute nodes
57 #   have been updated to support this option.
58 #   If undef is specified, remove the line in nova.conf
59 #   otherwise, use a boolean to remove or not the kernels.
60 #   Defaults to undef
61 #
62 # [*remove_unused_resized_minimum_age_seconds*]
63 #   (optional) Unused resized base images younger
64 #   than this will not be removed
65 #   If undef is specified, remove the line in nova.conf
66 #   otherwise, use a integer or a string to define after
67 #   how many seconds it will be removed.
68 #   Defaults to undef
69 #
70 # [*remove_unused_original_minimum_age_seconds*]
71 #   (optional) Unused unresized base images younger
72 #   than this will not be removed
73 #   If undef is specified, remove the line in nova.conf
74 #   otherwise, use a integer or a string to define after
75 #   how many seconds it will be removed.
76 #   Defaults to undef
77 #
78 # [*libvirt_service_name*]
79 #   (optional) libvirt service name.
80 #   Defaults to $::nova::params::libvirt_service_name
81 #
82 class nova::compute::libvirt (
83   $libvirt_virt_type                          = 'kvm',
84   $vncserver_listen                           = '127.0.0.1',
85   $migration_support                          = false,
86   $libvirt_cpu_mode                           = false,
87   $libvirt_disk_cachemodes                    = [],
88   $libvirt_inject_password                    = false,
89   $libvirt_inject_key                         = false,
90   $libvirt_inject_partition                   = -2,
91   $remove_unused_base_images                  = undef,
92   $remove_unused_kernels                      = undef,
93   $remove_unused_resized_minimum_age_seconds  = undef,
94   $remove_unused_original_minimum_age_seconds = undef,
95   $libvirt_service_name                       = $::nova::params::libvirt_service_name,
96   # DEPRECATED PARAMETER
97   $libvirt_type                               = false
98 ) inherits nova::params {
99
100   include nova::params
101
102   Service['libvirt'] -> Service['nova-compute']
103
104   if $libvirt_type {
105     warning ('The libvirt_type parameter is deprecated, use libvirt_virt_type instead.')
106     $libvirt_virt_type_real = $libvirt_type
107   } else {
108     $libvirt_virt_type_real = $libvirt_virt_type
109   }
110
111   # libvirt_cpu_mode has different defaults depending on hypervisor.
112   if !$libvirt_cpu_mode {
113     case $libvirt_virt_type_real {
114       'kvm','qemu': {
115         $libvirt_cpu_mode_real = 'host-model'
116       }
117       default: {
118         $libvirt_cpu_mode_real = 'none'
119       }
120     }
121   } else {
122     $libvirt_cpu_mode_real = $libvirt_cpu_mode
123   }
124
125   if($::osfamily == 'Debian') {
126     package { "nova-compute-${libvirt_virt_type_real}":
127       ensure  => present,
128       before  => Package['nova-compute'],
129       require => Package['nova-common'],
130       tag     => ['openstack', 'nova'],
131     }
132   }
133
134   if($::osfamily == 'RedHat' and $::operatingsystem != 'Fedora') {
135     service { 'messagebus':
136       ensure   => running,
137       enable   => true,
138       provider => $::nova::params::special_service_provider,
139     }
140     Package['libvirt'] -> Service['messagebus'] -> Service['libvirt']
141
142   }
143
144   if $migration_support {
145     if $vncserver_listen != '0.0.0.0' and $vncserver_listen != '::0' {
146       fail('For migration support to work, you MUST set vncserver_listen to \'0.0.0.0\' or \'::0\'')
147     } else {
148       class { 'nova::migration::libvirt': }
149     }
150   }
151
152   package { 'libvirt':
153     ensure => present,
154     name   => $::nova::params::libvirt_package_name,
155   }
156
157   service { 'libvirt' :
158     ensure   => running,
159     enable   => true,
160     name     => $libvirt_service_name,
161     provider => $::nova::params::special_service_provider,
162     require  => Package['libvirt'],
163   }
164
165   nova_config {
166     'DEFAULT/compute_driver':   value => 'libvirt.LibvirtDriver';
167     'DEFAULT/vncserver_listen': value => $vncserver_listen;
168     'libvirt/virt_type':        value => $libvirt_virt_type_real;
169     'libvirt/cpu_mode':         value => $libvirt_cpu_mode_real;
170     'libvirt/inject_password':  value => $libvirt_inject_password;
171     'libvirt/inject_key':       value => $libvirt_inject_key;
172     'libvirt/inject_partition': value => $libvirt_inject_partition;
173   }
174
175   if size($libvirt_disk_cachemodes) > 0 {
176     nova_config {
177       'libvirt/disk_cachemodes': value => join($libvirt_disk_cachemodes, ',');
178     }
179   } else {
180     nova_config {
181       'libvirt/disk_cachemodes': ensure => absent;
182     }
183   }
184
185   if $remove_unused_kernels != undef {
186     nova_config {
187       'libvirt/remove_unused_kernels': value => $remove_unused_kernels;
188     }
189   } else {
190     nova_config {
191       'libvirt/remove_unused_kernels': ensure => absent;
192     }
193   }
194
195   if $remove_unused_resized_minimum_age_seconds != undef {
196     nova_config {
197       'libvirt/remove_unused_resized_minimum_age_seconds': value => $remove_unused_resized_minimum_age_seconds;
198     }
199   } else {
200     nova_config {
201       'libvirt/remove_unused_resized_minimum_age_seconds': ensure => absent;
202     }
203   }
204
205   if $remove_unused_base_images != undef {
206     nova_config {
207       'DEFAULT/remove_unused_base_images': value => $remove_unused_base_images;
208     }
209   } else {
210     nova_config {
211       'DEFAULT/remove_unused_base_images': ensure => absent;
212     }
213   }
214
215   if $remove_unused_original_minimum_age_seconds != undef {
216     nova_config {
217       'DEFAULT/remove_unused_original_minimum_age_seconds': value => $remove_unused_original_minimum_age_seconds;
218     }
219   } else {
220     nova_config {
221       'DEFAULT/remove_unused_original_minimum_age_seconds': ensure => absent;
222     }
223   }
224 }