2011-06-28 09:47:16 -04:00
|
|
|
require 'fog/core/collection'
|
2011-08-29 11:24:39 -04:00
|
|
|
require 'fog/libvirt/models/compute/volume'
|
2011-06-28 09:47:16 -04:00
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class Libvirt
|
|
|
|
|
|
|
|
class Volumes < Fog::Collection
|
|
|
|
|
|
|
|
model Fog::Compute::Libvirt::Volume
|
|
|
|
|
2011-08-03 06:48:44 -04:00
|
|
|
def all(filter=nil)
|
2011-08-08 17:18:03 -04:00
|
|
|
data=[]
|
2011-08-03 06:48:44 -04:00
|
|
|
if filter.nil?
|
2011-09-13 01:34:18 -04:00
|
|
|
connection.raw.list_storage_pools.each do |poolname|
|
|
|
|
pool=connection.raw.lookup_storage_pool_by_name(poolname)
|
2011-08-03 06:48:44 -04:00
|
|
|
pool.list_volumes.each do |volumename|
|
|
|
|
data << { :raw => pool.lookup_volume_by_name(volumename) }
|
|
|
|
end
|
2011-06-28 09:47:16 -04:00
|
|
|
end
|
2011-08-03 06:48:44 -04:00
|
|
|
else
|
|
|
|
volume=nil
|
|
|
|
begin
|
|
|
|
volume=self.get_by_name(filter[:name]) if filter.has_key?(:name)
|
|
|
|
volume=self.get_by_key(filter[:key]) if filter.has_key?(:key)
|
|
|
|
volume=self.get_by_path(filter[:path]) if filter.has_key?(:path)
|
2011-08-04 07:26:27 -04:00
|
|
|
return nil if volume.nil?
|
2011-08-08 17:18:03 -04:00
|
|
|
|
2011-08-03 06:48:44 -04:00
|
|
|
rescue ::Libvirt::RetrieveError
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
data << { :raw => volume}
|
|
|
|
end
|
|
|
|
|
2011-06-28 09:47:16 -04:00
|
|
|
load(data)
|
|
|
|
end
|
|
|
|
|
2011-08-03 06:48:44 -04:00
|
|
|
def get(key)
|
|
|
|
self.all(:key => key).first
|
2011-08-01 09:18:00 -04:00
|
|
|
end
|
2011-08-03 06:48:44 -04:00
|
|
|
|
2011-08-08 17:18:03 -04:00
|
|
|
|
2011-08-01 09:18:00 -04:00
|
|
|
# Retrieve the volume by name
|
|
|
|
def get_by_name(name)
|
2011-09-13 01:34:18 -04:00
|
|
|
connection.raw.list_storage_pools.each do |poolname|
|
|
|
|
pool=connection.raw.lookup_storage_pool_by_name(poolname)
|
2011-08-03 06:48:44 -04:00
|
|
|
volume=pool.lookup_volume_by_name(name)
|
2011-08-08 17:18:03 -04:00
|
|
|
unless volume.nil?
|
2011-08-03 06:48:44 -04:00
|
|
|
return volume
|
2011-08-01 09:18:00 -04:00
|
|
|
end
|
2011-08-08 17:18:03 -04:00
|
|
|
end
|
2011-08-03 06:48:44 -04:00
|
|
|
|
2011-08-01 09:18:00 -04:00
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
# Retrieve the volume by key
|
|
|
|
def get_by_key(key)
|
2011-09-13 01:34:18 -04:00
|
|
|
connection.raw.list_storage_pools.each do |poolname|
|
|
|
|
pool=connection.raw.lookup_storage_pool_by_name(poolname)
|
2011-08-03 06:48:44 -04:00
|
|
|
volume=pool.lookup_volume_by_key(key)
|
2011-08-08 17:18:03 -04:00
|
|
|
unless volume.nil?
|
2011-08-03 06:48:44 -04:00
|
|
|
return volume
|
2011-08-01 09:18:00 -04:00
|
|
|
end
|
2011-08-08 17:18:03 -04:00
|
|
|
end
|
2011-08-03 06:48:44 -04:00
|
|
|
|
2011-08-01 09:18:00 -04:00
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
# Retrieve the volume by key
|
|
|
|
def get_by_path(path)
|
2011-09-13 01:34:18 -04:00
|
|
|
connection.raw.list_storage_pools.each do |poolname|
|
|
|
|
pool=connection.raw.lookup_storage_pool_by_name(poolname)
|
2011-08-03 06:48:44 -04:00
|
|
|
volume=pool.lookup_volume_by_key(path)
|
2011-08-08 17:18:03 -04:00
|
|
|
unless volume.nil?
|
2011-08-03 06:48:44 -04:00
|
|
|
return volume
|
2011-06-28 09:47:16 -04:00
|
|
|
end
|
2011-08-08 17:18:03 -04:00
|
|
|
end
|
2011-08-03 06:48:44 -04:00
|
|
|
|
2011-06-28 09:47:16 -04:00
|
|
|
return nil
|
|
|
|
end
|
2011-08-03 06:48:44 -04:00
|
|
|
|
2011-06-28 09:47:16 -04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|