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/network'
|
2011-06-28 09:47:16 -04:00
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class Libvirt
|
|
|
|
|
|
|
|
class Networks < Fog::Collection
|
|
|
|
|
|
|
|
model Fog::Compute::Libvirt::Network
|
|
|
|
|
2011-08-03 06:48:44 -04:00
|
|
|
def all(filter=nil)
|
2011-08-08 17:22:55 -04:00
|
|
|
data=[]
|
2011-08-03 06:48:44 -04:00
|
|
|
if filter.nil?
|
|
|
|
connection.list_networks.each do |networkname|
|
2011-08-08 17:22:55 -04:00
|
|
|
network=connection.lookup_network_by_name(networkname)
|
2011-08-03 06:48:44 -04:00
|
|
|
data << { :raw => network }
|
2011-08-08 17:22:55 -04:00
|
|
|
end
|
2011-08-03 06:48:44 -04:00
|
|
|
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
|
|
|
|
|
2011-06-28 09:47:16 -04:00
|
|
|
load(data)
|
|
|
|
end
|
|
|
|
|
|
|
|
def get(uuid)
|
2011-08-03 06:48:44 -04:00
|
|
|
self.all(:uuid => uuid).first
|
|
|
|
end
|
2011-08-08 17:22:55 -04:00
|
|
|
|
2011-08-03 08:28:40 -04:00
|
|
|
#private # Making these private, screws up realod
|
2011-08-03 06:48:44 -04:00
|
|
|
# Retrieve the network by uuid
|
|
|
|
def get_by_uuid(uuid)
|
2011-06-28 09:47:16 -04:00
|
|
|
network=connection.lookup_network_by_uuid(uuid)
|
2011-08-03 06:48:44 -04:00
|
|
|
return network
|
|
|
|
# new(:raw => network)
|
2011-06-28 09:47:16 -04:00
|
|
|
end
|
|
|
|
|
2011-08-03 06:48:44 -04:00
|
|
|
# Retrieve the network by name
|
|
|
|
def get_by_name(name)
|
|
|
|
network=connection.lookup_network_by_name(name)
|
|
|
|
return network
|
|
|
|
# new(:raw => network)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2011-06-28 09:47:16 -04:00
|
|
|
end #class
|
|
|
|
|
|
|
|
end #Class
|
|
|
|
end #module
|
|
|
|
end #module
|