From 192a9e00df8a0824bad8b54ccf0340ca565384a4 Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Mon, 21 Feb 2022 16:12:03 +0000 Subject: [PATCH] Allow serials to be disabled (#1453) Facilitate disabling serial devices by allowing for the configuration to explicitly set serials to an empty array and ignoring adding the default serial if this is the case. --- lib/vagrant-libvirt/config.rb | 14 +++++++++----- lib/vagrant-libvirt/templates/domain.xml.erb | 6 ++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index 5bafe45..6cbcc79 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -341,7 +341,7 @@ module VagrantPlugins # Use Qemu agent to get ip address @qemu_use_agent = UNSET_VALUE - @serials = [] + @serials = UNSET_VALUE end def boot(device) @@ -701,6 +701,8 @@ module VagrantPlugins end def serial(options={}) + @serials = [] if @serials == UNSET_VALUE + options = { :type => "pty", :source => nil, @@ -965,7 +967,7 @@ module VagrantPlugins @qemu_use_agent = false if @qemu_use_agent == UNSET_VALUE - @serials = [{:type => 'pty', :source => nil}] if @serials == [] + @serials = [{:type => 'pty', :source => nil}] if @serials == UNSET_VALUE end def validate(machine) @@ -1061,9 +1063,11 @@ module VagrantPlugins c.merge!(other.qemu_env) if other.qemu_env != UNSET_VALUE result.qemu_env = c - s = serials.dup - s += other.serials - result.serials = s + if serials != UNSET_VALUE + s = serials.dup + s += other.serials + result.serials = s + end end end diff --git a/lib/vagrant-libvirt/templates/domain.xml.erb b/lib/vagrant-libvirt/templates/domain.xml.erb index 8e7fc67..ae5b991 100644 --- a/lib/vagrant-libvirt/templates/domain.xml.erb +++ b/lib/vagrant-libvirt/templates/domain.xml.erb @@ -163,14 +163,16 @@ <%- end -%> - <%- end -%> +<%- end -%> +<%- unless @serials.empty? -%> <%- console_log = @serials.first -%> <%- unless console_log[:source].nil? -%> -<%- end -%> + <%- end -%> +<%- end -%> <%- @channels.each do |channel| -%> <%-if channel[:source_mode] or channel[:source_path] -%>