mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Merge pull request #1030 from voxik/use-fog-libvirt-for-volume-management
Use fog-libvirt facilities to create volumes for QEMU session.
This commit is contained in:
@@ -4,7 +4,6 @@ module VagrantPlugins
|
||||
module ProviderLibvirt
|
||||
module Action
|
||||
class HandleBoxImage
|
||||
include VagrantPlugins::ProviderLibvirt::Util::ErbTemplate
|
||||
include VagrantPlugins::ProviderLibvirt::Util::StorageUtil
|
||||
|
||||
|
||||
@@ -81,40 +80,19 @@ module VagrantPlugins
|
||||
message << " in storage pool #{config.storage_pool_name}."
|
||||
@logger.info(message)
|
||||
|
||||
if config.qemu_use_session
|
||||
begin
|
||||
@name = env[:box_volume_name]
|
||||
@allocation = "#{box_image_size / 1024 / 1024}M"
|
||||
@capacity = "#{box_virtual_size}G"
|
||||
@format_type = box_format ? box_format : 'raw'
|
||||
|
||||
@storage_volume_uid = storage_uid env
|
||||
@storage_volume_gid = storage_gid env
|
||||
|
||||
libvirt_client = env[:machine].provider.driver.connection.client
|
||||
libvirt_pool = libvirt_client.lookup_storage_pool_by_name(
|
||||
config.storage_pool_name
|
||||
)
|
||||
libvirt_volume = libvirt_pool.create_volume_xml(
|
||||
to_xml('default_storage_volume')
|
||||
)
|
||||
rescue => e
|
||||
raise Errors::CreatingVolumeError,
|
||||
error_message: e.message
|
||||
end
|
||||
else
|
||||
begin
|
||||
fog_volume = env[:machine].provider.driver.connection.volumes.create(
|
||||
name: env[:box_volume_name],
|
||||
allocation: "#{box_image_size / 1024 / 1024}M",
|
||||
capacity: "#{box_virtual_size}G",
|
||||
format_type: box_format,
|
||||
pool_name: config.storage_pool_name
|
||||
)
|
||||
rescue Fog::Errors::Error => e
|
||||
raise Errors::FogCreateVolumeError,
|
||||
error_message: e.message
|
||||
end
|
||||
begin
|
||||
fog_volume = env[:machine].provider.driver.connection.volumes.create(
|
||||
name: env[:box_volume_name],
|
||||
allocation: "#{box_image_size / 1024 / 1024}M",
|
||||
capacity: "#{box_virtual_size}G",
|
||||
format_type: box_format,
|
||||
owner: storage_uid env,
|
||||
group: storage_gid env,
|
||||
pool_name: config.storage_pool_name
|
||||
)
|
||||
rescue Fog::Errors::Error => e
|
||||
raise Errors::FogCreateVolumeError,
|
||||
error_message: e.message
|
||||
end
|
||||
|
||||
# Upload box image to storage pool
|
||||
@@ -132,11 +110,7 @@ module VagrantPlugins
|
||||
# storage pool.
|
||||
if env[:interrupted] || !ret
|
||||
begin
|
||||
if config.qemu_use_session
|
||||
libvirt_volume.delete
|
||||
else
|
||||
fog_volume.destroy
|
||||
end
|
||||
fog_volume.destroy
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
@@ -146,19 +120,6 @@ module VagrantPlugins
|
||||
@app.call(env)
|
||||
end
|
||||
|
||||
def split_size_unit(text)
|
||||
if text.kind_of? Integer
|
||||
# if text is an integer, match will fail
|
||||
size = text
|
||||
unit = 'G'
|
||||
else
|
||||
matcher = text.match(/(\d+)(.+)/)
|
||||
size = matcher[1]
|
||||
unit = matcher[2]
|
||||
end
|
||||
[size, unit]
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Fog Libvirt currently doesn't support uploading images to storage
|
||||
|
||||
@@ -29,10 +29,6 @@ module VagrantPlugins
|
||||
error_key(:creating_storage_pool_error)
|
||||
end
|
||||
|
||||
class CreatingVolumeError < VagrantLibvirtError
|
||||
error_key(:creating_volume_error)
|
||||
end
|
||||
|
||||
class ImageUploadError < VagrantLibvirtError
|
||||
error_key(:image_upload_error)
|
||||
end
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
<volume>
|
||||
<name><%= @name %></name>
|
||||
<allocation unit="<%= split_size_unit(@allocation)[1] %>"><%= split_size_unit(@allocation)[0] %></allocation>
|
||||
<capacity unit="<%= split_size_unit(@capacity)[1] %>"><%= split_size_unit(@capacity)[0] %></capacity>
|
||||
<target>
|
||||
<format type="<%= @format_type %>"/>
|
||||
<permissions>
|
||||
<owner><%= @storage_volume_uid %></owner>
|
||||
<group><%= @storage_volume_gid %></group>
|
||||
<mode>0744</mode>
|
||||
<label>virt_image_t</label>
|
||||
</permissions>
|
||||
</target>
|
||||
</volume>
|
||||
@@ -109,8 +109,6 @@ en:
|
||||
`vagrant up` command again.
|
||||
creating_storage_pool_error: |-
|
||||
There was error while creating Libvirt storage pool: %{error_message}
|
||||
creating_volume_error: |-
|
||||
There was error while creating Libvirt volume: %{error_message}
|
||||
image_upload_error: |-
|
||||
Error while uploading image to storage pool: %{error_message}
|
||||
no_domain_error: |-
|
||||
|
||||
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
||||
s.add_development_dependency "rspec-expectations", "~> 3.5.0"
|
||||
s.add_development_dependency "rspec-mocks", "~> 3.5.0"
|
||||
|
||||
s.add_runtime_dependency 'fog-libvirt', '>= 0.3.0'
|
||||
s.add_runtime_dependency 'fog-libvirt', '>= 0.6.0'
|
||||
s.add_runtime_dependency 'fog-core', '~> 2.1'
|
||||
|
||||
# Make sure to allow use of the same version as Vagrant by being less specific
|
||||
|
||||
Reference in New Issue
Block a user