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.
This commit is contained in:
Darragh Bailey
2022-02-21 16:12:03 +00:00
committed by GitHub
parent 23ddab1dcf
commit 192a9e00df
2 changed files with 13 additions and 7 deletions

View File

@@ -341,7 +341,7 @@ module VagrantPlugins
# Use Qemu agent to get ip address # Use Qemu agent to get ip address
@qemu_use_agent = UNSET_VALUE @qemu_use_agent = UNSET_VALUE
@serials = [] @serials = UNSET_VALUE
end end
def boot(device) def boot(device)
@@ -701,6 +701,8 @@ module VagrantPlugins
end end
def serial(options={}) def serial(options={})
@serials = [] if @serials == UNSET_VALUE
options = { options = {
:type => "pty", :type => "pty",
:source => nil, :source => nil,
@@ -965,7 +967,7 @@ module VagrantPlugins
@qemu_use_agent = false if @qemu_use_agent == UNSET_VALUE @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 end
def validate(machine) def validate(machine)
@@ -1061,9 +1063,11 @@ module VagrantPlugins
c.merge!(other.qemu_env) if other.qemu_env != UNSET_VALUE c.merge!(other.qemu_env) if other.qemu_env != UNSET_VALUE
result.qemu_env = c result.qemu_env = c
s = serials.dup if serials != UNSET_VALUE
s += other.serials s = serials.dup
result.serials = s s += other.serials
result.serials = s
end
end end
end end

View File

@@ -163,14 +163,16 @@
<%- end -%> <%- end -%>
<target port='<%= port %>'/> <target port='<%= port %>'/>
</serial> </serial>
<%- end -%> <%- end -%>
<%- unless @serials.empty? -%>
<%- console_log = @serials.first -%> <%- console_log = @serials.first -%>
<console type='<%= console_log[:type] %>'> <console type='<%= console_log[:type] %>'>
<%- unless console_log[:source].nil? -%> <%- unless console_log[:source].nil? -%>
<source path='<%= console_log[:source][:path] %>'/> <source path='<%= console_log[:source][:path] %>'/>
<%- end -%> <%- end -%>
<target port='0'/> <target port='0'/>
</console> </console>
<%- end -%>
<%- @channels.each do |channel| -%> <%- @channels.each do |channel| -%>
<channel type='<%= channel[:type] %>' > <channel type='<%= channel[:type] %>' >
<%-if channel[:source_mode] or channel[:source_path] -%> <%-if channel[:source_mode] or channel[:source_path] -%>