can now add local cdrom storage to a box

This commit is contained in:
James Johnson 2015-04-10 10:24:38 -05:00
parent 5b102cfa34
commit b31bfb7056
3 changed files with 49 additions and 3 deletions

View File

@ -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.

View File

@ -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)

View File

@ -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>