diff --git a/lib/vagrant-libvirt/action/handle_box_image.rb b/lib/vagrant-libvirt/action/handle_box_image.rb index 3a97356..93256aa 100644 --- a/lib/vagrant-libvirt/action/handle_box_image.rb +++ b/lib/vagrant-libvirt/action/handle_box_image.rb @@ -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 diff --git a/lib/vagrant-libvirt/errors.rb b/lib/vagrant-libvirt/errors.rb index 5023ce2..0bb3c3a 100644 --- a/lib/vagrant-libvirt/errors.rb +++ b/lib/vagrant-libvirt/errors.rb @@ -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 diff --git a/lib/vagrant-libvirt/templates/default_storage_volume.xml.erb b/lib/vagrant-libvirt/templates/default_storage_volume.xml.erb deleted file mode 100644 index c4b2268..0000000 --- a/lib/vagrant-libvirt/templates/default_storage_volume.xml.erb +++ /dev/null @@ -1,14 +0,0 @@ - - <%= @name %> - <%= split_size_unit(@allocation)[0] %> - <%= split_size_unit(@capacity)[0] %> - - - - <%= @storage_volume_uid %> - <%= @storage_volume_gid %> - 0744 - - - - diff --git a/locales/en.yml b/locales/en.yml index 2a59768..08a4c71 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -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: |- diff --git a/vagrant-libvirt.gemspec b/vagrant-libvirt.gemspec index b1e97a7..6d08374 100644 --- a/vagrant-libvirt.gemspec +++ b/vagrant-libvirt.gemspec @@ -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