Class: ForemanProbingCore::NeighbourCache
- Inherits:
-
Object
- Object
- ForemanProbingCore::NeighbourCache
- Defined in:
- lib/foreman_probing_core/neighbour_cache.rb
Instance Method Summary collapse
- #cache! ⇒ Object
- #clean! ⇒ Object
-
#initialize ⇒ NeighbourCache
constructor
A new instance of NeighbourCache.
- #ips_for_mac(mac) ⇒ Object
- #mac_for_ip(ip) ⇒ Object
Constructor Details
#initialize ⇒ NeighbourCache
Returns a new instance of NeighbourCache.
3 4 5 |
# File 'lib/foreman_probing_core/neighbour_cache.rb', line 3 def initialize @cache = [] end |
Instance Method Details
#cache! ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/foreman_probing_core/neighbour_cache.rb', line 15 def cache! @cache = `ip neigh show`.lines.map do |line| fields = line.chomp.split(/\s+/) hash = { :ip => fields.shift } fields.each_slice(2) do |k, v| if v hash[k] = v else hash[:state] = k end end hash end end |
#clean! ⇒ Object
30 31 32 |
# File 'lib/foreman_probing_core/neighbour_cache.rb', line 30 def clean! @cache = {} end |
#ips_for_mac(mac) ⇒ Object
7 8 9 |
# File 'lib/foreman_probing_core/neighbour_cache.rb', line 7 def ips_for_mac(mac) @cache.select { |record| record['lladdr'] == mac }.map { |record| record[:ip] } end |
#mac_for_ip(ip) ⇒ Object
11 12 13 |
# File 'lib/foreman_probing_core/neighbour_cache.rb', line 11 def mac_for_ip(ip) @cache.select { |record| record[:ip] == ip }.map { |record| record['lladdr'] }.first end |