From 70bb39224111fad17f58ae9a5b47f5a2c971a4fa Mon Sep 17 00:00:00 2001 From: Michael Ablassmeier Date: Fri, 23 Oct 2020 15:39:14 +0200 Subject: [PATCH] Support separate storage pools for additional disks (#1130) Add support for a pool setting for additional disks, example: Vagrant.configure("2") do |config| config.vm.box = "generic/centos8" config.vm.provider :libvirt do |domain| domain.storage :file, :size => '20G', :pool=>'default' domain.snapshot_pool_name='cache' end end this allows to place the virtual machines snapshot in the "cache" pool, while additional disks are created in the "default" storage pool. --- lib/vagrant-libvirt/action/create_domain.rb | 25 ++++++++++++++++----- lib/vagrant-libvirt/config.rb | 3 ++- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index 2ee3a11..be9cb0e 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -151,10 +151,7 @@ module VagrantPlugins if env[:machine].config.vm.box storage_prefix = File.dirname(@domain_volume_path) + '/' # steal else - storage_pool = env[:machine].provider.driver.connection.client.lookup_storage_pool_by_name(@storage_pool_name) - raise Errors::NoStoragePool if storage_pool.nil? - xml = Nokogiri::XML(storage_pool.xml_desc) - storage_prefix = xml.xpath('/pool/target/path').inner_text.to_s + '/' + storage_prefix = get_disk_storage_prefix(env, @storage_pool_name) end end @@ -169,6 +166,16 @@ module VagrantPlugins disk[:absolute_path] = storage_prefix + disk[:path] + if not disk[:pool].nil? + disk_pool_name = disk[:pool] + @logger.debug "Overriding pool name with: #{disk_pool_name}" + disk_storage_prefix = get_disk_storage_prefix(env, disk_pool_name) + disk[:absolute_path] = disk_storage_prefix + disk[:path] + @logger.debug "Overriding disk path with: #{disk[:absolute_path]}" + else + disk_pool_name = @storage_pool_name + end + # make the disk. equivalent to: # qemu-img create -f qcow2 5g begin @@ -178,7 +185,7 @@ module VagrantPlugins path: disk[:absolute_path], capacity: disk[:size], #:allocation => ?, - pool_name: @storage_pool_name + pool_name: disk_pool_name ) rescue Libvirt::Error => e # It is hard to believe that e contains just a string @@ -366,6 +373,14 @@ module VagrantPlugins @app.call(env) end + + private + def get_disk_storage_prefix(env, disk_pool_name) + disk_storage_pool = env[:machine].provider.driver.connection.client.lookup_storage_pool_by_name(disk_pool_name) + raise Errors::NoStoragePool if disk_storage_pool.nil? + xml = Nokogiri::XML(disk_storage_pool.xml_desc) + disk_storage_prefix = xml.xpath('/pool/target/path').inner_text.to_s + '/' + end end end end diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index a6693f0..4fbc7a8 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -605,7 +605,8 @@ module VagrantPlugins allow_existing: options[:allow_existing], shareable: options[:shareable], serial: options[:serial], - wwn: options[:wwn] + pool: options[:pool], # overrides storage_pool setting for additional disks + wwn: options[:wwn], } @disks << disk # append