Class: VagrantPlugins::AVF::DhcpLeases

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant_provider_avf/dhcp_leases.rb

Constant Summary collapse

DEFAULT_PATH =
"/private/var/db/dhcpd_leases".freeze

Instance Method Summary collapse

Constructor Details

#initialize(path: DEFAULT_PATH) ⇒ DhcpLeases

Returns a new instance of DhcpLeases.



6
7
8
# File 'lib/vagrant_provider_avf/dhcp_leases.rb', line 6

def initialize(path: DEFAULT_PATH)
  @path = path
end

Instance Method Details

#ip_address_for(mac_address:) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/vagrant_provider_avf/dhcp_leases.rb', line 10

def ip_address_for(mac_address:)
  return unless File.file?(@path)

  normalized_mac_address = normalize(mac_address)
  entries.reverse_each do |entry|
    next unless matches_mac_address?(entry, normalized_mac_address)

    ip_address = entry["ip_address"]
    return ip_address unless blank?(ip_address)
  end

  nil
end