Puppet Class: nova::migration::libvirt

Inherits:
nova::compute::libvirt::version
Defined in:
manifests/migration/libvirt.pp

Overview

Class: nova::migration::libvirt

Sets libvirt config that is required for migration

Parameters:

manage_service

(optional) Whether to start/stop the service Defaults to true

transport

(optional) Transport to use for live-migration. Valid options are ‘tcp’, ‘tls’, and ‘ssh’. Defaults to ‘tcp’

auth

(optional) Use this authentication scheme for remote libvirt connections. Valid options are none and sasl. Defaults to ‘none’

listen_address

(optional) Bind libvirtd tcp/tls socket to the given address. Defaults to $::os_service_default (bind to all addresses)

live_migration_inbound_addr

(optional) The IP address or hostname to be used as the target for live migration traffic. Defaults to $::os_service_default

live_migration_tunnelled

(optional) Whether to use tunnelled migration, where migration data is transported over the libvirtd connection. If True, we use the VIR_MIGRATE_TUNNELLED migration flag, avoiding the need to configure the network to allow direct hypervisor to hypervisor communication. If False, use the native transport. If not set, Nova will choose a sensible default based on, for example the availability of native encryption support in the hypervisor. Defaults to $::os_service_default

live_migration_with_native_tls

(optional) This option will allow both migration stream (guest RAM plus device state) and disk stream to be transported over native TLS, i.e. TLS support built into QEMU. Prerequisite: TLS environment is configured correctly on all relevant Compute nodes. This means, Certificate Authority (CA), server, client certificates, their corresponding keys, and their file permissions are in place, and are validated. Defaults to $::os_service_default

live_migration_completion_timeout

(optional) Time to wait, in seconds, for migration to successfully complete transferring data before aborting the operation. Value is per GiB of guest RAM + disk to be transferred, with lower bound of a minimum of 2 GiB. Set to 0 to disable timeouts. Defaults to $::os_service_default

live_migration_timeout_action

(optional) This option will be used to determine what action will be taken against a VM after live_migration_completion_timeout expires. By default, the live migrate operation will be aborted after completion timeout. If it is set to force_complete, the compute service will either pause the VM or trigger post-copy depending on if post copy is enabled and available Defaults to $::os_service_default

live_migration_permit_post_copy

(optional) This option allows nova to switch an on-going live migration to post-copy mode, i.e., switch the active VM to the one on the destination node before the migration is complete, therefore ensuring an upper bound on the memory that needs to be transferred. Post-copy requires libvirt>=1.3.3 and QEMU>=2.5.0. Defaults to $::os_service_default

live_migration_permit_auto_converge

(optional) This option allows nova to start live migration with auto converge on. Auto converge throttles down CPU if a progress of on-going live migration is slow. Auto converge will only be used if this flag is set to True and post copy is not permitted or post copy is unavailable due to the version of libvirt and QEMU in use. Defaults to $::os_service_default

override_uuid

(optional) Set uuid not equal to output from dmidecode (boolean) Defaults to false

host_uuid

(optional) Set host_uuid to this value, instead of generating a random uuid, if override_uuid is set to true. Defaults to undef

configure_libvirt

(optional) Whether or not configure libvirt bits. Defaults to true.

configure_nova

(optional) Whether or not configure libvirt bits. Defaults to true.

client_user

(optional) Remote user to connect as. Only applies to ssh transport. Defaults to undef (root)

client_port

(optional) Remote port to connect to. Defaults to undef (default port for the transport)

client_extraparams

(optional) Hash of additional params to append to the live-migration uri See libvirt.org/guide/html/Application_Development_Guide-Architecture-Remote_URIs.html Defaults to {}

ca_file

(optional) Specifies the CA certificate that the TLS transport will use. Note that this is only used if the TLS transport is enabled via the “transport” option. Defaults to $::os_service_default

crl_file

(optional) Specifies the CRL file that the TLS transport will use. Note that this is only used if the TLS transport is enabled via the “transport” option. Defaults to $::os_service_default

libvirt_version

(optional) installed libvirt version. Default is automatic detected depending of the used OS installed via ::nova::compute::libvirt::version::default . Defaults to ::nova::compute::libvirt::version::default

modular_libvirt

(optional) Whether to enable modular libvirt daemons or use monolithic libvirt daemon. Defaults to undef

Parameters:

  • manage_service (Any) (defaults to: true)
  • transport (Any) (defaults to: undef)
  • auth (Any) (defaults to: 'none')
  • listen_address (Any) (defaults to: $::os_service_default)
  • live_migration_inbound_addr (Any) (defaults to: $::os_service_default)
  • live_migration_tunnelled (Any) (defaults to: $::os_service_default)
  • live_migration_with_native_tls (Any) (defaults to: $::os_service_default)
  • live_migration_completion_timeout (Any) (defaults to: $::os_service_default)
  • live_migration_timeout_action (Any) (defaults to: $::os_service_default)
  • live_migration_permit_post_copy (Any) (defaults to: $::os_service_default)
  • live_migration_permit_auto_converge (Any) (defaults to: $::os_service_default)
  • override_uuid (Any) (defaults to: false)
  • host_uuid (Any) (defaults to: undef)
  • configure_libvirt (Any) (defaults to: true)
  • configure_nova (Any) (defaults to: true)
  • client_user (Any) (defaults to: undef)
  • client_port (Any) (defaults to: undef)
  • client_extraparams (Any) (defaults to: {})
  • ca_file (Any) (defaults to: $::os_service_default)
  • crl_file (Any) (defaults to: $::os_service_default)
  • libvirt_version (Any) (defaults to: $::nova::compute::libvirt::version::default)
  • modular_libvirt (Any) (defaults to: undef)


135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
# File 'manifests/migration/libvirt.pp', line 135

class nova::migration::libvirt(
  $manage_service                      = true,
  $transport                           = undef,
  $auth                                = 'none',
  $listen_address                      = $::os_service_default,
  $live_migration_inbound_addr         = $::os_service_default,
  $live_migration_tunnelled            = $::os_service_default,
  $live_migration_with_native_tls      = $::os_service_default,
  $live_migration_completion_timeout   = $::os_service_default,
  $live_migration_timeout_action       = $::os_service_default,
  $live_migration_permit_post_copy     = $::os_service_default,
  $live_migration_permit_auto_converge = $::os_service_default,
  $override_uuid                       = false,
  $host_uuid                           = undef,
  $configure_libvirt                   = true,
  $configure_nova                      = true,
  $client_user                         = undef,
  $client_port                         = undef,
  $client_extraparams                  = {},
  $ca_file                             = $::os_service_default,
  $crl_file                            = $::os_service_default,
  $libvirt_version                     = $::nova::compute::libvirt::version::default,
  $modular_libvirt                     = undef,
) inherits nova::compute::libvirt::version {

  include nova::deps
  include nova::params

  if $transport {
    $transport_real = $transport
  } else {
    $transport_real = 'tcp'
  }

  $modular_libvirt_real = pick($modular_libvirt, $::nova::params::modular_libvirt)

  if $modular_libvirt_real and !$::nova::params::modular_libvirt_support {
    fail('Modular libvirt daemons are not support in this distribution')
  }

  validate_legacy(Enum['tcp', 'tls', 'ssh'], 'validate_re', $transport_real,
    [['^tcp$', '^tls$', '^ssh$'], 'Valid options for transport are tcp, tls, ssh.'])
  validate_legacy(Enum['sasl', 'none'], 'validate_re', $auth,
    [['^sasl$', '^none$'], 'Valid options for auth are none and sasl.'])

  if $transport_real == 'tls' {
    $listen_tls = '1'
    $listen_tcp = '0'
  } elsif $transport_real == 'tcp' {
    $listen_tls = '0'
    $listen_tcp = '1'
  } else {
    $listen_tls = '0'
    $listen_tcp = '0'
  }

  if $configure_nova {
    if $transport_real == 'ssh' {
      if $client_user {
        $prefix =  "${client_user}@"
      } else {
        $prefix = ''
      }
    } else {
      $prefix = ''
    }

    if $client_port {
      $postfix = ":${client_port}"
    } else {
      $postfix = ''
    }

    if $client_extraparams != {} {
      $extra_params_before_python_escape = join(uriescape(join_keys_to_values($client_extraparams, '=')), '&')
      # Must escape % as nova interprets it incorrectly.
      $extra_params = sprintf('?%s', regsubst($extra_params_before_python_escape, '%', '%%', 'G'))
    } else {
      $extra_params =''
    }

    $live_migration_uri = "qemu+${transport_real}://${prefix}%s${postfix}/system${extra_params}"

    nova_config {
      'libvirt/live_migration_uri':                  value => $live_migration_uri;
      'libvirt/live_migration_tunnelled':            value => $live_migration_tunnelled;
      'libvirt/live_migration_with_native_tls':      value => $live_migration_with_native_tls;
      'libvirt/live_migration_completion_timeout':   value => $live_migration_completion_timeout;
      'libvirt/live_migration_timeout_action':       value => $live_migration_timeout_action;
      'libvirt/live_migration_inbound_addr':         value => $live_migration_inbound_addr;
      'libvirt/live_migration_permit_post_copy':     value => $live_migration_permit_post_copy;
      'libvirt/live_migration_permit_auto_converge': value => $live_migration_permit_auto_converge;
    }
  }

  if $configure_libvirt {
    Anchor['nova::config::begin']
    -> File<| tag == 'libvirt-file'|>
    -> File_line<| tag == 'libvirt-file_line'|>
    -> Anchor['nova::config::end']

    File_line<| tag == 'libvirt-file_line' |>
    ~> Service['libvirt']

    if $override_uuid {
      if ! $::libvirt_uuid {
        $host_uuid_real = pick(
          $host_uuid,
          generate('/bin/cat', '/proc/sys/kernel/random/uuid'))
        file { '/etc/libvirt/libvirt_uuid':
          content => $host_uuid_real,
          require => Package['libvirt'],
        }
      } else {
        $host_uuid_real = $::libvirt_uuid
      }

      if $modular_libvirt_real {
        ['virtqemud', 'virtproxyd', 'virtsecretd', 'virtnodedevd', 'virtstoraged'].each |String $daemon| {
          augeas { "${daemon}-conf-uuid":
            context => "/files/etc/libvirt/${daemon}.conf",
            changes => ["set host_uuid ${host_uuid_real}"],
            notify  => Service[$daemon],
            require => Package['libvirt'],
          }
        }
      } else {
        augeas { 'libvirt-conf-uuid':
          context => '/files/etc/libvirt/libvirtd.conf',
          changes => ["set host_uuid ${host_uuid_real}"],
          notify  => Service['libvirt'],
          require => Package['libvirt'],
        }
      }
    }

    if $transport_real == 'tls' {
      $auth_tls_real = $auth
      $auth_tcp_real = $::os_service_default
      $ca_file_real  = pick($ca_file, $::os_service_default)
      $crl_file_real = pick($crl_file, $::os_service_default)

      if $ca_file == undef {
        warning('Usage of undef for the ca_file parameter has been deprecated')
      }
      if $crl_file == undef {
        warning('Usage of undef for the crl_file parameter has been deprecated')
      }
    } elsif $transport_real == 'tcp' {
      $auth_tls_real = $::os_service_default
      $auth_tcp_real = $auth
      $ca_file_real  = $::os_service_default
      $crl_file_real = $::os_service_default
    } else {
      $auth_tls_real = $::os_service_default
      $auth_tcp_real = $::os_service_default
      $ca_file_real  = $::os_service_default
      $crl_file_real = $::os_service_default
    }

    if $listen_address == undef {
      warning('Usage of undef for the listen_addrss parameter has been deprecated')
    }

    $libvirt_listen_config = $modular_libvirt_real ? {
      true    => 'virtproxyd_config',
      default => 'libvirtd_config'
    }

    create_resources( $libvirt_listen_config , {
      'listen_tls' => { 'value' => $listen_tls },
      'listen_tcp' => { 'value' => $listen_tcp },
      'auth_tls'   => { 'value' => $auth_tls_real, 'quote' => true },
      'auth_tcp'   => { 'value' => $auth_tcp_real, 'quote' => true },
      'ca_file'    => { 'value' => $ca_file_real, 'quote'  => true },
      'crl_file'   => { 'value' => $crl_file_real, 'quote' => true },
      'listen_addr' => { 'value' => pick($listen_address, $::os_service_default), 'quote' => true }
    })

    if $transport_real == 'tls' or $transport_real == 'tcp' {
      if versioncmp($libvirt_version, '5.6') < 0 {
        fail('libvirt version < 5.6 is no longer supported')
      }

      if $manage_service {
        $proxy_service = $modular_libvirt ? {
          true    => 'virtproxyd',
          default => 'libvirtd',
        }
        # libvirtd.service should be stopped before socket service is started.
        # Otherwise, socket service fails to start.
        exec { "stop ${proxy_service}.service":
          path    => ['/sbin', '/usr/sbin', '/bin', '/usr/bin'],
          command => "systemctl -q stop ${proxy_service}.service",
          unless  => "systemctl -q is-active ${proxy_service}-${transport_real}.socket",
          require => Anchor['nova::install::end']
        }
        -> service { "${proxy_service}-${transport_real}":
          ensure  => 'running',
          name    => "${proxy_service}-${transport_real}.socket",
          enable  => true,
          require => Anchor['nova::config::end']
        }

        if $modular_libvirt {
          Service["${proxy_service}-${transport_real}"] -> Service<| title == 'virtproxyd' |>
        } else {
          Service["${proxy_service}-${transport_real}"] -> Service<| title == 'libvirt' |>
        }
      }
    }

    case $::osfamily {
      'RedHat': {
        # NOTE(tkajinam): Since libvirt 8.1.0, the sysconfig files are
        #                 no longer provided by packages.
        file { '/etc/sysconfig/libvirtd':
          ensure => present,
          path   => '/etc/sysconfig/libvirtd',
          tag    => 'libvirt-file',
        }

        file_line { '/etc/sysconfig/libvirtd libvirtd args':
          path  => '/etc/sysconfig/libvirtd',
          line  => 'LIBVIRTD_ARGS=',
          match => '^LIBVIRTD_ARGS=',
          tag   => 'libvirt-file_line',
        }
      }
      'Debian': {
        file_line { '/etc/default/libvirtd libvirtd opts':
          path  => '/etc/default/libvirtd',
          line  => 'libvirtd_opts=',
          match => 'libvirtd_opts=',
          tag   => 'libvirt-file_line',
        }
      }
      default: {
        warning("Unsupported osfamily: ${::osfamily}, make sure you are configuring this yourself")
      }
    }
  }
}