Sha256: 7c5f941a789ee094a3f3c2d7850fec3434a11e71d77599a2ccfc2d42e1b62fee

Contents?: true

Size: 829 Bytes

Versions: 1

Compression:

Stored size: 829 Bytes

Contents

module Clusterfuck
  class BGPPeer < Machine
    attr_accessor :bgp_asn,
      :bgp_router_id,
      :bgp_announced

    def initialize(name, **args)
      super

      @bgp_announced = args[:announced] ? Array(args[:announced]) : []
      @bgp_asn = args[:asn] || ASNFactory.next
      @bgp_router_id = args[:router_id] || RouterIDFactory.next
    end

    def bgp_announced
      @bgp_announced.map { |a|
        a.kind_of?(SubnetFactory) ? a.subnet : a 
      }
    end

    def bgp_neighbors
      network.adjacent(self).select { |neighbor|
        neighbor.kind_of?(BGPPeer)
      }
    end

    class ASNFactory
      @asn = 64999

      def self.next
        @asn += 1
      end
    end

    class RouterIDFactory
      @id = IPAddr.new("10.0.20.1")

      def self.next
        @id = @id.succ
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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