From 93cc6fba2013d05ad7935e7f0c74ce69225339cc Mon Sep 17 00:00:00 2001 From: Steffen Froemer Date: Tue, 10 Jan 2017 00:10:56 +0100 Subject: [PATCH] adding watchdog device support fixed spec file updated spec file fixed spec tests --- README.md | 27 ++++++++++++++++++++ lib/vagrant-libvirt/action/create_domain.rb | 7 +++++ lib/vagrant-libvirt/config.rb | 23 +++++++++++++++++ lib/vagrant-libvirt/templates/domain.xml.erb | 4 +++ spec/unit/templates/domain_all_settings.xml | 1 + spec/unit/templates/domain_spec.rb | 1 + 6 files changed, 63 insertions(+) diff --git a/README.md b/README.md index 0fbd837..6005d40 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ In the table below, build passing means that specific version combination of Vag - [PCI device passthrough](#pci-device-passthrough) - [USB Redirector Devices](#usb-redirector-devices) - [Random number generator passthrough](#random-number-generator-passthrough) +- [Watchdog·Device](#watchdog-device) - [CPU Features](#cpu-features) - [No box and PXE boot](#no-box-and-pxe-boot) - [SSH Access To VM](#ssh-access-to-vm) @@ -854,6 +855,32 @@ end At the moment only the `random` backend is supported. +## Watchdog device +A virtual hardware watchdog device can be added to the guest via the `libvirt.watchdog` element. The option `model` is mandatory and could have on of the following values. + +* `i6300esb` - the recommended device, emulating a PCI Intel 6300ESB +* 'ib700` - emulating an ISA iBase IB700 +* `diag288` - emulating an S390 DIAG288 device + +The optional action attribute describes what `action` to take when the watchdog expires. Valid values are specific to the underlying hypervisor. The default behavior is `reset`. + +* `reset` - default, forcefully reset the guest +* `shutdown` - gracefully shutdown the guest (not recommended) +* `poweroff` - forcefully power off the guest +* `pause` - pause the guest +* `none` - do nothing +* `dump` - automatically dump the guest +* `inject-nmi` - inject a non-maskable interrupt into the guest + +```ruby +Vagrant.configure("2") do |config| + config.vm.provider :libvirt do |libvirt| + # Add libvirt watchdog device model i6300esb + libvirt.watchdog :model => 'i6300esb', :action => 'reset' + end +end +``` + ## CPU features You can specify CPU feature policies via `libvirt.cpu_feature`. Available diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index 74c4e8c..fbc77d0 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -85,6 +85,9 @@ module VagrantPlugins # PCI device passthrough @pcis = config.pcis + + # Watchdog device + @watchdog_dev = config.watchdog_dev # USB device passthrough @usbs = config.usbs @@ -230,6 +233,10 @@ module VagrantPlugins env[:ui].info(" -- RNG device model: #{@rng[:model]}") end + if not @watchdog_dev.empty? + env[:ui].info(" -- Watchdog device: model=#{@watchdog_dev[:model]}, action=#{@watchdog_dev[:action]}") + end + @usbs.each do |usb| usb_dev = [] usb_dev.push("bus=#{usb[:bus]}") if usb[:bus] diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index e93cbd3..7346b57 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -116,6 +116,9 @@ module VagrantPlugins # Random number device passthrough attr_accessor :rng + # Watchdog device + attr_accessor :watchdog_dev + # USB device passthrough attr_accessor :usbs @@ -204,6 +207,9 @@ module VagrantPlugins # Random number device passthrough @rng = UNSET_VALUE + + # Watchdog device + @watchdog_dev = UNSET_VALUE # USB device passthrough @usbs = UNSET_VALUE @@ -343,6 +349,20 @@ module VagrantPlugins slot: options[:slot], function: options[:function]) end + + 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 + def usb(options = {}) if (options[:bus].nil? || options[:device].nil?) && options[:vendor].nil? && options[:product].nil? @@ -574,6 +594,9 @@ module VagrantPlugins # Random number generator passthrough @rng = {} if @rng == UNSET_VALUE + # Watchdog device + @watchdog_dev = {} if @watchdog_dev == UNSET_VALUE + # USB device passthrough @usbs = [] if @usbs == UNSET_VALUE diff --git a/lib/vagrant-libvirt/templates/domain.xml.erb b/lib/vagrant-libvirt/templates/domain.xml.erb index 1e3e416..de127b8 100644 --- a/lib/vagrant-libvirt/templates/domain.xml.erb +++ b/lib/vagrant-libvirt/templates/domain.xml.erb @@ -183,6 +183,10 @@ <% end %> <% end %> + <% unless @watchdog_dev.empty? %> + <%# Watchdog Device -%> + + <% end %> <% if @tpm_path -%> <%# TPM Device -%> diff --git a/spec/unit/templates/domain_all_settings.xml b/spec/unit/templates/domain_all_settings.xml index b810415..929a03a 100644 --- a/spec/unit/templates/domain_all_settings.xml +++ b/spec/unit/templates/domain_all_settings.xml @@ -115,6 +115,7 @@ + diff --git a/spec/unit/templates/domain_spec.rb b/spec/unit/templates/domain_spec.rb index c3cf59e..8a2a357 100644 --- a/spec/unit/templates/domain_spec.rb +++ b/spec/unit/templates/domain_spec.rb @@ -58,6 +58,7 @@ describe 'templates/domain' do domain.redirdev(type: 'tcp', host: 'localhost', port: '4000') domain.redirfilter(class: '0x0b', vendor: '0x08e6', product: '0x3437', version: '2.00', allow: 'yes') + domain.watchdog(model: 'i6300esb', action: 'reset') domain.tpm_path = '/dev/tpm0' end let(:test_file) { 'domain_all_settings.xml' }