[DRE-commits] [vagrant-libvirt] 143/163: can now add local cdrom storage to a box
Antonio Terceiro
terceiro at moszumanska.debian.org
Sun Apr 24 13:57:17 UTC 2016
This is an automated email from the git hooks/post-receive script.
terceiro pushed a commit to annotated tag 0.0.26
in repository vagrant-libvirt.
commit b31bfb70566d2d25143f95d8afc06be825057c67
Author: James Johnson <james.johnson at accuvant.com>
Date: Fri Apr 10 10:24:38 2015 -0500
can now add local cdrom storage to a box
---
lib/vagrant-libvirt/action/create_domain.rb | 2 ++
lib/vagrant-libvirt/config.rb | 41 ++++++++++++++++++++++++++--
lib/vagrant-libvirt/templates/domain.xml.erb | 9 ++++++
3 files changed, 49 insertions(+), 3 deletions(-)
diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb
index 1b1bde2..7cb988b 100644
--- a/lib/vagrant-libvirt/action/create_domain.rb
+++ b/lib/vagrant-libvirt/action/create_domain.rb
@@ -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.
diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb
index a27921b..d7cf921 100644
--- a/lib/vagrant-libvirt/config.rb
+++ b/lib/vagrant-libvirt/config.rb
@@ -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)
diff --git a/lib/vagrant-libvirt/templates/domain.xml.erb b/lib/vagrant-libvirt/templates/domain.xml.erb
index eebb8e2..33e6762 100644
--- a/lib/vagrant-libvirt/templates/domain.xml.erb
+++ b/lib/vagrant-libvirt/templates/domain.xml.erb
@@ -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>
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/vagrant-libvirt.git
More information about the Pkg-ruby-extras-commits
mailing list