class Fission::Lease

def self.all

If there is an error, an unsuccessful Response will be returned.
be an empty Array.
objects. If no leases are found, then the Response's data attribute will
If successful, the Response's data attribute will be an Array of Lease
Returns a Response with the result.

#]
# => [#,
Fission::Lease.all

Examples:

Public: Provides all of the known leases.
def self.all
  response = Response.new
  if File.file? Fission.config['lease_file']
    content = File.read Fission.config['lease_file']
    response.data = content.split('}').collect do |entry|
      parse entry
    end
    content = nil
    response.code = 0
  else
    response.code = 1
    response.message = "Unable to find the lease file '#{Fission.config['lease_file']}'"
  end
  response
end

def self.find_by_mac_address(mac_address)

If there is an error, an unsuccessful Response will be returned.
MAC address was not found.
MAC address was found. The Response's data attribute will be nil if the
If successful, the Response's data attribute will be a Lease object if the
Returns a Response with the result.

# => #
Fission::Lease.find_by_mac '00:11:AA:bb:cc:22'

Examples

mac_address - MAC address (String) to search for.

Public: Get lease information for a specific MAC address.
def self.find_by_mac_address(mac_address)
  all_response = all
  if all_response.successful?
    response = Response.new :code => 0
    leases = all_response.data.find_all { |l| l.mac_address == mac_address }
    response.data = leases.sort_by { |l| l.end }.last
  else
    response = all_response
  end
  response
end

def self.parse(lease_entry)

found.
Returns a Lease object which is populated with the attribute that were


# => #
Lease.parse my_lease_entry

Examples

entry - String of lease entry text.

Internal: Parses information out of a DHCP lease entry.
def self.parse(lease_entry)
  lease = Lease.new
  lease_entry.gsub! ';', ''
  lease_entry.split("\n").each do |line|
    next if line =~ /^#/
    line.strip!
    case line.strip
    when /^lease/
      lease.ip_address = line.split(' ')[1]
    when /^starts/
      lease.start = DateTime.parse(line.split(' ')[2..3].join(' '))
    when /^end/
      lease.end = DateTime.parse(line.split(' ')[2..3].join(' '))
    when /^hardware/
      lease.mac_address = line.split(' ')[2]
    end
  end
  lease
end

def expired?

attribute to the current date/time.
Returns a Boolean. The Boolean is determined by comparing the end

# => true
@lease.expired?

Examples:

Public: Determine if the lease has expired or not.
def expired?
  @end < DateTime.now
end

def initialize(args={})

Returns a new Lease instance.

Examples

:end - DateTime which denotes the end of the lease.
:start - DateTime which denotes the start of the lease.
:mac_address - String which denotes the MAC address of the lease.
:ip_address - String which denotes the IP address of the lease.
args - Hash of arguments:

Public: Initialize a Lease object.
def initialize(args={})
  @ip_address = args[:ip_address]
  @mac_address = args[:mac_address]
  @start = args[:start]
  @end = args[:end]
end