add support for bird bgp peers

This commit is contained in:
Jörg Thalheim 2015-01-16 09:18:52 +01:00
parent a03bb44e10
commit 50636135e4
2 changed files with 44 additions and 0 deletions

39
scripts/bird.rb Normal file
View File

@ -0,0 +1,39 @@
#!/usr/bin/env ruby
require_relative 'utils.rb'
class BgpRegistry < Registry
def update_configs
template_name = data["host"]["bird"]["template_name"] rescue nil
template_name or die "bird.template_name not set for this host"
peers = data["network"]
v4_templ, v6_templ = generate_configs(template_name, peers)
bird_path = Pathname.new(File.expand_path("../../bird/", __FILE__))
atomic_write(bird_path.join("peers.conf"), v4_templ)
atomic_write(bird_path.join("peers6.conf"), v6_templ)
end
def generate_configs(template_name, peers)
template_path = Pathname.new(File.expand_path("../../templates", __FILE__))
template = Template.new(template_path.join("bird.conf.erb"))
v4_peers = collect_bgp_peers(peers, template_name, :v4)
v6_peers = collect_bgp_peers(peers, template_name, :v6)
return template.render(peers: v4_peers), template.render(peers: v6_peers)
end
private
def collect_bgp_peers(peers, template_name, proto)
peers.map do |name, peer|
if peer["as"] && peer["#{proto}_tunnel"]
context = {
name: name,
template: template_name,
tunnel_ip: peer["#{proto}_tunnel"],
as: peer["as"]
}
TemplateContext.new(context)
end
end.compact!
end
end

5
templates/bird.conf.erb Normal file
View File

@ -0,0 +1,5 @@
<% peers.each do |peer| -%>
protocol bgp <%= peer.name %> as <%= peer.template %> {
neighbor <%= peer.tunnel_ip %> as <%= peer.as %>;
};
<% end -%>