Class: Dcmgr::Models::DhcpRange

Inherits:
BaseNew
  • Object
show all
Defined in:
lib/dcmgr/models/dhcp_range.rb

Overview

Dynamic IP address range in the network.

Constant Summary

Constants inherited from BaseNew

BaseNew::LOCK_TABLES_KEY

Instance Method Summary collapse

Methods inherited from BaseNew

Proxy, dataset, default_row_lock_mode=, install_data, install_data_hooks, lock!, #to_hash, unlock!, #with_timestamps?

Instance Method Details

#range_beginObject



30
31
32
# File 'lib/dcmgr/models/dhcp_range.rb', line 30

def range_begin
  IPAddress::IPv4.new("#{super}/#{network.prefix}")
end

#range_endObject



34
35
36
# File 'lib/dcmgr/models/dhcp_range.rb', line 34

def range_end
  IPAddress::IPv4.new("#{super}/#{network.prefix}")
end

#validateObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dcmgr/models/dhcp_range.rb', line 11

def validate
  super

  if !self.network.ipv4_ipaddress.include?(self.range_begin)
    errors.add(:range_begin, "Out of subnet range: #{self.range_begin}")
  end
  
  if !self.network.ipv4_ipaddress.include?(self.range_end)
    errors.add(:range_end, "Out of subnet range: #{self.range_end}")
  end

  if !(self.range_begin <= self.range_end)
    # swap values.
    t = self[:range_end]
    self[:range_end] = self[:range_begin]
    self[:range_begin] = t
  end
end