2011-06-28 09:47:16 -04:00
|
|
|
require 'fog/core/collection'
|
|
|
|
require 'fog/compute/models/libvirt/pool'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class Libvirt
|
|
|
|
|
|
|
|
class Pools < Fog::Collection
|
|
|
|
|
|
|
|
model Fog::Compute::Libvirt::Pool
|
|
|
|
|
2011-08-03 06:48:44 -04:00
|
|
|
def all(filter=nil)
|
2011-06-28 09:47:16 -04:00
|
|
|
data=[]
|
2011-08-03 06:48:44 -04:00
|
|
|
if filter.nil?
|
|
|
|
connection.list_storage_pools.each do |poolname|
|
|
|
|
pool=connection.lookup_storage_pool_by_name(poolname)
|
|
|
|
data << { :raw => pool }
|
|
|
|
end
|
|
|
|
connection.list_defined_storage_pools.each do |poolname|
|
|
|
|
data << {
|
|
|
|
:raw => connection.lookup_storage_pool_by_name(poolname)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
else
|
|
|
|
pool=nil
|
|
|
|
begin
|
|
|
|
pool=get_by_uuid(filter[:uuid]) if filter.has_key?(:uuid)
|
|
|
|
pool=get_by_name(filter[:name]) if filter.has_key?(:name)
|
|
|
|
rescue ::Libvirt::RetrieveError
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
data << { :raw => pool}
|
2011-08-01 08:00:13 -04:00
|
|
|
end
|
|
|
|
|
2011-06-28 09:47:16 -04:00
|
|
|
load(data)
|
|
|
|
end
|
|
|
|
|
2011-08-03 06:48:44 -04:00
|
|
|
def get(uuid)
|
|
|
|
self.all(:uuid => uuid).first
|
2011-08-01 08:00:13 -04:00
|
|
|
end
|
2011-08-03 06:48:44 -04:00
|
|
|
|
|
|
|
private
|
2011-08-01 08:00:13 -04:00
|
|
|
# Retrieve the pool by uuid
|
|
|
|
def get_by_uuid(uuid)
|
2011-06-28 09:47:16 -04:00
|
|
|
pool=connection.lookup_storage_pool_by_uuid(uuid)
|
2011-08-03 06:48:44 -04:00
|
|
|
return pool
|
2011-06-28 09:47:16 -04:00
|
|
|
end
|
|
|
|
|
2011-08-01 08:00:13 -04:00
|
|
|
# Retrieve the pool by name
|
|
|
|
def get_by_name(name)
|
|
|
|
pool=connection.lookup_storage_pool_by_name(name)
|
2011-08-03 06:48:44 -04:00
|
|
|
return pool
|
|
|
|
# new(:raw => pool)
|
2011-08-01 08:00:13 -04:00
|
|
|
end
|
|
|
|
|
2011-06-28 09:47:16 -04:00
|
|
|
end #class
|
|
|
|
|
|
|
|
end #Class
|
|
|
|
end #module
|
|
|
|
end #module
|