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/compute/models/libvirt/networks.rb

62 lines
1.6 KiB
Ruby
Raw Normal View History

require 'fog/core/collection'
require 'fog/compute/models/libvirt/network'
module Fog
module Compute
class Libvirt
class Networks < Fog::Collection
model Fog::Compute::Libvirt::Network
def all(filter=nil)
2011-08-08 17:22:55 -04:00
data=[]
if filter.nil?
connection.list_networks.each do |networkname|
2011-08-08 17:22:55 -04:00
network=connection.lookup_network_by_name(networkname)
data << { :raw => network }
2011-08-08 17:22:55 -04:00
end
connection.list_defined_networks.each do |networkname|
network=connection.lookup_network_by_name(networkname)
data << { :raw => network}
end
else
network=nil
begin
network=get_by_uuid(filter[:uuid]) if filter.has_key?(:uuid)
network=get_by_name(filter[:name]) if filter.has_key?(:name)
rescue ::Libvirt::RetrieveError
return nil
end
data << { :raw => network}
end
load(data)
end
def get(uuid)
self.all(:uuid => uuid).first
end
2011-08-08 17:22:55 -04:00
#private # Making these private, screws up realod
# Retrieve the network by uuid
def get_by_uuid(uuid)
network=connection.lookup_network_by_uuid(uuid)
return network
# new(:raw => network)
end
# Retrieve the network by name
def get_by_name(name)
network=connection.lookup_network_by_name(name)
return network
# new(:raw => network)
end
end #class
end #Class
end #module
end #module