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/interfaces.rb

63 lines
1.7 KiB
Ruby
Raw Normal View History

require 'fog/core/collection'
require 'fog/libvirt/models/compute/interface'
module Fog
module Compute
class Libvirt
class Interfaces < Fog::Collection
model Fog::Compute::Libvirt::Interface
def all(filter=nil)
2011-08-08 17:22:55 -04:00
data=[]
if filter.nil?
connection.raw.list_interfaces.each do |ifname|
interface=connection.raw.lookup_interface_by_name(ifname)
data << { :raw => interface }
end
connection.raw.list_defined_interfaces.each do |ifname|
interface=connection.raw.lookup_interface_by_name(ifname)
data << { :raw => interface }
end
else
interface=nil
begin
interface=get_by_name(filter[:name]) if filter.has_key?(:name)
interface=get_by_mac(filter[:mac]) if filter.has_key?(:mac)
rescue ::Libvirt::RetrieveError
return nil
end
data << { :raw => interface}
end
load(data)
end
2011-08-08 17:22:55 -04:00
def get(key)
self.all(:name => name).first
2011-08-08 17:22:55 -04:00
end
#private # Making these private, screws up realod
# Retrieve the interface by name
def get_by_name(name)
interface=connection.raw.lookup_interface_by_name(name)
return interface
# new(:raw => interface)
end
# Retrieve the interface by name
def get_by_mac(mac)
interface=connection.raw.lookup_interface_by_mac(mac)
return interface
# new(:raw => interface)
end
end #class
end #Class
end #module
end #module