libvirt.pp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. # == Class: nova::migration::libvirt
  2. #
  3. # Sets libvirt config that is required for migration
  4. #
  5. # === Parameters:
  6. #
  7. # [*use_tls*]
  8. # (optional) Use tls for remote connections to libvirt
  9. # Defaults to false
  10. #
  11. # [*auth*]
  12. # (optional) Use this authentication scheme for remote libvirt connections.
  13. # Valid options are none and sasl.
  14. # Defaults to 'none'
  15. #
  16. # [*live_migration_tunnelled*]
  17. # (optional) Whether to use tunnelled migration, where migration data is
  18. # transported over the libvirtd connection.
  19. # If True, we use the VIR_MIGRATE_TUNNELLED migration flag, avoiding the
  20. # need to configure the network to allow direct hypervisor to hypervisor
  21. # communication.
  22. # If False, use the native transport.
  23. # If not set, Nova will choose a sensible default based on, for example
  24. # the availability of native encryption support in the hypervisor.
  25. # Defaults to $::os_service_default
  26. #
  27. # [*live_migration_completion_timeout*]
  28. # (optional) Time to wait, in seconds, for migration to successfully complete
  29. # transferring data before aborting the operation. Value is per GiB of guest
  30. # RAM + disk to be transferred, with lower bound of a minimum of 2 GiB. Set
  31. # to 0 to disable timeouts.
  32. # Defaults to $::os_service_default
  33. #
  34. # [*live_migration_progress_timeout*]
  35. # (optional) Time to wait, in seconds, for migration to make forward progress
  36. # in transferring data before aborting the operation. Set to 0 to disable
  37. # timeouts.
  38. # Defaults to $::os_service_default
  39. #
  40. # [*override_uuid*]
  41. # (optional) Set uuid not equal to output from dmidecode (boolean)
  42. # Defaults to false
  43. #
  44. # [*configure_libvirt*]
  45. # (optional) Whether or not configure libvirt bits.
  46. # Defaults to true.
  47. #
  48. # [*configure_nova*]
  49. # (optional) Whether or not configure libvirt bits.
  50. # Defaults to true.
  51. #
  52. class nova::migration::libvirt(
  53. $use_tls = false,
  54. $auth = 'none',
  55. $live_migration_tunnelled = $::os_service_default,
  56. $live_migration_completion_timeout = $::os_service_default,
  57. $live_migration_progress_timeout = $::os_service_default,
  58. $override_uuid = false,
  59. $configure_libvirt = true,
  60. $configure_nova = true,
  61. ){
  62. include ::nova::deps
  63. validate_re($auth, [ '^sasl$', '^none$' ], 'Valid options for auth are none and sasl.')
  64. if $use_tls {
  65. $listen_tls = '1'
  66. $listen_tcp = '0'
  67. } else {
  68. $listen_tls = '0'
  69. $listen_tcp = '1'
  70. }
  71. if $configure_nova {
  72. if $use_tls {
  73. nova_config {
  74. 'libvirt/live_migration_uri': value => 'qemu+tls://%s/system';
  75. }
  76. }
  77. nova_config {
  78. 'libvirt/live_migration_tunnelled': value => $live_migration_tunnelled;
  79. 'libvirt/live_migration_completion_timeout': value => $live_migration_completion_timeout;
  80. 'libvirt/live_migration_progress_timeout': value => $live_migration_progress_timeout;
  81. }
  82. }
  83. if $configure_libvirt {
  84. Anchor['nova::config::begin']
  85. -> File_line<| tag == 'libvirt-file_line'|>
  86. -> Anchor['nova::config::end']
  87. File_line<| tag == 'libvirt-file_line' |>
  88. ~> Service['libvirt']
  89. if $override_uuid {
  90. if ! $::libvirt_uuid {
  91. $host_uuid = generate('/bin/cat', '/proc/sys/kernel/random/uuid')
  92. file { '/etc/libvirt/libvirt_uuid':
  93. content => $host_uuid,
  94. require => Package['libvirt'],
  95. }
  96. } else {
  97. $host_uuid = $::libvirt_uuid
  98. }
  99. augeas { 'libvirt-conf-uuid':
  100. context => '/files/etc/libvirt/libvirtd.conf',
  101. changes => [
  102. "set host_uuid ${host_uuid}",
  103. ],
  104. notify => Service['libvirt'],
  105. require => Package['libvirt'],
  106. }
  107. }
  108. case $::osfamily {
  109. 'RedHat': {
  110. file_line { '/etc/libvirt/libvirtd.conf listen_tls':
  111. path => '/etc/libvirt/libvirtd.conf',
  112. line => "listen_tls = ${listen_tls}",
  113. match => 'listen_tls =',
  114. tag => 'libvirt-file_line',
  115. }
  116. file_line { '/etc/libvirt/libvirtd.conf listen_tcp':
  117. path => '/etc/libvirt/libvirtd.conf',
  118. line => "listen_tcp = ${listen_tcp}",
  119. match => 'listen_tcp =',
  120. tag => 'libvirt-file_line',
  121. }
  122. if $use_tls {
  123. file_line { '/etc/libvirt/libvirtd.conf auth_tls':
  124. path => '/etc/libvirt/libvirtd.conf',
  125. line => "auth_tls = \"${auth}\"",
  126. match => 'auth_tls =',
  127. tag => 'libvirt-file_line',
  128. }
  129. } else {
  130. file_line { '/etc/libvirt/libvirtd.conf auth_tcp':
  131. path => '/etc/libvirt/libvirtd.conf',
  132. line => "auth_tcp = \"${auth}\"",
  133. match => 'auth_tcp =',
  134. tag => 'libvirt-file_line',
  135. }
  136. }
  137. file_line { '/etc/sysconfig/libvirtd libvirtd args':
  138. path => '/etc/sysconfig/libvirtd',
  139. line => 'LIBVIRTD_ARGS="--listen"',
  140. match => 'LIBVIRTD_ARGS=',
  141. tag => 'libvirt-file_line',
  142. }
  143. }
  144. 'Debian': {
  145. file_line { '/etc/libvirt/libvirtd.conf listen_tls':
  146. path => '/etc/libvirt/libvirtd.conf',
  147. line => "listen_tls = ${listen_tls}",
  148. match => 'listen_tls =',
  149. tag => 'libvirt-file_line',
  150. }
  151. file_line { '/etc/libvirt/libvirtd.conf listen_tcp':
  152. path => '/etc/libvirt/libvirtd.conf',
  153. line => "listen_tcp = ${listen_tcp}",
  154. match => 'listen_tcp =',
  155. tag => 'libvirt-file_line',
  156. }
  157. if $use_tls {
  158. file_line { '/etc/libvirt/libvirtd.conf auth_tls':
  159. path => '/etc/libvirt/libvirtd.conf',
  160. line => "auth_tls = \"${auth}\"",
  161. match => 'auth_tls =',
  162. tag => 'libvirt-file_line',
  163. }
  164. } else {
  165. file_line { '/etc/libvirt/libvirtd.conf auth_tcp':
  166. path => '/etc/libvirt/libvirtd.conf',
  167. line => "auth_tcp = \"${auth}\"",
  168. match => 'auth_tcp =',
  169. tag => 'libvirt-file_line',
  170. }
  171. }
  172. if $::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemmajrelease, '16') >= 0 {
  173. # If systemd is being used then libvirtd is already being launched correctly and
  174. # adding -d causes a second consecutive start to fail which causes puppet to fail.
  175. $libvirtd_opts = 'libvirtd_opts="-l"'
  176. } else {
  177. $libvirtd_opts = 'libvirtd_opts="-d -l"'
  178. }
  179. file_line { "/etc/default/${::nova::compute::libvirt::libvirt_service_name} libvirtd opts":
  180. path => "/etc/default/${::nova::compute::libvirt::libvirt_service_name}",
  181. line => $libvirtd_opts,
  182. match => 'libvirtd_opts=',
  183. tag => 'libvirt-file_line',
  184. }
  185. }
  186. default: {
  187. warning("Unsupported osfamily: ${::osfamily}, make sure you are configuring this yourself")
  188. }
  189. }
  190. }
  191. }