- Parse incoming BGP community
<AS>:<port>
; - Generate hash of arrays of IP addresses by port as a key;
- Generate custom template reusing
services
hash.
- gem install exa-template
require 'exa-template'
ExaTemplate.new('/etc/exa-template/service.cfg.erb',
'/etc/servicex/service.cfg').parse_events
services = {
'443' => ['2001:802::123/128', '1.1.1.1/32'],
'8080' => ['1.1.1.1/32']
}
<% services.each do |port, ips| %>
service_<%= port %>
listen 127.0.0.1:<%= port %>
<%- ips.each do |ip| -%>
backend <%= ip.split('/')[0] %>:<%= port %>
<%- end -%>
<% end %>