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/requests/compute/list_interfaces.rb
Ohad Levy 9d78d29a19 [libvirt] refactored libvirt entire code
* moved to using requests
* added vm nic/nics
* kept compatability with the existing interfaces
* moved util classes into util subdir

Signed-off-by: Amos Benari <abenari@redhat.com>
2012-04-04 15:35:05 +03:00

47 lines
1.1 KiB
Ruby

module Fog
module Compute
class Libvirt
class Real
def list_interfaces(filter = { })
data=[]
if filter.keys.empty?
(client.list_interfaces + client.list_defined_interfaces).each do |ifname|
data << interface_to_attributes(client.lookup_interface_by_name(ifname))
end
else
data = [interface_to_attributes(get_interface_by_filter(filter))]
end
data.compact
end
private
# Retrieve the interface by mac or by name
def get_interface_by_filter(filter)
case filter.keys.first
when :mac
client.lookup_interface_by_mac(filter[:mac])
when :name
client.lookup_interface_by_name(filter[:name])
end
end
def interface_to_attributes(net)
return if net.nil? || net.name == 'lo'
{
:mac => net.mac,
:name => net.name,
:active => net.active?
}
end
end
class Mock
def list_interfaces(filters={ })
[]
end
end
end
end
end