[DRE-commits] [vagrant-libvirt] 145/163: * fixed indentation (hopefully did not introduce more indentation problems) * undid extra refactoring * supports up to four cdroms (hda-hdd)

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 e6a4bd4ae0dc7f3be6c78ffcc26d02a9da8f68df
Author: James Johnson <james.johnson at accuvant.com>
Date:   Fri Apr 10 15:02:42 2015 -0500

    * fixed indentation (hopefully did not introduce more indentation problems)
    * undid extra refactoring
    * supports up to four cdroms (hda-hdd)
---
 lib/vagrant-libvirt/action/create_domain.rb  | 14 ++++++--
 lib/vagrant-libvirt/config.rb                | 48 ++++++++++++++++++++--------
 lib/vagrant-libvirt/templates/domain.xml.erb |  6 ++--
 3 files changed, 49 insertions(+), 19 deletions(-)

diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb
index 7cb988b..687437c 100644
--- a/lib/vagrant-libvirt/action/create_domain.rb
+++ b/lib/vagrant-libvirt/action/create_domain.rb
@@ -20,6 +20,10 @@ module VagrantPlugins
           return disks.collect{ |x| x[:device]+'('+x[:type]+','+x[:size]+')' }.join(', ')
         end
 
+        def _cdroms_print(cdroms)
+          return cdroms.collect{ |x| x[:dev] }.join(', ')
+        end
+
         def call(env)
           # Get config.
           config = env[:machine].provider_config
@@ -52,7 +56,7 @@ module VagrantPlugins
           # Storage
           @storage_pool_name = config.storage_pool_name
           @disks = config.disks
-		  @cdrom = config.cdrom
+          @cdroms = config.cdroms
 
           config = env[:machine].provider_config
           @domain_type = config.driver
@@ -122,7 +126,13 @@ module VagrantPlugins
           @disks.each do |disk|
             env[:ui].info(" -- Disk(#{disk[:device]}):     #{disk[:absolute_path]}")
           end
-          env[:ui].info(" -- CDROM:             #{@cdrom}")
+
+          if @cdroms.length > 0
+            env[:ui].info(" -- CDROMS:            #{_cdroms_print(@cdroms)}")
+          end
+          @cdroms.each do |cdrom|
+            env[:ui].info(" -- CDROM(#{cdrom[:dev]}):     #{cdrom[:path]}")
+          end
           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 d7cf921..70c6758 100644
--- a/lib/vagrant-libvirt/config.rb
+++ b/lib/vagrant-libvirt/config.rb
@@ -74,7 +74,7 @@ module VagrantPlugins
 
       # Storage
       attr_accessor :disks
-  	  attr_accessor :cdrom
+  	  attr_accessor :cdroms
 
       def initialize
         @uri               = UNSET_VALUE
@@ -113,7 +113,7 @@ module VagrantPlugins
 
         # Storage
         @disks             = []
-        @cdrom			       = UNSET_VALUE
+        @cdroms			       = []
       end
 
       def _get_device(disks)
@@ -129,18 +129,32 @@ module VagrantPlugins
         end
       end
 
-      # 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)
+      def _get_cdrom_dev(cdroms)
+        exist = Hash[cdroms.collect{|x| [x[:dev],true]}]
+        # hda - hdc
+        curr = "a".ord
+        while curr <= "d".ord
+          dev = "hd" + 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 four cdroms may be attached at a time"
       end
 
-      def _handle_file_storage(options={})
-        if options[:device] == :cdrom
-          _handle_cdrom_storage(options)
-        else
-          _handle_disk_storage(options)
+      # NOTE: this will run twice for each time it's needed- keep it idempotent
+      def storage(storage_type, options={})
+        if storage_type == :file
+          if options[:device] == :cdrom
+            _handle_cdrom_storage(options)
+          else
+            _handle_disk_storage(options)
+          end
         end
       end
 
@@ -149,19 +163,25 @@ module VagrantPlugins
         #   <source file="/home/user/virtio-win-0.1-100.iso"/>
         #   <target dev="hdc"/>
         #   <readonly/>
+        #   <address type='drive' controller='0' bus='1' target='0' unit='0'/>
         # </disk>
+        #
+        # note the target dev will need to be changed with each cdrom drive (hdc, hdd, etc),
+        # as will the address unit number (unit=0, unit=1, etc)
 
         options = {
-          :dev => "hdc",
+          :dev => self._get_cdrom_dev(@cdroms),
           :bus => "ide",
           :path => nil,
         }.merge(options)
 
-        @cdrom = {
+        cdrom = {
           :dev => options[:dev],
           :bus => options[:bus],
           :path => options[:path]
         }
+
+        @cdroms << cdrom
       end
 
       def _handle_disk_storage(options={})
@@ -276,7 +296,7 @@ module VagrantPlugins
 
         # Storage
         @disks = [] if @disks == UNSET_VALUE
-        @cdrom = nil if @cdrom == UNSET_VALUE
+        @cdroms = [] if @cdroms == 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 33e6762..3f06c78 100644
--- a/lib/vagrant-libvirt/templates/domain.xml.erb
+++ b/lib/vagrant-libvirt/templates/domain.xml.erb
@@ -49,10 +49,10 @@
     </disk>
 <% end -%>
 
-<% if @cdrom %>
+<% @cdroms.each do |c| %>
     <disk type='file' device='cdrom'>
-      <source file='<%= @cdrom[:path] %>'/>
-      <target dev='<%= @cdrom[:dev] %>' bus='<%= @cdrom[:bus] %>'/>
+      <source file='<%= c[:path] %>'/>
+      <target dev='<%= c[:dev] %>' bus='<%= c[:bus] %>'/>
       <readonly/>
     </disk>
 <% end %>

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