From 8f6e2326c8ed860a80063d32b23119184a24178d Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Wed, 15 Oct 2014 23:56:01 +0100 Subject: [PATCH 1/3] honour path parameter of storage directive Fix use of the `:path` parameter to the `storage` directive: config.vm.provider :libvirt do |libvirt| libvirt.storage :file, :path => 'my-disk.qcow2' end The value of the `:path` parameter was being correctly used in `domain.xml.erb` for defining the VM, but it was not passed to libvirt via fog's volume creation mechanism: lib/fog/libvirt/models/compute/templates/volume.xml.erb Instead, libvirt determines the backing file from the `` element, so we ensure that the `:name` parameter contains the correct filename. --- lib/vagrant-libvirt/action/create_domain.rb | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index 123cb08..0a7d2ef 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -66,15 +66,28 @@ module VagrantPlugins storage_prefix = File.dirname(@domain_volume_path)+'/' # steal @disks.each do |disk| - disk[:name] = _disk_name(@name, disk) - if disk[:path].nil? - disk[:path] = "#{storage_prefix}#{_disk_name(@name, disk)}" # automatically chosen! + if disk[:path] and disk[:path][0] == '/' + raise Errors::FogCreateVolumeError, + :error_message => + "absolute volume path '#{disk[:path]}' not yet supported" + end + + disk[:path] ||= _disk_name(@name, disk) + + # On volume creation, the element inside + # is oddly ignored; instead the path is taken from the + # element: + # http://www.redhat.com/archives/libvir-list/2008-August/msg00329.html + disk[:name] = disk[:path] + + # Prefix relative paths by storage pool path + unless disk[:path][0] == '/' + disk[:path] = storage_prefix + disk[:path] end # make the disk. equivalent to: # qemu-img create -f qcow2 5g begin - #puts "Making disk: #{d}, #{t}, #{p}" domain_volume_disk = env[:libvirt_compute].volumes.create( :name => disk[:name], :format_type => disk[:type], From f39797fa6adf957fa452be36d52cf1dbb4ca7378 Mon Sep 17 00:00:00 2001 From: Brian Pitts Date: Mon, 17 Nov 2014 21:35:38 -0600 Subject: [PATCH 2/3] Check for absolute disk path in #validate --- lib/vagrant-libvirt/action/create_domain.rb | 5 ----- lib/vagrant-libvirt/config.rb | 10 ++++++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index 0a7d2ef..a49e4fe 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -66,11 +66,6 @@ module VagrantPlugins storage_prefix = File.dirname(@domain_volume_path)+'/' # steal @disks.each do |disk| - if disk[:path] and disk[:path][0] == '/' - raise Errors::FogCreateVolumeError, - :error_message => - "absolute volume path '#{disk[:path]}' not yet supported" - end disk[:path] ||= _disk_name(@name, disk) diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index 3186309..12e049e 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -243,7 +243,17 @@ module VagrantPlugins end def validate(machine) + errors = _detected_errors + + machine.provider_config.disks.each do |disk| + if disk[:path] and disk[:path][0] == '/' + errors << "absolute volume paths like '#{disk[:path]}' not yet supported" + end + end + + { "Libvirt Provider" => errors } end + end end end From a5b5e3e800fcc1b633a651509c85a91555575232 Mon Sep 17 00:00:00 2001 From: Brian Pitts Date: Mon, 17 Nov 2014 22:47:32 -0600 Subject: [PATCH 3/3] Do not chance disk path Mutating path caused vagrant to constatnyl spew errors from #validate while waiting for ssh to be available. Instead, create a new key. --- lib/vagrant-libvirt/action/create_domain.rb | 9 +++------ lib/vagrant-libvirt/templates/domain.xml.erb | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index a49e4fe..094fe96 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -75,10 +75,7 @@ module VagrantPlugins # http://www.redhat.com/archives/libvir-list/2008-August/msg00329.html disk[:name] = disk[:path] - # Prefix relative paths by storage pool path - unless disk[:path][0] == '/' - disk[:path] = storage_prefix + disk[:path] - end + disk[:absolute_path] = storage_prefix + disk[:path] # make the disk. equivalent to: # qemu-img create -f qcow2 5g @@ -86,7 +83,7 @@ module VagrantPlugins domain_volume_disk = env[:libvirt_compute].volumes.create( :name => disk[:name], :format_type => disk[:type], - :path => disk[:path], + :path => disk[:absolute_path], :capacity => disk[:size], #:allocation => ?, :pool_name => @storage_pool_name) @@ -119,7 +116,7 @@ module VagrantPlugins env[:ui].info(" -- Disks: #{_disks_print(@disks)}") end @disks.each do |disk| - env[:ui].info(" -- Disk(#{disk[:device]}): #{disk[:path]}") + env[:ui].info(" -- Disk(#{disk[:device]}): #{disk[:absolute_path]}") end env[:ui].info(" -- Command line : #{@cmd_line}") diff --git a/lib/vagrant-libvirt/templates/domain.xml.erb b/lib/vagrant-libvirt/templates/domain.xml.erb index 1db5894..7351448 100644 --- a/lib/vagrant-libvirt/templates/domain.xml.erb +++ b/lib/vagrant-libvirt/templates/domain.xml.erb @@ -37,7 +37,7 @@ <% @disks.each do |d| -%> - + <%# this will get auto generated by libvirt