Sha256: 3d81eb366f269a6055a4af10e851e7211add72a0e4ba3e2011800ac2859a7cf1

Contents?: true

Size: 507 Bytes

Versions: 1

Compression:

Stored size: 507 Bytes

Contents

module Clusterfuck
  class SubnetFactory
    attr_reader :subnet

    START_SUBNET = "10.0.39.0/24"
    @previous = IPAddr.new(START_SUBNET)

    def initialize(subnet)
      @subnet = subnet
    end

    def next
      @subnet = @subnet.succ
    end

    def self.next(cidr = 24)
      # succ twice to start at x.x.x.2
      @previous = @previous.mask(cidr).to_range.last.succ.succ
      SubnetFactory.new(@previous)
    end

    def self.reset
      @previous = IPAddr.new(START_SUBNET)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vagrant-clusterfuck-0.0.1 lib/clusterfuck/subnet_factory.rb