Sha256: 5ed623c9df7669b697ee009232b41d316419d2d4f900340f2723790979e9bc61

Contents?: true

Size: 875 Bytes

Versions: 2

Compression:

Stored size: 875 Bytes

Contents

# -*- coding: utf-8 -*-

require 'ipaddress'

module Dcmgr::Models
  # Dynamic IP address range in the network.
  class DhcpRange < BaseNew

    many_to_one :network

    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

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

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

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
wakame-vdc-agents-11.12.0 lib/dcmgr/models/dhcp_range.rb
wakame-vdc-dcmgr-11.12.0 lib/dcmgr/models/dhcp_range.rb