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