Defined Type: libvirt::domain

Defined in:
manifests/domain.pp

Overview

libvirt::domain

Parameters:

  • type (String) (defaults to: 'kvm')

    Specify the hypervisor used for running the domain. The allowed values are driver specific, but include "xen", "kvm", "qemu" and "lxc" Defaults to 'kvm'

  • domain_title (String) (defaults to: '')

    Free text title of the domain. Defaults to ''.

  • description (String) (defaults to: '')

    Free text description of the domain. Defaults to ''.

  • uuid (String) (defaults to: libvirt_generate_uuid($name))

    UUID for the domain. The default is the uuid, generated with puppet.

  • boot (String) (defaults to: 'hd')

    Default boot device. Valid values are any accepted by libvirt or the string 'per-device' to set individual boot orders on disks or interfaces. Defaults to 'hd'.

  • disks (Array) (defaults to: [])

    Array of hashes defining the disks of this domain. Defaults to no disks at all. The hashes support the following keys:

    • type: Disk type, supported types are 'file', 'block', 'network' and 'volume'.
    • device: Disk device type exposed to the guest. Supported values are 'floppy', 'disk', 'cdrom' and 'lun'.
    • bus: Target bus, defaults to 'virtio'.
    • source: Hash of source parameters. The supported hash keys vary by the type of disk: file: 'file' key to specify the pathname of the source file backing this disk. block: 'dev' key to specify the pathname to the block device backing this disk. network: 'protocol' and 'name' volume: 'pool' and 'volume'
      • driver: Hash of driver parameters. Defaults to raw disks images, no caching and native io. Use => 'qemu', 'type' => 'qcow2' for QCOW2 images. See the libvirt domain XML documentation for all possible values.
      • boot_order: Integer starting at 1 for the highest priority (shared with interfaces).
  • interfaces (Array) (defaults to: [])

    Array of hashes defining the network interfaces of this domain. Defaults to no network interfaces. The hashes support the following keys:

    • mac: MAC address of the interface. Without a mac key, a random address will be assigned by libvirt. The MAC address should start with 52:54:00.
    • network: libvirt network to attach to (mandatory).
    • portgroup: portgroup to attach to (optional).
    • type: Type of network card. Defaults to 'virtio'.
    • boot_order: Integer starting at 1 for the highest priority (shared with disks).
  • autostart (Boolean) (defaults to: true)

    Wheter the libvirt autostart flag should be set. Defaults to true. Autostart domains are started if the host is booted.

  • dom_profile (String) (defaults to: 'default')

    profile to use for $domconf. Defaults to 'default' which is defined in data/profiles/xxx.yaml A profile is a predefined set of parameters for a vm. see class libvirt::profiles for additional information.

  • domconf (Hash) (defaults to: {})

    the generic domain configuration to activate for vm. this parameter is merged with the choosen profile, ($libvirt::profiles::domconf) to generate the final configuration. Defaults to {} which does not change the profile. see also libvirt::profiles for how to use profiles

  • devices_profile (String) (defaults to: 'default')

    profile to use for $devices. Defaults to 'default' which is defined in data/profiles/xxx.yaml A profile is a predefined set of parameters for a vm. see class libvirt::profiles for additional information.

  • devices (Hash) (defaults to: {})

    devices to attach to the vm this parameter is merged with the choosen profile, ($libvirt::profiles::devices) to generate the final configuration. Defaults to {} which does not change the profile. see also libvirt::profiles for how to use profiles

  • additionaldevices (Hash) (defaults to: {})

    additional devices to attach to the vm Same format as $devices, but without merging. Defaults to {}

  • default_host (Optional[String]) (defaults to: undef)

    FQDN for the default host of this domain. The manage-domains script uses this value to move a domain to it's default host if it's running elsewhere.

    Only useful together with the drbd qemu_hook in setups of two redundant virtualization hosts synchronized over DRBD. They have no effect if qemu_hook is not set to drbd.

  • evacuation (Optional[String]) (defaults to: undef)

    Evacuation policy for this domain. Valid values are 'migrate', 'save' and 'shutdown'. The default is to not set a value and to use the global default.

    Only useful together with the drbd qemu_hook in setups of two redundant virtualization hosts synchronized over DRBD. They have no effect if qemu_hook is not set to drbd.

  • max_job_time (Optional[String]) (defaults to: undef)

    Maximum job time in seconds when migrating, saving or shuting down this domain with the manage-domains script. The default is to not set a value and to use the global default.

    Only useful together with the drbd qemu_hook in setups of two redundant virtualization hosts synchronized over DRBD. They have no effect if qemu_hook is not set to drbd.

  • suspend_multiplier (Optional[String]) (defaults to: undef)

    suspend_multiplier for migrating domains with the manage-domains script. The default is to not set a value and to use the global default.

    Only useful together with the drbd qemu_hook in setups of two redundant virtualization hosts synchronized over DRBD. They have no effect if qemu_hook is not set to drbd.

  • max_memory (Optional[Any]) (defaults to: undef)

    Deprecated: Maximum amount of memory that can be allocated to the domain. Example (yaml): domconf: memory: attrs: unit: 'MiB' values: 2000 This parameter is deprecated, if set, the manifest will fail

  • initial_memory (Optional[Any]) (defaults to: undef)

    Initial memory allocation for the domain. Defaults to max_memory. Deprecation notice: use $domconf (or profile) to set. Example (yaml): domconf: currentMemory: attrs: unit: 'MiB' values: 1000 This parameter is deprecated, if set, the manifest will fail

  • cpus (Optional[Any]) (defaults to: undef)

    Number of virtual CPUs for the domain. Defaults to '1'. Deprecation notice: use $domconf (or profile) to set. Example (yaml): domconf: vcpu: values: 1 This parameter is deprecated, if set, the manifest will fail

  • bootmenu (Optional[Any]) (defaults to: undef)

    Wheter the boot menu option should be available or not. Defaults to true. Deprecation notice: use $domconf if you want to disable the bootmenu Example (yaml): domconf: os: bootmenu: attrs: enable: 'no' This parameter is deprecated, if set, the manifest will fail

  • machine_type (Optional[Any]) (defaults to: undef)

    Machine type to use, i.e.

    • "pc" - Standard PC (i440FX + PIIX, 1996)
    • "q35" - Standard PC (Q35 + ICH9, 2009) Deprecation notice: use $domconf if you want to set the machine type This parameter is deprecated, if set, the manifest will fail
  • cpu_model (Optional[Any]) (defaults to: undef)

    CPU model to emulate. Valid values are any cpu model accepted by libvirt or the special values 'host-model' and 'host-passthrough'. See http://libvirt.org/formatdomain.html#elementsCPU for details. Defaults to not set a CPU at all and let libvirt choose. The values 'host-model' and 'host-passthrough' prevent migrations from working. Deprecation notice: use $domconf (or profile) if you want to set the machine type Example (yaml): domconf: cpu: attrs: mode: 'custom' values: model: 'SandyBridge' This parameter is deprecated, if set, the manifest will fail



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
# File 'manifests/domain.pp', line 178

define libvirt::domain (
  String            $type               = 'kvm',
  String            $domain_title       = '',
  String            $description        = '',
  String            $uuid               = libvirt_generate_uuid($name),
  String            $boot               = 'hd',
  Array             $disks              = [],
  Array             $interfaces         = [],
  Boolean           $autostart          = true,
  String            $dom_profile        = 'default',
  Hash              $domconf            = {},
  String            $devices_profile    = 'default',
  Hash              $devices            = {},
  Hash              $additionaldevices  = {},
  Optional[String]  $default_host       = undef,
  Optional[String]  $evacuation         = undef,
  Optional[String]  $max_job_time       = undef,
  Optional[String]  $suspend_multiplier = undef,
  # deprecated parameters:
  Optional[Any]     $max_memory         = undef,
  Optional[Any]     $initial_memory     = undef,
  Optional[Any]     $cpus               = undef,
  Optional[Any]     $cpu_model          = undef,
  Optional[Any]     $bootmenu           = undef,
  Optional[Any]     $machine_type       = undef,
) {
  if $max_memory != undef {
    fail("deprecation: libvirt::domain, ${title}: max_memory parameter is deprecated, use domconf Hash or profile instead")
  }
  if $initial_memory != undef {
    fail("deprecation: libvirt::domain, ${title}: initial_memory parameter is deprecated, use domconf Hash or profile instead")
  }
  if $cpus != undef {
    fail("deprecation: libvirt::domain, ${title}: cpus parameter is deprecated, use domconf Hash or profile instead")
  }
  if $cpu_model != undef {
    fail("deprecation: libvirt::domain, ${title}: cpu_model parameter is deprecated, use domconf Hash or profile instead")
  }
  if $bootmenu != undef {
    fail("deprecation: libvirt::domain, ${title}: bootmenu is deprecated, use domconf Hash or profile instead")
  }
  if $machine_type != undef {
    warning("deprecation: libvirt::domain, ${title}: machine_type parameter is deprecated, use domconf Hash or profile Hash instead")
  }

  include ::libvirt
  include ::libvirt::profiles

  $devices_real  = libvirt::get_merged_profile($libvirt::profiles::devices, $devices_profile) + $devices

  if $boot == 'per-device' {
    $domconf_real  = libvirt::get_merged_profile($libvirt::profiles::domconf, $dom_profile) + $domconf
  } else {
    $_domconf = libvirt::get_merged_profile($libvirt::profiles::domconf, $dom_profile) + $domconf
    $domconf_real = deep_merge($_domconf,{'os' => {'boot' => { 'attrs' => { 'dev' => $boot }}}})
  }

  exec {"libvirt-domain-${name}":
    command  => join(['f=$(mktemp) && echo "',
                      template('libvirt/domain.xml.erb'),
                      '" > $f && virsh define $f && rm $f']),
    provider => 'shell',
    creates  => "${libvirt::config_dir}/qemu/${name}.xml",
    require  => Anchor['libvirt::end'],
  }

  if $libvirt::diff_dir != '' {
    file {"${libvirt::diff_dir}/domains/${name}.xml":
      content => template('libvirt/domain.xml.erb'),
    }
  }

  if ($autostart) {
    exec {"libvirt-domain-autostart-${name}":
      command  => "virsh autostart ${name}",
      provider => 'shell',
      creates  => "${libvirt::config_dir}/qemu/autostart/${name}.xml",
      require  => Exec["libvirt-domain-${name}"],
    }

    exec {"libvirt-domain-start-${name}":
      command  => "virsh start ${name}",
      provider => 'shell',
      unless   => "virsh list --name | grep -q ^${name}$",
      require  => Exec["libvirt-domain-${name}"],
    }
  }

  if ($libvirt::qemu_hook=='drbd') {
    concat::fragment { $name:
      target  => $libvirt::manage_domains_config,
      content => template('libvirt/manage-domains.ini.domain.erb'),
      order   => '10',
    }
  }
}