class Construqt::Bgps::Filter
Public Class Methods
new(name)
click to toggle source
# File lib/construqt/bgps.rb, line 77 def initialize(name) @name = name @list = [] end
Public Instance Methods
accept(cfg)
click to toggle source
# File lib/construqt/bgps.rb, line 110 def accept(cfg) cfg = {}.merge(cfg) cfg['rule'] = 'accept' addr_v_(cfg) throw "we need a network attribute" unless cfg['network'] @list << cfg if cfg['network'] end
addr_v_(cfg)
click to toggle source
# File lib/construqt/bgps.rb, line 90 def addr_v_(cfg) [OpenStruct.new({:code=>4, :is? => lambda {|i| i.ipv4? }, :max_prefix=>32}), OpenStruct.new({:code=>6, :is? => lambda {|i| i.ipv6? }, :max_prefix=>128})].each do |family| addrs = cfg["addr_v#{family.code}"] next unless addrs cfg.delete("addr_v#{family.code}") addr_sub_prefix = cfg['addr_sub_prefix'] cfg.delete('addr_sub_prefix') throw "addrs must be array" unless addrs.kind_of?([].class) #puts addr.inspect addrs.each do |net| next unless family.is?.call(net) out = ({ 'network' => Construqt::Addresses::Address.new.add_ip(net.to_string) }).merge(cfg) out['prefix_length'] = [net.prefix,family.max_prefix] if addr_sub_prefix @list << out end nil end end
list()
click to toggle source
# File lib/construqt/bgps.rb, line 82 def list @list end
name()
click to toggle source
# File lib/construqt/bgps.rb, line 86 def name @name end
reject(cfg)
click to toggle source
# File lib/construqt/bgps.rb, line 118 def reject(cfg) cfg = {}.merge(cfg) cfg['rule'] = 'reject' addr_v_(cfg) throw "we need a network attribute" unless cfg['network'] @list << cfg if cfg['network'] end