Permalink
Browse files

Changes to work with local ISOS

  • Loading branch information...
1 parent 8e360a9 commit a4923516defb689c6f9d8930e3cfd19151b61030 @leehambley leehambley committed Apr 2, 2013
Showing with 11 additions and 23 deletions.
  1. +10 −22 app/mvmc.rb
  2. +1 −1 lib/iso.rb
View
@@ -15,7 +15,6 @@
VIRSH_URI = "qemu+ssh://protonet@cebit.local/system?socket=/var/run/libvirt/libvirt-sock"
VIRSH_POOL_DIR = "/var/lib/libvirt/images"
-VMS_DIR = File.expand_path(File.join(File.dirname(__FILE__), '../vms/'))
ISOS_DIR = File.expand_path(File.join(File.dirname(__FILE__), '../isos/'))
class Mvmc < Sinatra::Base
@@ -136,28 +135,14 @@ def hypervisor_url
redirect '/vms'
end
- get '/isos/:basename' do |basename|
- send_file File.join(settings.isos_dir, basename)
+ get '/isos/:basename' do |path|
+ send_file File.join(path)
end
post '/isos' do
if params['file']
- Virsh::StoragePool.find_by_name('virsh-isos').tap do |pool|
- pool.create_volume(
- params[:file][:filename],
- params[:file][:tempfile].size
- ).tap do |volume|
- stream = $libvirt.stream
- volume.upload(
- stream,
- 0,
- params[:file][:tempfile].size
- )
- stream.sendall(params[:file][:tempfile]) do |opaque, nbytes|
- [0, opaque.read(nbytes)]
- end
- stream.finish
- end
+ File.open(File.join(ISOS_DIR, params['file'][:filename]), 'wb') do |f|
+ f.write(params['file'][:tempfile].read)
end
end
status 200
@@ -171,9 +156,12 @@ def hypervisor_url
private
def isos
- pool = $libvirt.lookup_storage_pool_by_name('virsh-isos')
- pool.list_volumes.collect do |volume_name|
- pool.lookup_volume_by_name(volume_name)
+ Dir[File.join(ISOS_DIR, '*')].collect do |path|
+ ISO.new(path, OpenStruct.new(
+ {
+ allocation: File.size(path)
+ }
+ ))
end
end
View
@@ -1 +1 @@
-ISO = Struct.new(:basename, :mtime, :size)
+ISO = Struct.new(:path, :info)

0 comments on commit a492351

Please sign in to comment.