Class: VagrantPlugins::ProviderLibvirt::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-libvirt/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



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
# File 'lib/vagrant-libvirt/config.rb', line 176

def initialize
  @uri               = UNSET_VALUE
  @driver            = UNSET_VALUE
  @host              = UNSET_VALUE
  @connect_via_ssh   = UNSET_VALUE
  @username          = UNSET_VALUE
  @password          = UNSET_VALUE
  @id_ssh_key_file   = UNSET_VALUE
  @storage_pool_name = UNSET_VALUE
  @snapshot_pool_name = UNSET_VALUE
  @random_hostname   = UNSET_VALUE
  @management_network_device  = UNSET_VALUE
  @management_network_name    = UNSET_VALUE
  @management_network_address = UNSET_VALUE
  @management_network_mode = UNSET_VALUE
  @management_network_mac  = UNSET_VALUE
  @management_network_guest_ipv6 = UNSET_VALUE
  @management_network_autostart = UNSET_VALUE
  @management_network_pci_slot = UNSET_VALUE
  @management_network_pci_bus = UNSET_VALUE
  @management_network_domain = UNSET_VALUE

  # System connection information
  @system_uri      = UNSET_VALUE

  # Domain specific settings.
  @title             = UNSET_VALUE
  @description       = UNSET_VALUE
  @uuid              = UNSET_VALUE
  @memory            = UNSET_VALUE
  @nodeset           = UNSET_VALUE
  @memory_backing    = UNSET_VALUE
  @cpus              = UNSET_VALUE
  @cpuset            = UNSET_VALUE
  @cpu_mode          = UNSET_VALUE
  @cpu_model         = UNSET_VALUE
  @cpu_fallback      = UNSET_VALUE
  @cpu_features      = UNSET_VALUE
  @cpu_topology      = UNSET_VALUE
  @shares            = UNSET_VALUE
  @features          = UNSET_VALUE
  @features_hyperv   = UNSET_VALUE
  @numa_nodes        = UNSET_VALUE
  @loader            = UNSET_VALUE
  @nvram             = UNSET_VALUE
  @machine_type      = UNSET_VALUE
  @machine_arch      = UNSET_VALUE
  @machine_virtual_size = UNSET_VALUE
  @disk_bus          = UNSET_VALUE
  @disk_device       = UNSET_VALUE
  @nic_model_type    = UNSET_VALUE
  @nested            = UNSET_VALUE
  @volume_cache      = UNSET_VALUE
  @kernel            = UNSET_VALUE
  @initrd            = UNSET_VALUE
  @dtb               = UNSET_VALUE
  @cmd_line          = UNSET_VALUE
  @emulator_path     = UNSET_VALUE
  @graphics_type     = UNSET_VALUE
  @graphics_autoport = UNSET_VALUE
  @graphics_port     = UNSET_VALUE
  @graphics_ip       = UNSET_VALUE
  @graphics_passwd   = UNSET_VALUE
  @video_type        = UNSET_VALUE
  @video_vram        = UNSET_VALUE
  @sound_type        = UNSET_VALUE
  @keymap            = UNSET_VALUE
  @kvm_hidden        = UNSET_VALUE

  @tpm_model         = UNSET_VALUE
  @tpm_type          = UNSET_VALUE
  @tpm_path          = UNSET_VALUE

  @nic_adapter_count = UNSET_VALUE

  # Boot order
  @boot_order        = []
  # Storage
  @disks             = []
  @cdroms            = []

  # Inputs
  @inputs            = UNSET_VALUE

  # Channels
  @channels          = UNSET_VALUE

  # PCI device passthrough
  @pcis              = UNSET_VALUE

  # Random number device passthrough
  @rng = UNSET_VALUE

  # Watchdog device
  @watchdog_dev      = UNSET_VALUE

  # USB controller
  @usbctl_dev        = UNSET_VALUE

  # USB device passthrough
  @usbs              = UNSET_VALUE

  # Redirected devices
  @redirdevs         = UNSET_VALUE
  @redirfilters      = UNSET_VALUE

  # smartcard device
  @smartcard_dev     = UNSET_VALUE

  # Suspend mode
  @suspend_mode      = UNSET_VALUE

  # Autostart
  @autostart         = UNSET_VALUE

  # Attach mgmt network
  @mgmt_attach       = UNSET_VALUE

  # Additional QEMU commandline arguments
  @qemu_args         = UNSET_VALUE

  # Additional QEMU commandline environment variables
  @qemu_env          = UNSET_VALUE

  @qemu_use_session  = UNSET_VALUE
end

Instance Attribute Details

#autostartObject

Autostart



162
163
164
# File 'lib/vagrant-libvirt/config.rb', line 162

def autostart
  @autostart
end

#boot_orderObject

Returns the value of attribute boot_order.



90
91
92
# File 'lib/vagrant-libvirt/config.rb', line 90

def boot_order
  @boot_order
end

#cdromsObject

Returns the value of attribute cdroms.



128
129
130
# File 'lib/vagrant-libvirt/config.rb', line 128

def cdroms
  @cdroms
end

#channel(options = {}) ⇒ Object

Returns the value of attribute channel.



76
77
78
# File 'lib/vagrant-libvirt/config.rb', line 76

def channel
  @channel
end

#channelsObject

Channels



134
135
136
# File 'lib/vagrant-libvirt/config.rb', line 134

def channels
  @channels
end

#cmd_lineObject

Returns the value of attribute cmd_line.



100
101
102
# File 'lib/vagrant-libvirt/config.rb', line 100

def cmd_line
  @cmd_line
end

#connect_via_sshObject

If use ssh tunnel to connect to Libvirt.



27
28
29
# File 'lib/vagrant-libvirt/config.rb', line 27

def connect_via_ssh
  @connect_via_ssh
end

#cpu_fallbackObject

Returns the value of attribute cpu_fallback.



81
82
83
# File 'lib/vagrant-libvirt/config.rb', line 81

def cpu_fallback
  @cpu_fallback
end

#cpu_featuresObject

Returns the value of attribute cpu_features.



82
83
84
# File 'lib/vagrant-libvirt/config.rb', line 82

def cpu_features
  @cpu_features
end

#cpu_modeObject

Returns the value of attribute cpu_mode.



79
80
81
# File 'lib/vagrant-libvirt/config.rb', line 79

def cpu_mode
  @cpu_mode
end

#cpu_modelObject

Returns the value of attribute cpu_model.



80
81
82
# File 'lib/vagrant-libvirt/config.rb', line 80

def cpu_model
  @cpu_model
end

#cpu_topologyObject

Returns the value of attribute cpu_topology.



83
84
85
# File 'lib/vagrant-libvirt/config.rb', line 83

def cpu_topology
  @cpu_topology
end

#cpusObject

Returns the value of attribute cpus.



77
78
79
# File 'lib/vagrant-libvirt/config.rb', line 77

def cpus
  @cpus
end

#cpusetObject

Returns the value of attribute cpuset.



78
79
80
# File 'lib/vagrant-libvirt/config.rb', line 78

def cpuset
  @cpuset
end

#default_prefixObject

Default host prefix (alternative to use project folder name)



67
68
69
# File 'lib/vagrant-libvirt/config.rb', line 67

def default_prefix
  @default_prefix
end

#descriptionObject

Returns the value of attribute description.



71
72
73
# File 'lib/vagrant-libvirt/config.rb', line 71

def description
  @description
end

#disk_busObject

Returns the value of attribute disk_bus.



94
95
96
# File 'lib/vagrant-libvirt/config.rb', line 94

def disk_bus
  @disk_bus
end

#disk_deviceObject

Returns the value of attribute disk_device.



95
96
97
# File 'lib/vagrant-libvirt/config.rb', line 95

def disk_device
  @disk_device
end

#disksObject

Storage



127
128
129
# File 'lib/vagrant-libvirt/config.rb', line 127

def disks
  @disks
end

#driverObject

A hypervisor name to access via Libvirt.



21
22
23
# File 'lib/vagrant-libvirt/config.rb', line 21

def driver
  @driver
end

#dtbObject

Returns the value of attribute dtb.



102
103
104
# File 'lib/vagrant-libvirt/config.rb', line 102

def dtb
  @dtb
end

#emulator_pathObject

Returns the value of attribute emulator_path.



103
104
105
# File 'lib/vagrant-libvirt/config.rb', line 103

def emulator_path
  @emulator_path
end

#featuresObject

Returns the value of attribute features.



85
86
87
# File 'lib/vagrant-libvirt/config.rb', line 85

def features
  @features
end

#features_hypervObject

Returns the value of attribute features_hyperv.



86
87
88
# File 'lib/vagrant-libvirt/config.rb', line 86

def features_hyperv
  @features_hyperv
end

#graphics_autoportObject

Returns the value of attribute graphics_autoport.



105
106
107
# File 'lib/vagrant-libvirt/config.rb', line 105

def graphics_autoport
  @graphics_autoport
end

#graphics_ipObject

Returns the value of attribute graphics_ip.



108
109
110
# File 'lib/vagrant-libvirt/config.rb', line 108

def graphics_ip
  @graphics_ip
end

#graphics_passwdObject

Returns the value of attribute graphics_passwd.



107
108
109
# File 'lib/vagrant-libvirt/config.rb', line 107

def graphics_passwd
  @graphics_passwd
end

#graphics_portObject

Returns the value of attribute graphics_port.



106
107
108
# File 'lib/vagrant-libvirt/config.rb', line 106

def graphics_port
  @graphics_port
end

#graphics_typeObject

Returns the value of attribute graphics_type.



104
105
106
# File 'lib/vagrant-libvirt/config.rb', line 104

def graphics_type
  @graphics_type
end

#hostObject

The name of the server, where Libvirtd is running.



24
25
26
# File 'lib/vagrant-libvirt/config.rb', line 24

def host
  @host
end

#id_ssh_key_fileObject

ID SSH key file



38
39
40
# File 'lib/vagrant-libvirt/config.rb', line 38

def id_ssh_key_file
  @id_ssh_key_file
end

#initrdObject

Returns the value of attribute initrd.



101
102
103
# File 'lib/vagrant-libvirt/config.rb', line 101

def initrd
  @initrd
end

#inputsObject

Inputs



131
132
133
# File 'lib/vagrant-libvirt/config.rb', line 131

def inputs
  @inputs
end

#kernelObject

Returns the value of attribute kernel.



99
100
101
# File 'lib/vagrant-libvirt/config.rb', line 99

def kernel
  @kernel
end

#keymapObject

Returns the value of attribute keymap.



111
112
113
# File 'lib/vagrant-libvirt/config.rb', line 111

def keymap
  @keymap
end

#kvm_hiddenObject

Returns the value of attribute kvm_hidden.



112
113
114
# File 'lib/vagrant-libvirt/config.rb', line 112

def kvm_hidden
  @kvm_hidden
end

#loaderObject

Returns the value of attribute loader.



88
89
90
# File 'lib/vagrant-libvirt/config.rb', line 88

def loader
  @loader
end

#machine_archObject

Returns the value of attribute machine_arch.



92
93
94
# File 'lib/vagrant-libvirt/config.rb', line 92

def machine_arch
  @machine_arch
end

#machine_typeObject

Returns the value of attribute machine_type.



91
92
93
# File 'lib/vagrant-libvirt/config.rb', line 91

def machine_type
  @machine_type
end

#machine_virtual_sizeObject

Returns the value of attribute machine_virtual_size.



93
94
95
# File 'lib/vagrant-libvirt/config.rb', line 93

def machine_virtual_size
  @machine_virtual_size
end

#management_network_addressObject

Returns the value of attribute management_network_address.



54
55
56
# File 'lib/vagrant-libvirt/config.rb', line 54

def management_network_address
  @management_network_address
end

#management_network_autostartObject

Returns the value of attribute management_network_autostart.



58
59
60
# File 'lib/vagrant-libvirt/config.rb', line 58

def management_network_autostart
  @management_network_autostart
end

#management_network_deviceObject

Libvirt default network



52
53
54
# File 'lib/vagrant-libvirt/config.rb', line 52

def management_network_device
  @management_network_device
end

#management_network_domainObject

Returns the value of attribute management_network_domain.



61
62
63
# File 'lib/vagrant-libvirt/config.rb', line 61

def management_network_domain
  @management_network_domain
end

#management_network_guest_ipv6Object

Returns the value of attribute management_network_guest_ipv6.



57
58
59
# File 'lib/vagrant-libvirt/config.rb', line 57

def management_network_guest_ipv6
  @management_network_guest_ipv6
end

#management_network_macObject

Returns the value of attribute management_network_mac.



56
57
58
# File 'lib/vagrant-libvirt/config.rb', line 56

def management_network_mac
  @management_network_mac
end

#management_network_modeObject

Returns the value of attribute management_network_mode.



55
56
57
# File 'lib/vagrant-libvirt/config.rb', line 55

def management_network_mode
  @management_network_mode
end

#management_network_nameObject

Returns the value of attribute management_network_name.



53
54
55
# File 'lib/vagrant-libvirt/config.rb', line 53

def management_network_name
  @management_network_name
end

#management_network_pci_busObject

Returns the value of attribute management_network_pci_bus.



59
60
61
# File 'lib/vagrant-libvirt/config.rb', line 59

def management_network_pci_bus
  @management_network_pci_bus
end

#management_network_pci_slotObject

Returns the value of attribute management_network_pci_slot.



60
61
62
# File 'lib/vagrant-libvirt/config.rb', line 60

def management_network_pci_slot
  @management_network_pci_slot
end

#memoryObject

Returns the value of attribute memory.



73
74
75
# File 'lib/vagrant-libvirt/config.rb', line 73

def memory
  @memory
end

#memory_backingObject

Returns the value of attribute memory_backing.



75
76
77
# File 'lib/vagrant-libvirt/config.rb', line 75

def memory_backing
  @memory_backing
end

#mgmt_attachObject

Attach mgmt network



165
166
167
# File 'lib/vagrant-libvirt/config.rb', line 165

def mgmt_attach
  @mgmt_attach
end

#nestedObject

Returns the value of attribute nested.



97
98
99
# File 'lib/vagrant-libvirt/config.rb', line 97

def nested
  @nested
end

#nic_adapter_countObject

Sets the max number of NICs that can be created Default set to 8. Don’t change the default unless you know what are doing



124
125
126
# File 'lib/vagrant-libvirt/config.rb', line 124

def nic_adapter_count
  @nic_adapter_count
end

#nic_model_typeObject

Returns the value of attribute nic_model_type.



96
97
98
# File 'lib/vagrant-libvirt/config.rb', line 96

def nic_model_type
  @nic_model_type
end

#nodesetObject

Returns the value of attribute nodeset.



74
75
76
# File 'lib/vagrant-libvirt/config.rb', line 74

def nodeset
  @nodeset
end

#numa_nodesObject

Returns the value of attribute numa_nodes.



87
88
89
# File 'lib/vagrant-libvirt/config.rb', line 87

def numa_nodes
  @numa_nodes
end

#nvramObject

Returns the value of attribute nvram.



89
90
91
# File 'lib/vagrant-libvirt/config.rb', line 89

def nvram
  @nvram
end

#passwordObject

Password for Libvirt connection.



35
36
37
# File 'lib/vagrant-libvirt/config.rb', line 35

def password
  @password
end

#pcisObject

PCI device passthrough



137
138
139
# File 'lib/vagrant-libvirt/config.rb', line 137

def pcis
  @pcis
end

#qemu_argsObject

Additional qemuargs arguments



168
169
170
# File 'lib/vagrant-libvirt/config.rb', line 168

def qemu_args
  @qemu_args
end

#qemu_envObject

Additional qemuenv arguments



171
172
173
# File 'lib/vagrant-libvirt/config.rb', line 171

def qemu_env
  @qemu_env
end

#qemu_use_sessionObject

Use QEMU session instead of system



174
175
176
# File 'lib/vagrant-libvirt/config.rb', line 174

def qemu_use_session
  @qemu_use_session
end

#random_hostnameObject

Turn on to prevent hostname conflicts



49
50
51
# File 'lib/vagrant-libvirt/config.rb', line 49

def random_hostname
  @random_hostname
end

#redirdevsObject

Redirected devices



152
153
154
# File 'lib/vagrant-libvirt/config.rb', line 152

def redirdevs
  @redirdevs
end

#redirfiltersObject

Returns the value of attribute redirfilters.



153
154
155
# File 'lib/vagrant-libvirt/config.rb', line 153

def redirfilters
  @redirfilters
end

#rngObject

Random number device passthrough



140
141
142
# File 'lib/vagrant-libvirt/config.rb', line 140

def rng
  @rng
end

#sharesObject

Returns the value of attribute shares.



84
85
86
# File 'lib/vagrant-libvirt/config.rb', line 84

def shares
  @shares
end

#smartcard_devObject

smartcard device



156
157
158
# File 'lib/vagrant-libvirt/config.rb', line 156

def smartcard_dev
  @smartcard_dev
end

#snapshot_pool_nameObject

Libvirt storage pool where the base image snapshot shall be stored



46
47
48
# File 'lib/vagrant-libvirt/config.rb', line 46

def snapshot_pool_name
  @snapshot_pool_name
end

#socketObject

Path towards the Libvirt socket



29
30
31
# File 'lib/vagrant-libvirt/config.rb', line 29

def socket
  @socket
end

#sound_typeObject

Returns the value of attribute sound_type.



113
114
115
# File 'lib/vagrant-libvirt/config.rb', line 113

def sound_type
  @sound_type
end

#storage_pool_nameObject

Libvirt storage pool name, where box image and instance snapshots will be stored.



42
43
44
# File 'lib/vagrant-libvirt/config.rb', line 42

def storage_pool_name
  @storage_pool_name
end

#storage_pool_pathObject

Returns the value of attribute storage_pool_path.



43
44
45
# File 'lib/vagrant-libvirt/config.rb', line 43

def storage_pool_path
  @storage_pool_path
end

#suspend_modeObject

Suspend mode



159
160
161
# File 'lib/vagrant-libvirt/config.rb', line 159

def suspend_mode
  @suspend_mode
end

#system_uriObject

System connection information



64
65
66
# File 'lib/vagrant-libvirt/config.rb', line 64

def system_uri
  @system_uri
end

#titleObject

Domain specific settings used while creating new domain.



70
71
72
# File 'lib/vagrant-libvirt/config.rb', line 70

def title
  @title
end

#tpm_modelObject

Sets the information for connecting to a host TPM device Only supports socket-based TPMs



117
118
119
# File 'lib/vagrant-libvirt/config.rb', line 117

def tpm_model
  @tpm_model
end

#tpm_pathObject

Returns the value of attribute tpm_path.



119
120
121
# File 'lib/vagrant-libvirt/config.rb', line 119

def tpm_path
  @tpm_path
end

#tpm_typeObject

Returns the value of attribute tpm_type.



118
119
120
# File 'lib/vagrant-libvirt/config.rb', line 118

def tpm_type
  @tpm_type
end

#uriObject

manually specify URI will supercede most other options if provided



18
19
20
# File 'lib/vagrant-libvirt/config.rb', line 18

def uri
  @uri
end

#usbctl_devObject

USB controller



146
147
148
# File 'lib/vagrant-libvirt/config.rb', line 146

def usbctl_dev
  @usbctl_dev
end

#usbsObject

USB device passthrough



149
150
151
# File 'lib/vagrant-libvirt/config.rb', line 149

def usbs
  @usbs
end

#usernameObject

The username to access Libvirt.



32
33
34
# File 'lib/vagrant-libvirt/config.rb', line 32

def username
  @username
end

#uuidObject

Returns the value of attribute uuid.



72
73
74
# File 'lib/vagrant-libvirt/config.rb', line 72

def uuid
  @uuid
end

#video_typeObject

Returns the value of attribute video_type.



109
110
111
# File 'lib/vagrant-libvirt/config.rb', line 109

def video_type
  @video_type
end

#video_vramObject

Returns the value of attribute video_vram.



110
111
112
# File 'lib/vagrant-libvirt/config.rb', line 110

def video_vram
  @video_vram
end

#volume_cacheObject

Returns the value of attribute volume_cache.



98
99
100
# File 'lib/vagrant-libvirt/config.rb', line 98

def volume_cache
  @volume_cache
end

#watchdog_devObject

Watchdog device



143
144
145
# File 'lib/vagrant-libvirt/config.rb', line 143

def watchdog_dev
  @watchdog_dev
end

Instance Method Details

#_generate_numaObject



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'lib/vagrant-libvirt/config.rb', line 336

def _generate_numa
  @numa_nodes.collect { |x|
    # Perform some validation of cpu values
    unless x[:cpus] =~ /^\d+-\d+$/
      raise 'numa_nodes[:cpus] must be in format "integer-integer"'
    end

    # Convert to KiB
    x[:memory] = x[:memory].to_i * 1024
  }

  # Grab the value of the last @numa_nodes[:cpus] and verify @cpus matches
  # Note: [:cpus] is zero based and @cpus is not, so we need to +1
  last_cpu = @numa_nodes.last[:cpus]
  last_cpu = last_cpu.scan(/\d+$/)[0]
  last_cpu = last_cpu.to_i + 1

  if @cpus != last_cpu.to_i
    raise 'The total number of numa_nodes[:cpus] must equal config.cpus'
  end

  @numa_nodes
end

#_generate_uri(qemu_use_session) ⇒ Object

code to generate URI from from either the LIBVIRT_URI environment variable or a config moved out of the connect action



629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
# File 'lib/vagrant-libvirt/config.rb', line 629

def _generate_uri(qemu_use_session)

  # If the LIBVIRT_DEFAULT_URI var is set, we'll use that
  if ENV.fetch('LIBVIRT_DEFAULT_URI', '') != ""
    return ENV['LIBVIRT_DEFAULT_URI']
  end

  # builds the Libvirt connection URI from the given driver config
  # Setup connection uri.
  uri = @driver.dup
  virt_path = case uri
              when 'qemu', 'kvm'
                qemu_use_session ? '/session' : '/system'
              when 'openvz', 'uml', 'phyp', 'parallels'
                '/system'
              when '@en', 'esx'
                '/'
              when 'vbox', 'vmwarews', 'hyperv'
                '/session'
              else
                raise "Require specify driver #{uri}"
  end
  if uri == 'kvm'
    uri = 'qemu' # use QEMU uri for KVM domain type
  end

  if @connect_via_ssh
    uri << '+ssh://'
    uri << @username + '@' if @username

    uri << ( @host ? @host : 'localhost' )
  else
    uri << '://'
    uri << @host if @host
  end

  uri << virt_path

  params = {'no_verify' => '1'}

  if @id_ssh_key_file
    # set ssh key for access to Libvirt host
    # if no slash, prepend $HOME/.ssh/
    @id_ssh_key_file.prepend("#{ENV['HOME']}/.ssh/") if @id_ssh_key_file !~ /\A\//
    params['keyfile'] = @id_ssh_key_file
  end
  # set path to Libvirt socket
  params['socket'] = @socket if @socket

  uri << "?" + params.map{|pair| pair.join('=')}.join('&')
  uri
end

#_get_cdrom_dev(cdroms) ⇒ Object



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/vagrant-libvirt/config.rb', line 318

def _get_cdrom_dev(cdroms)
  exist = Hash[cdroms.collect { |x| [x[:dev], true] }]
  # hda - hdc
  curr = 'a'.ord
  while curr <= 'd'.ord
    dev = 'hd' + curr.chr
    if exist[dev]
      curr += 1
      next
    else
      return dev
    end
  end

  # is it better to raise our own error, or let Libvirt cause the exception?
  raise 'Only four cdroms may be attached at a time'
end

#_get_device(disks) ⇒ Object



307
308
309
310
311
312
313
314
315
316
# File 'lib/vagrant-libvirt/config.rb', line 307

def _get_device(disks)
  # skip existing devices and also the first one (vda)
  exist = disks.collect { |x| x[:device] } + [1.vdev.to_s]
  skip = 1 # we're 1 based, not 0 based...
  loop do
    dev = skip.vdev # get lettered device
    return dev unless exist.include?(dev)
    skip += 1
  end
end

#_handle_cdrom_storage(options = {}) ⇒ Object



565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
# File 'lib/vagrant-libvirt/config.rb', line 565

def _handle_cdrom_storage(options = {})
  # <disk type="file" device="cdrom">
  #   <source file="/home/user/virtio-win-0.1-100.iso"/>
  #   <target dev="hdc"/>
  #   <readonly/>
  #   <address type='drive' controller='0' bus='1' target='0' unit='0'/>
  # </disk>
  #
  # note the target dev will need to be changed with each cdrom drive (hdc, hdd, etc),
  # as will the address unit number (unit=0, unit=1, etc)

  options = {
    bus: 'ide',
    path: nil
  }.merge(options)

  cdrom = {
    dev: options[:dev],
    bus: options[:bus],
    path: options[:path]
  }

  @cdroms << cdrom
end

#_handle_disk_storage(options = {}) ⇒ Object



590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
# File 'lib/vagrant-libvirt/config.rb', line 590

def _handle_disk_storage(options = {})
  options = {
    type: 'qcow2',
    size: '10G', # matches the fog default
    path: nil,
    bus: 'virtio'
  }.merge(options)

  disk = {
    device: options[:device],
    type: options[:type],
    size: options[:size],
    path: options[:path],
    bus: options[:bus],
    cache: options[:cache] || 'default',
    allow_existing: options[:allow_existing],
    shareable: options[:shareable],
    serial: options[:serial],
    pool: options[:pool], # overrides storage_pool setting for additional disks
    wwn: options[:wwn],
  }

  @disks << disk # append
end

#_parse_uri(uri) ⇒ Object



682
683
684
685
686
687
688
# File 'lib/vagrant-libvirt/config.rb', line 682

def _parse_uri(uri)
  begin
    URI.parse(uri)
  rescue
    raise "@uri set to invalid uri '#{uri}'"
  end
end

#boot(device) ⇒ Object



303
304
305
# File 'lib/vagrant-libvirt/config.rb', line 303

def boot(device)
  @boot_order << device # append
end

#cpu_feature(options = {}) ⇒ Object



360
361
362
363
364
365
366
367
368
369
# File 'lib/vagrant-libvirt/config.rb', line 360

def cpu_feature(options = {})
  if options[:name].nil? || options[:policy].nil?
    raise 'CPU Feature name AND policy must be specified'
  end

  @cpu_features = [] if @cpu_features == UNSET_VALUE

  @cpu_features.push(name:   options[:name],
                     policy: options[:policy])
end

#cputopology(options = {}) ⇒ Object



382
383
384
385
386
387
388
389
390
391
392
393
394
# File 'lib/vagrant-libvirt/config.rb', line 382

def cputopology(options = {})
  if options[:sockets].nil? || options[:cores].nil? || options[:threads].nil?
    raise 'CPU topology must have all of sockets, cores and threads specified'
  end

  if @cpu_topology == UNSET_VALUE
    @cpu_topology = {}
  end

  @cpu_topology[:sockets] = options[:sockets]
  @cpu_topology[:cores] = options[:cores]
  @cpu_topology[:threads] = options[:threads]
end

#finalize!Object



690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
# File 'lib/vagrant-libvirt/config.rb', line 690

def finalize!
  @driver = 'kvm' if @driver == UNSET_VALUE
  @host = nil if @host == UNSET_VALUE
  @connect_via_ssh = false if @connect_via_ssh == UNSET_VALUE
  @username = nil if @username == UNSET_VALUE
  @password = nil if @password == UNSET_VALUE
  @id_ssh_key_file = 'id_rsa' if @id_ssh_key_file == UNSET_VALUE
  @storage_pool_name = 'default' if @storage_pool_name == UNSET_VALUE
  @snapshot_pool_name = @storage_pool_name if @snapshot_pool_name == UNSET_VALUE
  @storage_pool_path = nil if @storage_pool_path == UNSET_VALUE
  @random_hostname = false if @random_hostname == UNSET_VALUE
  @management_network_device = 'virbr0' if @management_network_device == UNSET_VALUE
  @management_network_name = 'vagrant-libvirt' if @management_network_name == UNSET_VALUE
  @management_network_address = '192.168.121.0/24' if @management_network_address == UNSET_VALUE
  @management_network_mode = 'nat' if @management_network_mode == UNSET_VALUE
  @management_network_mac = nil if @management_network_mac == UNSET_VALUE
  @management_network_guest_ipv6 = 'yes' if @management_network_guest_ipv6 == UNSET_VALUE
  @management_network_autostart = false if @management_network_autostart == UNSET_VALUE
  @management_network_pci_bus = nil if @management_network_pci_bus == UNSET_VALUE
  @management_network_pci_slot = nil if @management_network_pci_slot == UNSET_VALUE
  @management_network_domain = nil if @management_network_domain == UNSET_VALUE
  @system_uri      = 'qemu:///system' if @system_uri == UNSET_VALUE

  # If uri isn't set then let's build one from various sources.
  # Default to passing false for qemu_use_session if it's not set.
  if @uri == UNSET_VALUE
    @uri = _generate_uri(@qemu_use_session == UNSET_VALUE ? false : @qemu_use_session)
  end

  # Set qemu_use_session based on the URI if it wasn't set by the user
  if @qemu_use_session == UNSET_VALUE
    uri = _parse_uri(@uri)
    if (uri.scheme.start_with? "qemu") && (uri.path.include? "session")
      @qemu_use_session = true
    else
      @qemu_use_session = false
    end
  end

  # Domain specific settings.
  @title = '' if @title == UNSET_VALUE
  @description = '' if @description == UNSET_VALUE
  @uuid = '' if @uuid == UNSET_VALUE
  @memory = 512 if @memory == UNSET_VALUE
  @nodeset = nil if @nodeset == UNSET_VALUE
  @memory_backing = [] if @memory_backing == UNSET_VALUE
  @cpus = 1 if @cpus == UNSET_VALUE
  @cpuset = nil if @cpuset == UNSET_VALUE
  @cpu_mode = 'host-model' if @cpu_mode == UNSET_VALUE
  @cpu_model = if (@cpu_model == UNSET_VALUE) && (@cpu_mode == 'custom')
                 'qemu64'
               elsif @cpu_mode != 'custom'
                 ''
               else
                 @cpu_model
    end
  @cpu_topology = {} if @cpu_topology == UNSET_VALUE
  @cpu_fallback = 'allow' if @cpu_fallback == UNSET_VALUE
  @cpu_features = [] if @cpu_features == UNSET_VALUE
  @shares = nil if @shares == UNSET_VALUE
  @features = ['acpi','apic','pae'] if @features == UNSET_VALUE
  @features_hyperv = [] if @features_hyperv == UNSET_VALUE
  @numa_nodes = @numa_nodes == UNSET_VALUE ? nil : _generate_numa
  @loader = nil if @loader == UNSET_VALUE
  @nvram = nil if @nvram == UNSET_VALUE
  @machine_type = nil if @machine_type == UNSET_VALUE
  @machine_arch = nil if @machine_arch == UNSET_VALUE
  @machine_virtual_size = nil if @machine_virtual_size == UNSET_VALUE
  @disk_bus = 'virtio' if @disk_bus == UNSET_VALUE
  @disk_device = 'vda' if @disk_device == UNSET_VALUE
  @nic_model_type = nil if @nic_model_type == UNSET_VALUE
  @nested = false if @nested == UNSET_VALUE
  @volume_cache = 'default' if @volume_cache == UNSET_VALUE
  @kernel = nil if @kernel == UNSET_VALUE
  @cmd_line = '' if @cmd_line == UNSET_VALUE
  @initrd = '' if @initrd == UNSET_VALUE
  @dtb = nil if @dtb == UNSET_VALUE
  @graphics_type = 'vnc' if @graphics_type == UNSET_VALUE
  @graphics_autoport = 'yes' if @graphics_port == UNSET_VALUE
  @graphics_autoport = 'no' if @graphics_port != UNSET_VALUE
  if (@graphics_type != 'vnc' && @graphics_type != 'spice') ||
     @graphics_passwd == UNSET_VALUE
    @graphics_passwd = nil
  end
  @graphics_port = -1 if @graphics_port == UNSET_VALUE
  @graphics_ip = '127.0.0.1' if @graphics_ip == UNSET_VALUE
  @video_type = 'cirrus' if @video_type == UNSET_VALUE
  @video_vram = 9216 if @video_vram == UNSET_VALUE
  @sound_type = nil if @sound_type == UNSET_VALUE
  @keymap = 'en-us' if @keymap == UNSET_VALUE
  @kvm_hidden = false if @kvm_hidden == UNSET_VALUE
  @tpm_model = 'tpm-tis' if @tpm_model == UNSET_VALUE
  @tpm_type = 'passthrough' if @tpm_type == UNSET_VALUE
  @tpm_path = nil if @tpm_path == UNSET_VALUE
  @nic_adapter_count = 8 if @nic_adapter_count == UNSET_VALUE
  @emulator_path = nil if @emulator_path == UNSET_VALUE

  # Boot order
  @boot_order = [] if @boot_order == UNSET_VALUE

  # Storage
  @disks = [] if @disks == UNSET_VALUE
  @disks.map! do |disk|
    disk[:device] = _get_device(@disks) if disk[:device].nil?
    disk
  end
  @cdroms = [] if @cdroms == UNSET_VALUE
  @cdroms.map! do |cdrom|
    cdrom[:dev] = _get_cdrom_dev(@cdroms) if cdrom[:dev].nil?
    cdrom
  end

  # Inputs
  @inputs = [{ type: 'mouse', bus: 'ps2' }] if @inputs == UNSET_VALUE

  # Channels
  @channels = [] if @channels == UNSET_VALUE

  # PCI device passthrough
  @pcis = [] if @pcis == UNSET_VALUE

  # Random number generator passthrough
  @rng = {} if @rng == UNSET_VALUE

  # Watchdog device
  @watchdog_dev = {} if @watchdog_dev == UNSET_VALUE

  # USB controller
  @usbctl_dev = {} if @usbctl_dev == UNSET_VALUE

  # USB device passthrough
  @usbs = [] if @usbs == UNSET_VALUE

  # Redirected devices
  @redirdevs = [] if @redirdevs == UNSET_VALUE
  @redirfilters = [] if @redirfilters == UNSET_VALUE

  # smartcard device
  @smartcard_dev = {} if @smartcard_dev == UNSET_VALUE

  # Suspend mode
  @suspend_mode = 'pause' if @suspend_mode == UNSET_VALUE

  # Autostart
  @autostart = false if @autostart == UNSET_VALUE

  # Attach mgmt network
  @mgmt_attach = true if @mgmt_attach == UNSET_VALUE

  # Additional QEMU commandline arguments
  @qemu_args = [] if @qemu_args == UNSET_VALUE

  # Additional QEMU commandline environment variables
  @qemu_env = {} if @qemu_env == UNSET_VALUE
end

#hyperv_feature(options = {}) ⇒ Object



371
372
373
374
375
376
377
378
379
380
# File 'lib/vagrant-libvirt/config.rb', line 371

def hyperv_feature(options = {})
  if options[:name].nil? || options[:state].nil?
    raise 'Feature name AND state must be specified'
  end

  @features_hyperv = []  if @features_hyperv == UNSET_VALUE

  @features_hyperv.push(name: options[:name],
                        state: options[:state])
end

#input(options = {}) ⇒ Object



411
412
413
414
415
416
417
418
419
420
# File 'lib/vagrant-libvirt/config.rb', line 411

def input(options = {})
  if options[:type].nil? || options[:bus].nil?
    raise 'Input type AND bus must be specified'
  end

  @inputs = [] if @inputs == UNSET_VALUE

  @inputs.push(type: options[:type],
               bus:  options[:bus])
end

#memorybacking(option, config = {}) ⇒ Object



396
397
398
399
400
401
402
403
404
405
406
407
408
409
# File 'lib/vagrant-libvirt/config.rb', line 396

def memorybacking(option, config = {})
  case option
  when :source
    raise 'Source type must be specified' if config[:type].nil?
  when :access
    raise 'Access mode must be specified' if config[:mode].nil?
  when :allocation
    raise 'Allocation mode must be specified' if config[:mode].nil?
  end

  @memory_backing = [] if @memory_backing == UNSET_VALUE
  @memory_backing.push(name: option,
                       config: config)
end

#merge(other) ⇒ Object



878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
# File 'lib/vagrant-libvirt/config.rb', line 878

def merge(other)
  super.tap do |result|
    c = disks.dup
    c += other.disks
    result.disks = c

    c = cdroms.dup
    c += other.cdroms
    result.cdroms = c

    c = qemu_env != UNSET_VALUE ? qemu_env.dup : {}
    c.merge!(other.qemu_env) if other.qemu_env != UNSET_VALUE
    result.qemu_env = c
  end
end

#pci(options = {}) ⇒ Object



454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
# File 'lib/vagrant-libvirt/config.rb', line 454

def pci(options = {})
  if options[:bus].nil? || options[:slot].nil? || options[:function].nil?
    raise 'Bus AND slot AND function must be specified. Check `lspci` for that numbers.'
  end

  @pcis = [] if @pcis == UNSET_VALUE

  if options[:domain].nil?
    pci_domain = '0x0000'
  else
    pci_domain = options[:domain]
  end

  @pcis.push(domain:    pci_domain,
             bus:       options[:bus],
             slot:      options[:slot],
             function:  options[:function])
end

#qemuargs(options = {}) ⇒ Object



615
616
617
618
619
# File 'lib/vagrant-libvirt/config.rb', line 615

def qemuargs(options = {})
  @qemu_args = [] if @qemu_args == UNSET_VALUE

  @qemu_args << options if options[:value]
end

#qemuenv(options = {}) ⇒ Object



621
622
623
624
625
# File 'lib/vagrant-libvirt/config.rb', line 621

def qemuenv(options = {})
  @qemu_env = {} if @qemu_env == UNSET_VALUE

  @qemu_env.merge!(options)
end

#random(options = {}) ⇒ Object



444
445
446
447
448
449
450
451
452
# File 'lib/vagrant-libvirt/config.rb', line 444

def random(options = {})
  if !options[:model].nil? && options[:model] != 'random'
    raise 'The only supported rng backend is "random".'
  end

  @rng = {} if @rng == UNSET_VALUE

  @rng[:model] = options[:model]
end

#redirdev(options = {}) ⇒ Object



514
515
516
517
518
519
520
# File 'lib/vagrant-libvirt/config.rb', line 514

def redirdev(options = {})
  raise 'Type must be specified.' if options[:type].nil?

  @redirdevs = [] if @redirdevs == UNSET_VALUE

  @redirdevs.push(type: options[:type])
end

#redirfilter(options = {}) ⇒ Object



522
523
524
525
526
527
528
529
530
531
532
# File 'lib/vagrant-libvirt/config.rb', line 522

def redirfilter(options = {})
  raise 'Option allow must be specified.' if options[:allow].nil?

  @redirfilters = [] if @redirfilters == UNSET_VALUE

  @redirfilters.push(class: options[:class] || -1,
                     vendor: options[:vendor] || -1,
                     product: options[:product] || -1,
                     version: options[:version] || -1,
                     allow: options[:allow])
end

#smartcard(options = {}) ⇒ Object



534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
# File 'lib/vagrant-libvirt/config.rb', line 534

def smartcard(options = {})
  if options[:mode].nil?
    raise 'Option mode must be specified.'
  elsif options[:mode] != 'passthrough'
    raise 'Currently only passthrough mode is supported!'
  elsif options[:type] == 'tcp' && (options[:source_mode].nil? || options[:source_host].nil? || options[:source_service].nil?)
    raise 'If using type "tcp", option "source_mode", "source_host" and "source_service" must be specified.'
  end

  if @smartcard_dev == UNSET_VALUE
    @smartcard_dev = {}
  end

  @smartcard_dev[:mode] = options[:mode]
  @smartcard_dev[:type] = options[:type] || 'spicevmc'
  @smartcard_dev[:source_mode] = options[:source_mode] if @smartcard_dev[:type] == 'tcp'
  @smartcard_dev[:source_host] = options[:source_host] if @smartcard_dev[:type] == 'tcp'
  @smartcard_dev[:source_service] = options[:source_service] if @smartcard_dev[:type] == 'tcp'
end

#storage(storage_type, options = {}) ⇒ Object

NOTE: this will run twice for each time it’s needed- keep it idempotent



555
556
557
558
559
560
561
562
563
# File 'lib/vagrant-libvirt/config.rb', line 555

def storage(storage_type, options = {})
  if storage_type == :file
    if options[:device] == :cdrom
      _handle_cdrom_storage(options)
    else
      _handle_disk_storage(options)
    end
  end
end

#usb(options = {}) ⇒ Object



500
501
502
503
504
505
506
507
508
509
510
511
512
# File 'lib/vagrant-libvirt/config.rb', line 500

def usb(options = {})
  if (options[:bus].nil? || options[:device].nil?) && options[:vendor].nil? && options[:product].nil?
    raise 'Bus and device and/or vendor and/or product must be specified. Check `lsusb` for these.'
  end

  @usbs = [] if @usbs == UNSET_VALUE

  @usbs.push(bus:           options[:bus],
             device:        options[:device],
             vendor:        options[:vendor],
             product:       options[:product],
             startupPolicy: options[:startupPolicy])
end

#usb_controller(options = {}) ⇒ Object



487
488
489
490
491
492
493
494
495
496
497
498
# File 'lib/vagrant-libvirt/config.rb', line 487

def usb_controller(options = {})
  if options[:model].nil?
    raise 'USB controller model must be specified.'
  end

  if @usbctl_dev == UNSET_VALUE
      @usbctl_dev = {}
  end

  @usbctl_dev[:model] = options[:model]
  @usbctl_dev[:ports] = options[:ports]
end

#validate(machine) ⇒ Object



846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
# File 'lib/vagrant-libvirt/config.rb', line 846

def validate(machine)
  errors = _detected_errors

  # The @uri and @qemu_use_session should not conflict
  uri = _parse_uri(@uri)
  if (uri.scheme.start_with? "qemu") && (uri.path.include? "session")
    if @qemu_use_session != true
      errors << "the URI and qemu_use_session configuration conflict: uri:'#{@uri}' qemu_use_session:'#{@qemu_use_session}'"
    end
  end

  machine.provider_config.disks.each do |disk|
    if disk[:path] && (disk[:path][0] == '/')
      errors << "absolute volume paths like '#{disk[:path]}' not yet supported"
    end
  end

  machine.config.vm.networks.each do |_type, opts|
    if opts[:mac]
      opts[:mac].downcase!
      if opts[:mac] =~ /\A([0-9a-f]{12})\z/
        opts[:mac] = opts[:mac].scan(/../).join(':')
      end
      unless opts[:mac] =~ /\A([0-9a-f]{2}:){5}([0-9a-f]{2})\z/
        errors << "Configured NIC MAC '#{opts[:mac]}' is not in 'xx:xx:xx:xx:xx:xx' or 'xxxxxxxxxxxx' format"
      end
    end
  end

  { 'Libvirt Provider' => errors }
end

#watchdog(options = {}) ⇒ Object



473
474
475
476
477
478
479
480
481
482
483
484
# File 'lib/vagrant-libvirt/config.rb', line 473

def watchdog(options = {})
  if options[:model].nil?
    raise 'Model must be specified.'
  end

  if @watchdog_dev == UNSET_VALUE
      @watchdog_dev = {}
  end

  @watchdog_dev[:model] = options[:model]
  @watchdog_dev[:action] = options[:action] || 'reset'
end