Class: Construqt::Bgps::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/construqt/bgps.rb

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Filter

Returns a new instance of Filter.



77
78
79
80
# File 'lib/construqt/bgps.rb', line 77

def initialize(name)
  @name = name
  @list = []
end

Instance Method Details

#accept(cfg) ⇒ Object



110
111
112
113
114
115
116
# 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) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# 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

#listObject



82
83
84
# File 'lib/construqt/bgps.rb', line 82

def list
  @list
end

#nameObject



86
87
88
# File 'lib/construqt/bgps.rb', line 86

def name
  @name
end

#reject(cfg) ⇒ Object



118
119
120
121
122
123
124
# 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