aboutsummaryrefslogtreecommitdiff
path: root/app/models/libvirt_extensions.rb
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2016-06-14 19:14:10 +0200
committerGuido Günther <agx@sigxcpu.org>2016-06-14 19:14:10 +0200
commitbe945de33c794a449c5fcbf991db4bf0d49b1fb7 (patch)
tree477c5f4b708e37200f9042e206e4d7874d2eeae7 /app/models/libvirt_extensions.rb
Initial commitHEADmaster
Diffstat (limited to 'app/models/libvirt_extensions.rb')
-rw-r--r--app/models/libvirt_extensions.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/app/models/libvirt_extensions.rb b/app/models/libvirt_extensions.rb
new file mode 100644
index 0000000..b9b55c9
--- /dev/null
+++ b/app/models/libvirt_extensions.rb
@@ -0,0 +1,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