Module: Construqt::Bgps
- Defined in:
- lib/construqt/bgps.rb
Defined Under Namespace
Class Method Summary collapse
- .add_as(as, config) ⇒ Object
- .add_connection(cfg, id) ⇒ Object
- .add_filter(name, &block) ⇒ Object
- .build_config ⇒ Object
- .connection(name, cfg) ⇒ Object
- .connections ⇒ Object
- .filters ⇒ Object
- .find_as(as) ⇒ Object
- .find_filter(name) ⇒ Object
Class Method Details
.add_as(as, config) ⇒ Object
144 145 146 147 148 149 |
# File 'lib/construqt/bgps.rb', line 144 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) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# 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) ⇒ Object
157 158 159 160 161 |
# File 'lib/construqt/bgps.rb', line 157 def self.add_filter(name, &block) @filters[name] = Filter.new(name) block.call(@filters[name]) @filters[name] end |
.build_config ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# 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) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# 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 ⇒ Object
19 20 21 |
# File 'lib/construqt/bgps.rb', line 19 def self.connections @bgps.values end |
.filters ⇒ Object
163 164 165 |
# File 'lib/construqt/bgps.rb', line 163 def self.filters @filters.values end |
.find_as(as) ⇒ Object
151 152 153 154 155 |
# File 'lib/construqt/bgps.rb', line 151 def self.find_as(as) ret = @as[as] throw "as not found #{as}" unless ret ret end |
.find_filter(name) ⇒ Object
167 168 169 170 171 |
# File 'lib/construqt/bgps.rb', line 167 def self.find_filter(name) ret = @filters[name] throw "bgp not filter with name #{name}" unless ret ret end |