module Construqt::Bgps
Public Class Methods
add_as(as, config)
click to toggle source
# File lib/construqt/bgps.rb, line 142 def self.add_as(as, config) throw "as must be a number #{as}" unless as.kind_of?(Fixnum) throw "as defined before #{as}" if @as[as] config['as'] = as @as[as] = As.new(config) end
add_connection(cfg, id)
click to toggle source
# File lib/construqt/bgps.rb, line 23 def self.add_connection(cfg, id) throw "my not found #{cfg[id]['my'].inspect}" unless cfg[id]['my'] throw "as not found #{cfg[id]['as'].inspect}" unless cfg[id]['as'] throw "as not a as #{cfg[id]['as'].inspect}" unless cfg[id]['as'].kind_of?(As) #throw "filter not found #{cfg.inspect}" unless cfg[id]['filter'] cfg[id]['filter'] ||= {} cfg[id]['other'] = nil cfg[id]['cfg'] = nil cfg[id]['host'] = cfg[id]['my'].host cfg[id] = cfg[id]['host'].flavour.create_bgp(cfg[id]) end
add_filter(name, &block)
click to toggle source
# File lib/construqt/bgps.rb, line 155 def self.add_filter(name, &block) @filters[name] = Filter.new(name) block.call(@filters[name]) @filters[name] end
build_config()
click to toggle source
# File lib/construqt/bgps.rb, line 53 def self.build_config() #binding.pry hosts = {} @bgps.values.each do |bgp| hosts[bgp.left.host.object_id] ||= bgp.left.host hosts[bgp.right.host.object_id] ||= bgp.right.host end #binding.pry hosts.values.each do |host| host.flavour.bgp.header(host) if host.flavour.bgp.respond_to?(:header) end @bgps.each do |name, bgp| bgp.build_config() end #hosts.values.each do |flavour_bgp| # flavour_bgp.header(flavour_bgp.host) # flavour_bgp.footer(flavour_bgp.host) #end end
connection(name, cfg)
click to toggle source
# File lib/construqt/bgps.rb, line 35 def self.connection(name, cfg) throw "filter not allowed" if cfg['filter'] throw "duplicated name #{name}" if @bgps[name] add_connection(cfg, 'left') add_connection(cfg, 'right') cfg['name'] = name cfg = @bgps[name] = Bgp.new(cfg) cfg.left.other = cfg.right cfg.left.cfg = cfg cfg.right.other = cfg.left cfg.right.cfg = cfg cfg.right.host.add_bgp(cfg) cfg.left.host.add_bgp(cfg) cfg end
connections()
click to toggle source
# File lib/construqt/bgps.rb, line 19 def self.connections @bgps.values end
filters()
click to toggle source
# File lib/construqt/bgps.rb, line 161 def self.filters @filters.values end
find_as(as)
click to toggle source
# File lib/construqt/bgps.rb, line 149 def self.find_as(as) ret = @as[as] throw "as not found #{as}" unless ret ret end
find_filter(name)
click to toggle source
# File lib/construqt/bgps.rb, line 165 def self.find_filter(name) ret = @filters[name] throw "bgp not filter with name #{name}" unless ret ret end