1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/libvirt/models/compute/volumes.rb
Patrick Debois 4740174f12 [Libvirt] renamed 'raw' connection to raw in the Fog Connection
Because the initial provider was copied from the virtualbox example we ended up with a notation
connection.connection for the raw provider

The function of the raw are injected on the connection object. Still in analogy with the raw
for server , volume, ... it makes sense to rename connection.connection to connection.raw

Also all calls to the raw connection are now explicit
2011-09-13 07:34:18 +02:00

87 lines
2.3 KiB
Ruby

require 'fog/core/collection'
require 'fog/libvirt/models/compute/volume'
module Fog
module Compute
class Libvirt
class Volumes < Fog::Collection
model Fog::Compute::Libvirt::Volume
def all(filter=nil)
data=[]
if filter.nil?
connection.raw.list_storage_pools.each do |poolname|
pool=connection.raw.lookup_storage_pool_by_name(poolname)
pool.list_volumes.each do |volumename|
data << { :raw => pool.lookup_volume_by_name(volumename) }
end
end
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)
return nil if volume.nil?
rescue ::Libvirt::RetrieveError
return nil
end
data << { :raw => volume}
end
load(data)
end
def get(key)
self.all(:key => key).first
end
# Retrieve the volume by name
def get_by_name(name)
connection.raw.list_storage_pools.each do |poolname|
pool=connection.raw.lookup_storage_pool_by_name(poolname)
volume=pool.lookup_volume_by_name(name)
unless volume.nil?
return volume
end
end
return nil
end
# Retrieve the volume by key
def get_by_key(key)
connection.raw.list_storage_pools.each do |poolname|
pool=connection.raw.lookup_storage_pool_by_name(poolname)
volume=pool.lookup_volume_by_key(key)
unless volume.nil?
return volume
end
end
return nil
end
# Retrieve the volume by key
def get_by_path(path)
connection.raw.list_storage_pools.each do |poolname|
pool=connection.raw.lookup_storage_pool_by_name(poolname)
volume=pool.lookup_volume_by_key(path)
unless volume.nil?
return volume
end
end
return nil
end
end
end
end
end