2011-06-28 09:47:16 -04:00
|
|
|
require 'fog/core/collection'
|
|
|
|
require 'fog/compute/models/libvirt/volume'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class Libvirt
|
|
|
|
|
|
|
|
class Volumes < Fog::Collection
|
|
|
|
|
|
|
|
model Fog::Compute::Libvirt::Volume
|
|
|
|
|
|
|
|
def all
|
|
|
|
data=[]
|
|
|
|
connection.list_storage_pools.each do |poolname|
|
|
|
|
pool=connection.lookup_storage_pool_by_name(poolname)
|
|
|
|
pool.list_volumes.each do |volumename|
|
|
|
|
data << { :raw => pool.lookup_volume_by_name(volumename) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
load(data)
|
|
|
|
end
|
|
|
|
|
2011-08-01 09:18:00 -04:00
|
|
|
# Retrieve the volume by type
|
|
|
|
def get(param)
|
|
|
|
volume=nil
|
|
|
|
volume=get_by_key(param[:key]) if param.has_key?(:key)
|
|
|
|
volume=get_by_path(param[:path]) if param.has_key?(:path)
|
|
|
|
volume=get_by_name(param[:name]) if param.has_key?(:name)
|
|
|
|
return volume
|
|
|
|
end
|
|
|
|
|
|
|
|
# Retrieve the volume by name
|
|
|
|
def get_by_name(name)
|
|
|
|
connection.list_storage_pools.each do |poolname|
|
|
|
|
pool=connection.lookup_storage_pool_by_name(poolname)
|
|
|
|
volume=pool.lookup_volume_by_name(name)
|
|
|
|
unless volume.nil?
|
|
|
|
return new(:raw => volume)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
# Retrieve the volume by key
|
|
|
|
def get_by_key(key)
|
|
|
|
connection.list_storage_pools.each do |poolname|
|
|
|
|
pool=connection.lookup_storage_pool_by_name(poolname)
|
|
|
|
volume=pool.lookup_volume_by_key(key)
|
|
|
|
unless volume.nil?
|
|
|
|
return new(:raw => volume)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
# Retrieve the volume by key
|
|
|
|
def get_by_path(path)
|
2011-06-28 09:47:16 -04:00
|
|
|
connection.list_storage_pools.each do |poolname|
|
|
|
|
pool=connection.lookup_storage_pool_by_name(poolname)
|
2011-08-01 09:18:00 -04:00
|
|
|
volume=pool.lookup_volume_by_key(path)
|
2011-06-28 09:47:16 -04:00
|
|
|
unless volume.nil?
|
|
|
|
return new(:raw => volume)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return nil
|
|
|
|
end
|
2011-08-01 09:18:00 -04:00
|
|
|
|
2011-06-28 09:47:16 -04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|