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
|
||||||
@storage_pool_name = config.storage_pool_name
|
@storage_pool_name = config.storage_pool_name
|
||||||
@disks = config.disks
|
@disks = config.disks
|
||||||
|
@cdrom = config.cdrom
|
||||||
|
|
||||||
config = env[:machine].provider_config
|
config = env[:machine].provider_config
|
||||||
@domain_type = config.driver
|
@domain_type = config.driver
|
||||||
@ -121,6 +122,7 @@ module VagrantPlugins
|
|||||||
@disks.each do |disk|
|
@disks.each do |disk|
|
||||||
env[:ui].info(" -- Disk(#{disk[:device]}): #{disk[:absolute_path]}")
|
env[:ui].info(" -- Disk(#{disk[:device]}): #{disk[:absolute_path]}")
|
||||||
end
|
end
|
||||||
|
env[:ui].info(" -- CDROM: #{@cdrom}")
|
||||||
env[:ui].info(" -- Command line : #{@cmd_line}")
|
env[:ui].info(" -- Command line : #{@cmd_line}")
|
||||||
|
|
||||||
# Create libvirt domain.
|
# Create libvirt domain.
|
||||||
|
@ -74,6 +74,7 @@ module VagrantPlugins
|
|||||||
|
|
||||||
# Storage
|
# Storage
|
||||||
attr_accessor :disks
|
attr_accessor :disks
|
||||||
|
attr_accessor :cdrom
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@uri = UNSET_VALUE
|
@uri = UNSET_VALUE
|
||||||
@ -112,6 +113,7 @@ module VagrantPlugins
|
|||||||
|
|
||||||
# Storage
|
# Storage
|
||||||
@disks = []
|
@disks = []
|
||||||
|
@cdrom = UNSET_VALUE
|
||||||
end
|
end
|
||||||
|
|
||||||
def _get_device(disks)
|
def _get_device(disks)
|
||||||
@ -129,6 +131,40 @@ 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
|
||||||
|
_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 = {
|
options = {
|
||||||
:device => _get_device(@disks),
|
:device => _get_device(@disks),
|
||||||
:type => 'qcow2',
|
:type => 'qcow2',
|
||||||
@ -146,10 +182,8 @@ module VagrantPlugins
|
|||||||
:cache => options[:cache] || 'default',
|
:cache => options[:cache] || 'default',
|
||||||
}
|
}
|
||||||
|
|
||||||
if storage_type == :file
|
|
||||||
@disks << disk # append
|
@disks << disk # append
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# code to generate URI from a config moved out of the connect action
|
# code to generate URI from a config moved out of the connect action
|
||||||
def _generate_uri
|
def _generate_uri
|
||||||
@ -242,6 +276,7 @@ module VagrantPlugins
|
|||||||
|
|
||||||
# Storage
|
# Storage
|
||||||
@disks = [] if @disks == UNSET_VALUE
|
@disks = [] if @disks == UNSET_VALUE
|
||||||
|
@cdrom = nil if @cdrom == UNSET_VALUE
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate(machine)
|
def validate(machine)
|
||||||
|
@ -48,6 +48,15 @@
|
|||||||
-%>
|
-%>
|
||||||
</disk>
|
</disk>
|
||||||
<% end -%>
|
<% 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'>
|
<serial type='pty'>
|
||||||
<target port='0'/>
|
<target port='0'/>
|
||||||
</serial>
|
</serial>
|
||||||
|
Loading…
Reference in New Issue
Block a user