aboutsummaryrefslogtreecommitdiff
path: root/app/models/libvirt_extensions.rb
blob: b9b55c90ec0a809488e3c8eda635fed1a699f509 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
module LibvirtExtensions
  extend ActiveSupport::Concern

  def upload_image source, pool_name, volume_name
    begin
      vol = new_volume(:name      => volume_name,
                       :pool_name => pool_name,
                       :capacity  => "#{File.size(source)}b")
      vol.save
      vol.upload_image source
    rescue Libvirt::Error => e
      raise Foreman::Exception.new("Cannot upload image '#{volume_name}' to '#{pool_name}': #{e}")
    end
  end
end