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.
This commit is contained in:
Michael Ablassmeier 2020-10-23 15:39:14 +02:00 committed by GitHub
parent 06e31d3918
commit 70bb392241
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 6 deletions

View File

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

View File

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