Floppy support (#1334)

Add support for attaching 1 or 2 floppy drives to the VM using "vfd"
image files.
This commit is contained in:
Oded Arbel
2022-10-08 13:59:06 +03:00
committed by GitHub
parent 35e3730abf
commit d38e130f47
8 changed files with 142 additions and 2 deletions

View File

@@ -101,6 +101,7 @@ module VagrantPlugins
@domain_volumes = env[:domain_volumes] || []
@disks = env[:disks] || []
@cdroms = config.cdroms
@floppies = config.floppies
# Input
@inputs = config.inputs
@@ -326,6 +327,14 @@ module VagrantPlugins
env[:ui].info(" -- CDROM(#{cdrom[:dev]}): #{cdrom[:path]}")
end
unless @floppies.empty?
env[:ui].info(" -- Floppies: #{_floppies_print(@floppies)}")
end
@floppies.each do |floppy|
env[:ui].info(" -- Floppy(#{floppy[:dev]}): #{floppy[:path]}")
end
@inputs.each do |input|
env[:ui].info(" -- INPUT: type=#{input[:type]}, bus=#{input[:bus]}")
end
@@ -443,6 +452,10 @@ module VagrantPlugins
def _cdroms_print(cdroms)
cdroms.collect { |x| x[:dev] }.join(', ')
end
def _floppies_print(floppies)
floppies.collect { |x| x[:dev] }.join(', ')
end
end
end
end

View File

@@ -148,6 +148,7 @@ module VagrantPlugins
# Storage
attr_accessor :disks
attr_accessor :cdroms
attr_accessor :floppies
# Inputs
attr_accessor :inputs
@@ -305,6 +306,7 @@ module VagrantPlugins
# Storage
@disks = []
@cdroms = []
@floppies = []
# Inputs
@inputs = UNSET_VALUE
@@ -382,6 +384,25 @@ module VagrantPlugins
raise 'Only four cdroms may be attached at a time'
end
def _get_floppy_dev(floppies)
exist = Hash[floppies.collect { |x| [x[:dev], true] }]
# fda - fdb
curr = 'a'.ord
while curr <= 'b'.ord
dev = "fd#{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 two floppies may be attached at a time'
end
def _generate_numa
@numa_nodes.collect { |x|
# Perform some validation of cpu values
@@ -654,8 +675,11 @@ module VagrantPlugins
# NOTE: this will run twice for each time it's needed- keep it idempotent
def storage(storage_type, options = {})
if storage_type == :file
if options[:device] == :cdrom
case options[:device]
when :cdrom
_handle_cdrom_storage(options)
when :floppy
_handle_floppy_storage(options)
else
_handle_disk_storage(options)
end
@@ -689,6 +713,28 @@ module VagrantPlugins
@cdroms << cdrom
end
def _handle_floppy_storage(options = {})
# <disk type='file' device='floppy'>
# <source file='/var/lib/libvirt/images/floppy.vfd'/>
# <target dev='fda' bus='fdc'/>
# </disk>
#
# note the target dev will need to be changed with each floppy drive (fda or fdb)
options = {
bus: 'fdc',
path: nil
}.merge(options)
floppy = {
dev: options[:dev],
bus: options[:bus],
path: options[:path]
}
@floppies << floppy
end
def _handle_disk_storage(options = {})
options = {
type: 'qcow2',
@@ -947,6 +993,11 @@ module VagrantPlugins
cdrom[:dev] = _get_cdrom_dev(@cdroms) if cdrom[:dev].nil?
cdrom
end
@floppies = [] if @floppies == UNSET_VALUE
@floppies.map! do |floppy|
floppy[:dev] = _get_floppy_dev(@floppies) if floppy[:dev].nil?
floppy
end
# Inputs
@inputs = [{ type: 'mouse', bus: 'ps2' }] if @inputs == UNSET_VALUE
@@ -1115,6 +1166,10 @@ module VagrantPlugins
c += other.cdroms
result.cdroms = c
c = floppies.dup
c += other.floppies
result.floppies = c
result.disk_driver_opts = disk_driver_opts.merge(other.disk_driver_opts)
result.inputs = inputs != UNSET_VALUE ? inputs.dup + (other.inputs != UNSET_VALUE ? other.inputs : []) : other.inputs

View File

@@ -185,6 +185,12 @@
<readonly/>
</disk>
<%- end -%>
<%- @floppies.each do |f| -%>
<disk type='file' device='floppy'>
<source file='<%= f[:path] %>'/>
<target dev='<%= f[:dev] %>' bus='<%= f[:bus] %>'/>
</disk>
<%- end -%>
<%- @serials.each_with_index do |serial, port| -%>
<serial type='<%= serial[:type] %>'>
<%- unless serial[:source].nil? -%>