mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Floppy support (#1334)
Add support for attaching 1 or 2 floppy drives to the VM using "vfd" image files.
This commit is contained in:
parent
35e3730abf
commit
d38e130f47
@ -685,6 +685,25 @@ Vagrant.configure("2") do |config|
|
|||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Floppies
|
||||||
|
|
||||||
|
You can attach up to two floppies to a VM via `libvirt.storage :file,
|
||||||
|
:device => :floppy`. Available options are:
|
||||||
|
|
||||||
|
* `path` - The path to the vfd image to be used for the floppy drive.
|
||||||
|
* `dev` - The device to use (`fda` or `fdb`). This will be
|
||||||
|
automatically determined if unspecified.
|
||||||
|
|
||||||
|
The following example creates a floppy drive in the VM:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
Vagrant.configure("2") do |config|
|
||||||
|
config.vm.provider :libvirt do |libvirt|
|
||||||
|
libvirt.storage :file, :device => :floppy, :path => '/path/to/floppy.vfs'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
## Input
|
## Input
|
||||||
|
|
||||||
You can specify multiple inputs to the VM via `libvirt.input`. Available
|
You can specify multiple inputs to the VM via `libvirt.input`. Available
|
||||||
|
@ -101,6 +101,7 @@ module VagrantPlugins
|
|||||||
@domain_volumes = env[:domain_volumes] || []
|
@domain_volumes = env[:domain_volumes] || []
|
||||||
@disks = env[:disks] || []
|
@disks = env[:disks] || []
|
||||||
@cdroms = config.cdroms
|
@cdroms = config.cdroms
|
||||||
|
@floppies = config.floppies
|
||||||
|
|
||||||
# Input
|
# Input
|
||||||
@inputs = config.inputs
|
@inputs = config.inputs
|
||||||
@ -326,6 +327,14 @@ module VagrantPlugins
|
|||||||
env[:ui].info(" -- CDROM(#{cdrom[:dev]}): #{cdrom[:path]}")
|
env[:ui].info(" -- CDROM(#{cdrom[:dev]}): #{cdrom[:path]}")
|
||||||
end
|
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|
|
@inputs.each do |input|
|
||||||
env[:ui].info(" -- INPUT: type=#{input[:type]}, bus=#{input[:bus]}")
|
env[:ui].info(" -- INPUT: type=#{input[:type]}, bus=#{input[:bus]}")
|
||||||
end
|
end
|
||||||
@ -443,6 +452,10 @@ module VagrantPlugins
|
|||||||
def _cdroms_print(cdroms)
|
def _cdroms_print(cdroms)
|
||||||
cdroms.collect { |x| x[:dev] }.join(', ')
|
cdroms.collect { |x| x[:dev] }.join(', ')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def _floppies_print(floppies)
|
||||||
|
floppies.collect { |x| x[:dev] }.join(', ')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -148,6 +148,7 @@ module VagrantPlugins
|
|||||||
# Storage
|
# Storage
|
||||||
attr_accessor :disks
|
attr_accessor :disks
|
||||||
attr_accessor :cdroms
|
attr_accessor :cdroms
|
||||||
|
attr_accessor :floppies
|
||||||
|
|
||||||
# Inputs
|
# Inputs
|
||||||
attr_accessor :inputs
|
attr_accessor :inputs
|
||||||
@ -305,6 +306,7 @@ module VagrantPlugins
|
|||||||
# Storage
|
# Storage
|
||||||
@disks = []
|
@disks = []
|
||||||
@cdroms = []
|
@cdroms = []
|
||||||
|
@floppies = []
|
||||||
|
|
||||||
# Inputs
|
# Inputs
|
||||||
@inputs = UNSET_VALUE
|
@inputs = UNSET_VALUE
|
||||||
@ -382,6 +384,25 @@ module VagrantPlugins
|
|||||||
raise 'Only four cdroms may be attached at a time'
|
raise 'Only four cdroms may be attached at a time'
|
||||||
end
|
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
|
def _generate_numa
|
||||||
@numa_nodes.collect { |x|
|
@numa_nodes.collect { |x|
|
||||||
# Perform some validation of cpu values
|
# 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
|
# NOTE: this will run twice for each time it's needed- keep it idempotent
|
||||||
def storage(storage_type, options = {})
|
def storage(storage_type, options = {})
|
||||||
if storage_type == :file
|
if storage_type == :file
|
||||||
if options[:device] == :cdrom
|
case options[:device]
|
||||||
|
when :cdrom
|
||||||
_handle_cdrom_storage(options)
|
_handle_cdrom_storage(options)
|
||||||
|
when :floppy
|
||||||
|
_handle_floppy_storage(options)
|
||||||
else
|
else
|
||||||
_handle_disk_storage(options)
|
_handle_disk_storage(options)
|
||||||
end
|
end
|
||||||
@ -689,6 +713,28 @@ module VagrantPlugins
|
|||||||
@cdroms << cdrom
|
@cdroms << cdrom
|
||||||
end
|
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 = {})
|
def _handle_disk_storage(options = {})
|
||||||
options = {
|
options = {
|
||||||
type: 'qcow2',
|
type: 'qcow2',
|
||||||
@ -947,6 +993,11 @@ module VagrantPlugins
|
|||||||
cdrom[:dev] = _get_cdrom_dev(@cdroms) if cdrom[:dev].nil?
|
cdrom[:dev] = _get_cdrom_dev(@cdroms) if cdrom[:dev].nil?
|
||||||
cdrom
|
cdrom
|
||||||
end
|
end
|
||||||
|
@floppies = [] if @floppies == UNSET_VALUE
|
||||||
|
@floppies.map! do |floppy|
|
||||||
|
floppy[:dev] = _get_floppy_dev(@floppies) if floppy[:dev].nil?
|
||||||
|
floppy
|
||||||
|
end
|
||||||
|
|
||||||
# Inputs
|
# Inputs
|
||||||
@inputs = [{ type: 'mouse', bus: 'ps2' }] if @inputs == UNSET_VALUE
|
@inputs = [{ type: 'mouse', bus: 'ps2' }] if @inputs == UNSET_VALUE
|
||||||
@ -1115,6 +1166,10 @@ module VagrantPlugins
|
|||||||
c += other.cdroms
|
c += other.cdroms
|
||||||
result.cdroms = c
|
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.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
|
result.inputs = inputs != UNSET_VALUE ? inputs.dup + (other.inputs != UNSET_VALUE ? other.inputs : []) : other.inputs
|
||||||
|
@ -185,6 +185,12 @@
|
|||||||
<readonly/>
|
<readonly/>
|
||||||
</disk>
|
</disk>
|
||||||
<%- end -%>
|
<%- 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| -%>
|
<%- @serials.each_with_index do |serial, port| -%>
|
||||||
<serial type='<%= serial[:type] %>'>
|
<serial type='<%= serial[:type] %>'>
|
||||||
<%- unless serial[:source].nil? -%>
|
<%- unless serial[:source].nil? -%>
|
||||||
|
@ -20,7 +20,7 @@ class EnvironmentHelper
|
|||||||
1024
|
1024
|
||||||
end
|
end
|
||||||
|
|
||||||
%w(cpus cpu_mode loader nvram boot_order machine_type disk_bus disk_device nested volume_cache kernel cmd_line initrd graphics_type graphics_autoport graphics_port graphics_ip graphics_passwd video_type video_vram keymap storage_pool_name disks cdroms driver).each do |name|
|
%w(cpus cpu_mode loader nvram boot_order machine_type disk_bus disk_device nested volume_cache kernel cmd_line initrd graphics_type graphics_autoport graphics_port graphics_ip graphics_passwd video_type video_vram keymap storage_pool_name disks cdroms floppies driver).each do |name|
|
||||||
define_method(name.to_sym) do
|
define_method(name.to_sym) do
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
@ -873,6 +873,26 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with cdroms and floppies' do
|
||||||
|
it 'should be invalid if too many cdroms' do
|
||||||
|
subject.storage :file, :device => :cdrom
|
||||||
|
subject.storage :file, :device => :cdrom
|
||||||
|
subject.storage :file, :device => :cdrom
|
||||||
|
subject.storage :file, :device => :cdrom
|
||||||
|
subject.storage :file, :device => :cdrom
|
||||||
|
|
||||||
|
expect{ subject.finalize! }.to raise_error('Only four cdroms may be attached at a time')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'sould be invalid if too many floppies' do
|
||||||
|
subject.storage :file, :device => :floppy
|
||||||
|
subject.storage :file, :device => :floppy
|
||||||
|
subject.storage :file, :device => :floppy
|
||||||
|
|
||||||
|
expect{ subject.finalize! }.to raise_error('Only two floppies may be attached at a time')
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#merge' do
|
describe '#merge' do
|
||||||
@ -925,6 +945,28 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with floppies only' do
|
||||||
|
context 'assigned specific devs' do
|
||||||
|
it 'should merge floppies with specific devices' do
|
||||||
|
one.storage(:file, device: :floppy, dev: 'fda')
|
||||||
|
two.storage(:file, device: :floppy, dev: 'fdb')
|
||||||
|
subject.finalize!
|
||||||
|
expect(subject.floppies).to include(include(dev: 'fda'),
|
||||||
|
include(dev: 'fdb'))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'without devs given' do
|
||||||
|
it 'should merge floppies with different devs assigned automatically' do
|
||||||
|
one.storage(:file, device: :floppy)
|
||||||
|
two.storage(:file, device: :floppy)
|
||||||
|
subject.finalize!
|
||||||
|
expect(subject.floppies).to include(include(dev: 'fda'),
|
||||||
|
include(dev: 'fdb'))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'clock_timers' do
|
context 'clock_timers' do
|
||||||
|
@ -85,6 +85,10 @@
|
|||||||
<target dev='hdb' bus='ide'/>
|
<target dev='hdb' bus='ide'/>
|
||||||
<readonly/>
|
<readonly/>
|
||||||
</disk>
|
</disk>
|
||||||
|
<disk type='file' device='floppy'>
|
||||||
|
<source file=''/>
|
||||||
|
<target dev='fda' bus='fdc'/>
|
||||||
|
</disk>
|
||||||
<serial type='file'>
|
<serial type='file'>
|
||||||
<source path='/var/log/vm_consoles/machine.log'/>
|
<source path='/var/log/vm_consoles/machine.log'/>
|
||||||
<target port='0'/>
|
<target port='0'/>
|
||||||
|
@ -81,6 +81,7 @@ describe 'templates/domain' do
|
|||||||
domain.disk_driver(:cache => 'unsafe', :io => 'threads', :copy_on_read => 'on', :discard => 'unmap', :detect_zeroes => 'on')
|
domain.disk_driver(:cache => 'unsafe', :io => 'threads', :copy_on_read => 'on', :discard => 'unmap', :detect_zeroes => 'on')
|
||||||
domain.storage(:file, path: 'test-disk1.qcow2')
|
domain.storage(:file, path: 'test-disk1.qcow2')
|
||||||
domain.storage(:file, path: 'test-disk2.qcow2', io: 'threads', copy_on_read: 'on', discard: 'unmap', detect_zeroes: 'on')
|
domain.storage(:file, path: 'test-disk2.qcow2', io: 'threads', copy_on_read: 'on', discard: 'unmap', detect_zeroes: 'on')
|
||||||
|
domain.storage(:file, device: :floppy)
|
||||||
domain.storage(:file, device: :cdrom)
|
domain.storage(:file, device: :cdrom)
|
||||||
domain.storage(:file, device: :cdrom)
|
domain.storage(:file, device: :cdrom)
|
||||||
domain.channel(type: 'unix',
|
domain.channel(type: 'unix',
|
||||||
|
Loading…
Reference in New Issue
Block a user