mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
can now add local cdrom storage to a box
This commit is contained in:
parent
5b102cfa34
commit
b31bfb7056
@ -52,6 +52,7 @@ module VagrantPlugins
|
||||
# Storage
|
||||
@storage_pool_name = config.storage_pool_name
|
||||
@disks = config.disks
|
||||
@cdrom = config.cdrom
|
||||
|
||||
config = env[:machine].provider_config
|
||||
@domain_type = config.driver
|
||||
@ -121,6 +122,7 @@ module VagrantPlugins
|
||||
@disks.each do |disk|
|
||||
env[:ui].info(" -- Disk(#{disk[:device]}): #{disk[:absolute_path]}")
|
||||
end
|
||||
env[:ui].info(" -- CDROM: #{@cdrom}")
|
||||
env[:ui].info(" -- Command line : #{@cmd_line}")
|
||||
|
||||
# Create libvirt domain.
|
||||
|
@ -74,6 +74,7 @@ module VagrantPlugins
|
||||
|
||||
# Storage
|
||||
attr_accessor :disks
|
||||
attr_accessor :cdrom
|
||||
|
||||
def initialize
|
||||
@uri = UNSET_VALUE
|
||||
@ -112,6 +113,7 @@ module VagrantPlugins
|
||||
|
||||
# Storage
|
||||
@disks = []
|
||||
@cdrom = UNSET_VALUE
|
||||
end
|
||||
|
||||
def _get_device(disks)
|
||||
@ -129,6 +131,40 @@ 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
|
||||
_handle_file_storage(options)
|
||||
end
|
||||
end
|
||||
|
||||
def _handle_file_storage(options={})
|
||||
if options[:device] == :cdrom
|
||||
_handle_cdrom_storage(options)
|
||||
else
|
||||
_handle_disk_storage(options)
|
||||
end
|
||||
end
|
||||
|
||||
def _handle_cdrom_storage(options={})
|
||||
# <disk type="file" device="cdrom">
|
||||
# <source file="/home/user/virtio-win-0.1-100.iso"/>
|
||||
# <target dev="hdc"/>
|
||||
# <readonly/>
|
||||
# </disk>
|
||||
|
||||
options = {
|
||||
:dev => "hdc",
|
||||
:bus => "ide",
|
||||
:path => nil,
|
||||
}.merge(options)
|
||||
|
||||
@cdrom = {
|
||||
:dev => options[:dev],
|
||||
:bus => options[:bus],
|
||||
:path => options[:path]
|
||||
}
|
||||
end
|
||||
|
||||
def _handle_disk_storage(options={})
|
||||
options = {
|
||||
:device => _get_device(@disks),
|
||||
:type => 'qcow2',
|
||||
@ -146,9 +182,7 @@ module VagrantPlugins
|
||||
:cache => options[:cache] || 'default',
|
||||
}
|
||||
|
||||
if storage_type == :file
|
||||
@disks << disk # append
|
||||
end
|
||||
@disks << disk # append
|
||||
end
|
||||
|
||||
# code to generate URI from a config moved out of the connect action
|
||||
@ -242,6 +276,7 @@ module VagrantPlugins
|
||||
|
||||
# Storage
|
||||
@disks = [] if @disks == UNSET_VALUE
|
||||
@cdrom = nil if @cdrom == UNSET_VALUE
|
||||
end
|
||||
|
||||
def validate(machine)
|
||||
|
@ -48,6 +48,15 @@
|
||||
-%>
|
||||
</disk>
|
||||
<% end -%>
|
||||
|
||||
<% if @cdrom %>
|
||||
<disk type='file' device='cdrom'>
|
||||
<source file='<%= @cdrom[:path] %>'/>
|
||||
<target dev='<%= @cdrom[:dev] %>' bus='<%= @cdrom[:bus] %>'/>
|
||||
<readonly/>
|
||||
</disk>
|
||||
<% end %>
|
||||
|
||||
<serial type='pty'>
|
||||
<target port='0'/>
|
||||
</serial>
|
||||
|
Loading…
Reference in New Issue
Block a user