Defined Type: libvirt::vm

Defined in:
manifests/vm.pp

Overview

The options in the “vm()“ define use the exact same field syntax as the virt-install command.

See “virt-install(1)“ for variable details.

If “virbr0“ doesn’t do what you need it to, you may need to set up your own bridge using the networking module.

If you do set up your own bridge, make sure your call of this define ‘require’s that network stanza.

Examples:

libvirt::vm { 'test_system':
   mac_addr          => 'AA:BB:CC:DD:EE:FF',
   size              => 20,
   networks          => { 'type' => 'bridge', 'target' =>  'br0' },
   pxe               => true,
   disk_opts         => { 'bus' => 'virtio' }
}

Parameters:

  • size (Integer)
  • mac_addr (Optional[String]) (defaults to: undef)
  • sparse (Boolean) (defaults to: false)
  • mem (Integer) (defaults to: 512)
  • arch (Optional[String]) (defaults to: undef)
  • machine (Optional[String]) (defaults to: undef)
  • ostype (String) (defaults to: 'linux')
  • osvariant (String) (defaults to: 'rhel7')

    Optimize the guest configuration for a specific operating system (ex. ‘fedora18’, ‘rhel7’, ‘winxp’). See ‘man virt-install` for more information.

  • bridge (String) (defaults to: 'virbr0')

    A legacy option for connecting to a single bridge. ‘$bridges’ is now the favored option.

  • networks (Optional[Array]) (defaults to: undef)

    An array of hashes of networks where you can specify both the mac and model of each network if desired.

    This option overrides ‘$bridge’

    Example:

    [
      {
        'type'        => 'bridge',
        'target'      => '<bridge>',
        'mac'         => '<macaddr>', # Optional
        'model'       => '<model>',   # Optional
      },
      {
        'type'        => 'network'
        'target'      => '<network1>',
        'mac'         => '<macaddr>', # Optional
        'model'       => '<model>',   # Optional
      }
    ]
    
  • vcpus (Integer) (defaults to: 1)
  • vcpu_options (Optional[Hash]) (defaults to: undef)

    A hash of options that match the vcpus extended arguments. Options will be passed directly and without translation. Example:

    { 'maxvcpus'      => '3', 'sockets' => '2' }
    
  • numatune (Optional[Hash]) (defaults to: undef)

    A hash of options that correspond to the numatune options. Example:

    { 'nodeset'       => '1,2,3', 'mode' => 'preferred' }
    
  • cpu (Optional[Hash]) (defaults to: undef)

    A hash of the ‘cpu’ options:

    {
      'name'          => '<cpu_name>',
      'features'      => ['+<feature>','-<feature>','disable=<feature>']
      'match'         => <match>
      'vendor'        => <vendor>
    }
    
  • description (Optional[String]) (defaults to: undef)
  • security (Optional[Hash]) (defaults to: undef)

    A hash of the ‘security’ options:

    {
      'type'          => '<type>'
      'label'         => '<label>'
    }
    
  • cpuset (Optional[String]) (defaults to: undef)
  • full_virt (Boolean) (defaults to: true)
  • accelerate (Boolean) (defaults to: true)
  • sound (Boolean) (defaults to: true)
  • noapic (Boolean) (defaults to: false)
  • noacpi (Boolean) (defaults to: false)
  • pxe (Boolean) (defaults to: false)
  • cdrom_path (Optional[String]) (defaults to: undef)
  • location_url (Optional[String]) (defaults to: undef)

    This has been overloaded to accept DVD ISO image paths as well. If the target ends in ‘.iso’ the correct option will be used.

  • ks_url (Optional[String]) (defaults to: undef)
  • target_dir (Stdlib::AbsolutePath) (defaults to: '/var/VM')

    The directory in which to install the VM.

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

    A legacy option now superseded by ‘$disk_opts’

  • disk_opts (Optional[Hash]) (defaults to: undef)

    A hash of options as presented to the disk parameter of virt-install Supported options are: bus, perms, cache, format, io, error_policy, serial

  • graphics (Hash) (defaults to: { 'type' => 'vnc', 'keymap' => 'en_us' })

    A hash of options that are passed to the ‘–graphics’ option of virt-install, see the man page for details.

    Example:

    'type'            => 'vnc',
    'port'            => <port>                     #optional
    'tlsport'         => <spice tls port>           #optional
    'listen'          => <listen address>           #optional
    'keymap'          => <virtual keymap>           #optional
    'password'        => <password>                 #optional
    'passwordvalidto' => <expire date for password> #optional
    

  • virt_type (Optional[String]) (defaults to: undef)
  • host_device (Optional[String]) (defaults to: undef)
  • watchdog (Hash) (defaults to: { 'model' => 'default' })

    A hash of options to pass to the watchdog option of virt-install. Options are ‘model’, and ‘action’(optional)

Author:



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

define libvirt::vm (
  Integer              $size,
  Optional[String]     $mac_addr     = undef,
  Boolean              $sparse       = false,
  Integer              $mem          = 512,
  Optional[String]     $arch         = undef,
  Optional[String]     $machine      = undef,
  String               $ostype       = 'linux',
  String               $osvariant    = 'rhel7',
  String               $bridge       = 'virbr0',
  Optional[Array]      $networks     = undef,
  Integer              $vcpus        = 1,
  Optional[Hash]       $vcpu_options = undef,
  Optional[Hash]       $numatune     = undef,
  Optional[Hash]       $cpu          = undef,
  Optional[String]     $description  = undef,
  Optional[Hash]       $security     = undef,
  Optional[String]     $cpuset       = undef,
  Boolean              $full_virt    = true,
  Boolean              $accelerate   = true,
  Boolean              $sound        = true,
  Boolean              $noapic       = false,
  Boolean              $noacpi       = false,
  Boolean              $pxe          = false,
  Optional[String]     $cdrom_path   = undef,
  Optional[String]     $location_url = undef,
  Optional[String]     $ks_url       = undef,
  Stdlib::AbsolutePath $target_dir   = '/var/VM',
  Optional[String]     $disk_bus     = undef,
  Optional[Hash]       $disk_opts    = undef,
  Hash                 $graphics     = { 'type' => 'vnc', 'keymap' => 'en_us' },
  Optional[String]     $virt_type    = undef,
  Optional[String]     $host_device  = undef,
  Hash                 $watchdog     = { 'model' => 'default' }
) {
  include 'libvirt::kvm'

  if !defined(File[$target_dir]) {
    exec { "make ${target_dir}":
      command => "/bin/mkdir -p -m 2755 ${target_dir}",
      onlyif  => "/usr/bin/test ! -d ${target_dir}",
      notify  => File[$target_dir]
    }

    file { $target_dir:
      ensure => 'directory',
      owner  => 'root',
      group  => 'kvm',
      mode   => '2660'
    }
  }

  file { "/usr/local/sbin/vm-create-${name}.sh":
    owner   => 'root',
    group   => 'kvm',
    mode    => '0750',
    content => template('libvirt/newvm.erb'),
    require => File[$target_dir]
  }

  exec { "vm-create-${name}":
    command => "/usr/local/sbin/vm-create-${name}.sh > /dev/null 2>&1 &",
    onlyif  => "/usr/bin/virsh domstate ${name}; /usr/bin/test \$? -ne 0",
    require => Class['Libvirt::Service']
  }
}