libvirt.pp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. # == Class: nova::compute::libvirt
  2. #
  3. # Install and manage nova-compute guests managed
  4. # by libvirt
  5. #
  6. # === Parameters:
  7. #
  8. # [*ensure_package*]
  9. # (optional) The state of nova packages
  10. # Defaults to 'present'
  11. #
  12. # [*libvirt_virt_type*]
  13. # (optional) Libvirt domain type. Options are: kvm, lxc, qemu, uml, xen
  14. # Defaults to 'kvm'
  15. #
  16. # [*vncserver_listen*]
  17. # (optional) IP address on which instance vncservers should listen
  18. # Defaults to '127.0.0.1'
  19. #
  20. # [*migration_support*]
  21. # (optional) Whether to support virtual machine migration
  22. # Defaults to false
  23. #
  24. # [*libvirt_cpu_mode*]
  25. # (optional) The libvirt CPU mode to configure. Possible values
  26. # include custom, host-model, none, host-passthrough.
  27. # Defaults to 'host-model' if libvirt_virt_type is set to kvm,
  28. # otherwise defaults to 'none'.
  29. #
  30. # [*libvirt_cpu_model*]
  31. # (optional) The named libvirt CPU model (see names listed in
  32. # /usr/share/libvirt/cpu_map.xml). Only has effect if
  33. # cpu_mode="custom" and virt_type="kvm|qemu".
  34. # Defaults to undef
  35. #
  36. # [*libvirt_disk_cachemodes*]
  37. # (optional) A list of cachemodes for different disk types, e.g.
  38. # ["file=directsync", "block=none"]
  39. # If an empty list is specified, the disk_cachemodes directive
  40. # will be removed from nova.conf completely.
  41. # Defaults to an empty list
  42. #
  43. # [*libvirt_hw_disk_discard*]
  44. # (optional) Discard option for nova managed disks. Need Libvirt(1.0.6)
  45. # Qemu1.5 (raw format) Qemu1.6(qcow2 format).
  46. # Defaults to $::os_service_default
  47. #
  48. # [*libvirt_hw_machine_type*]
  49. # (optional) Option to specify a default machine type per host architecture.
  50. # Defaults to $::os_service_default
  51. #
  52. # [*libvirt_inject_password*]
  53. # (optional) Inject the admin password at boot time, without an agent.
  54. # Defaults to false
  55. #
  56. # [*libvirt_inject_key*]
  57. # (optional) Inject the ssh public key at boot time.
  58. # Defaults to false
  59. #
  60. # [*libvirt_inject_partition*]
  61. # (optional) The partition to inject to : -2 => disable, -1 => inspect
  62. # (libguestfs only), 0 => not partitioned, >0 => partition
  63. # number (integer value)
  64. # Defaults to -2
  65. #
  66. # [*libvirt_enabled_perf_events*]
  67. # (optional) This is a performance event list which could be used as monitor.
  68. # A string list. For example: ``enabled_perf_events = cmt, mbml, mbmt``
  69. # The supported events list can be found in
  70. # https://libvirt.org/html/libvirt-libvirt-domain.html ,
  71. # which you may need to search key words ``VIR_PERF_PARAM_*``
  72. # Defaults to $::os_service_default
  73. #
  74. # [*remove_unused_base_images*]
  75. # (optional) Should unused base images be removed?
  76. # If undef is specified, remove the line in nova.conf
  77. # otherwise, use a boolean to remove or not the base images.
  78. # Defaults to undef
  79. #
  80. # [*remove_unused_resized_minimum_age_seconds*]
  81. # (optional) Unused resized base images younger
  82. # than this will not be removed
  83. # If undef is specified, remove the line in nova.conf
  84. # otherwise, use a integer or a string to define after
  85. # how many seconds it will be removed.
  86. # Defaults to undef
  87. #
  88. # [*remove_unused_original_minimum_age_seconds*]
  89. # (optional) Unused unresized base images younger
  90. # than this will not be removed
  91. # If undef is specified, remove the line in nova.conf
  92. # otherwise, use a integer or a string to define after
  93. # how many seconds it will be removed.
  94. # Defaults to undef
  95. #
  96. # [*libvirt_service_name*]
  97. # (optional) libvirt service name.
  98. # Defaults to $::nova::params::libvirt_service_name
  99. #
  100. # [*virtlock_service_name*]
  101. # (optional) virtlock service name.
  102. # Defaults to $::nova::params::virtlock_service_name
  103. #
  104. # [*virtlog_service_name*]
  105. # (optional) virtlog service name.
  106. # Defaults to $::nova::params::virtlog_service_name
  107. #
  108. # [*compute_driver*]
  109. # (optional) Compute driver.
  110. # Defaults to 'libvirt.LibvirtDriver'
  111. #
  112. # [*preallocate_images*]
  113. # (optional) The image preallocation mode to use.
  114. # Valid values are 'none' or 'space'.
  115. # Defaults to $::os_service_default
  116. #
  117. # [*manage_libvirt_services*]
  118. # (optional) Whether or not deploy Libvirt services.
  119. # In the case of micro-services, set it to False and use
  120. # nova::compute::libvirt::services + hiera to select what
  121. # you actually want to deploy.
  122. # Defaults to true for backward compatibility.
  123. #
  124. class nova::compute::libvirt (
  125. $ensure_package = 'present',
  126. $libvirt_virt_type = 'kvm',
  127. $vncserver_listen = '127.0.0.1',
  128. $migration_support = false,
  129. $libvirt_cpu_mode = false,
  130. $libvirt_cpu_model = undef,
  131. $libvirt_disk_cachemodes = [],
  132. $libvirt_hw_disk_discard = $::os_service_default,
  133. $libvirt_hw_machine_type = $::os_service_default,
  134. $libvirt_inject_password = false,
  135. $libvirt_inject_key = false,
  136. $libvirt_inject_partition = -2,
  137. $libvirt_enabled_perf_events = $::os_service_default,
  138. $remove_unused_base_images = undef,
  139. $remove_unused_resized_minimum_age_seconds = undef,
  140. $remove_unused_original_minimum_age_seconds = undef,
  141. $libvirt_service_name = $::nova::params::libvirt_service_name,
  142. $virtlock_service_name = $::nova::params::virtlock_service_name,
  143. $virtlog_service_name = $::nova::params::virtlog_service_name,
  144. $compute_driver = 'libvirt.LibvirtDriver',
  145. $preallocate_images = $::os_service_default,
  146. $manage_libvirt_services = true,
  147. ) inherits nova::params {
  148. include ::nova::deps
  149. include ::nova::params
  150. # libvirt_cpu_mode has different defaults depending on hypervisor.
  151. if !$libvirt_cpu_mode {
  152. case $libvirt_virt_type {
  153. 'kvm': {
  154. $libvirt_cpu_mode_real = 'host-model'
  155. }
  156. default: {
  157. $libvirt_cpu_mode_real = 'none'
  158. }
  159. }
  160. } else {
  161. $libvirt_cpu_mode_real = $libvirt_cpu_mode
  162. }
  163. if($::osfamily == 'Debian') {
  164. package { "nova-compute-${libvirt_virt_type}":
  165. ensure => $ensure_package,
  166. tag => ['openstack', 'nova-package'],
  167. }
  168. }
  169. if $migration_support {
  170. include ::nova::migration::libvirt
  171. }
  172. # manage_libvirt_services is here for backward compatibility to support
  173. # deployments that do not include nova::compute::libvirt::services
  174. #
  175. # If you're using hiera:
  176. # - set nova::compute::libvirt::manage_libvirt_services to false
  177. # - include ::nova::compute::libvirt::services in your composition layer
  178. # - select which services you want to deploy with
  179. # ::nova::compute::libvirt::services:* parameters.
  180. #
  181. # If you're not using hiera:
  182. # - set nova::compute::libvirt::manage_libvirt_services to true (default).
  183. # - select which services you want to deploy with
  184. # ::nova::compute::libvirt::*_service_name parameters.
  185. if $manage_libvirt_services {
  186. class { '::nova::compute::libvirt::services':
  187. libvirt_service_name => $libvirt_service_name,
  188. virtlock_service_name => $virtlock_service_name,
  189. virtlog_service_name => $virtlog_service_name,
  190. libvirt_virt_type => $libvirt_virt_type,
  191. }
  192. }
  193. nova_config {
  194. 'DEFAULT/compute_driver': value => $compute_driver;
  195. 'DEFAULT/preallocate_images': value => $preallocate_images;
  196. 'vnc/vncserver_listen': value => $vncserver_listen;
  197. 'libvirt/virt_type': value => $libvirt_virt_type;
  198. 'libvirt/cpu_mode': value => $libvirt_cpu_mode_real;
  199. 'libvirt/inject_password': value => $libvirt_inject_password;
  200. 'libvirt/inject_key': value => $libvirt_inject_key;
  201. 'libvirt/inject_partition': value => $libvirt_inject_partition;
  202. 'libvirt/hw_disk_discard': value => $libvirt_hw_disk_discard;
  203. 'libvirt/hw_machine_type': value => $libvirt_hw_machine_type;
  204. 'libvirt/enabled_perf_events': value => $libvirt_enabled_perf_events;
  205. }
  206. # cpu_model param is only valid if cpu_mode=custom
  207. # otherwise it should be commented out
  208. if $libvirt_cpu_mode_real == 'custom' {
  209. validate_string($libvirt_cpu_model)
  210. nova_config {
  211. 'libvirt/cpu_model': value => $libvirt_cpu_model;
  212. }
  213. } else {
  214. nova_config {
  215. 'libvirt/cpu_model': ensure => absent;
  216. }
  217. if $libvirt_cpu_model {
  218. warning('$libvirt_cpu_model requires that $libvirt_cpu_mode => "custom" and will be ignored')
  219. }
  220. }
  221. if size($libvirt_disk_cachemodes) > 0 {
  222. nova_config {
  223. 'libvirt/disk_cachemodes': value => join($libvirt_disk_cachemodes, ',');
  224. }
  225. } else {
  226. nova_config {
  227. 'libvirt/disk_cachemodes': ensure => absent;
  228. }
  229. }
  230. if $remove_unused_resized_minimum_age_seconds != undef {
  231. nova_config {
  232. 'libvirt/remove_unused_resized_minimum_age_seconds': value => $remove_unused_resized_minimum_age_seconds;
  233. }
  234. } else {
  235. nova_config {
  236. 'libvirt/remove_unused_resized_minimum_age_seconds': ensure => absent;
  237. }
  238. }
  239. if $remove_unused_base_images != undef {
  240. nova_config {
  241. 'DEFAULT/remove_unused_base_images': value => $remove_unused_base_images;
  242. }
  243. } else {
  244. nova_config {
  245. 'DEFAULT/remove_unused_base_images': ensure => absent;
  246. }
  247. }
  248. if $remove_unused_original_minimum_age_seconds != undef {
  249. nova_config {
  250. 'DEFAULT/remove_unused_original_minimum_age_seconds': value => $remove_unused_original_minimum_age_seconds;
  251. }
  252. } else {
  253. nova_config {
  254. 'DEFAULT/remove_unused_original_minimum_age_seconds': ensure => absent;
  255. }
  256. }
  257. }