Skip to content

Commit

Permalink
Merge pull request #199 from derJD/master
Browse files Browse the repository at this point in the history
add support for virtual_rules
  • Loading branch information
bastelfreak authored Oct 29, 2019
2 parents af206c0 + cd098e3 commit 2db0f02
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ node /node01/ {
auth_type => 'PASS',
auth_pass => 'secret',
virtual_ipaddress => [ '10.0.0.1/29' ],
virtual_routes => [ { to => '168.168.2.0/24', via => '10.0.0.2' },
{ to => '168.168.3.0/24', via => '10.0.0.3' } ]
virtual_routes => [ { to => '168.168.2.0/24', via => '10.0.0.2' },
{ to => '168.168.3.0/24', via => '10.0.0.3' } ],
virtual_rules => [ { from => '168.168.2.42', lookup => 'customroute' } ]
}
}
```
Expand All @@ -115,6 +116,9 @@ keepalived::vrrp_instance:
via: '10.0.0.2'
- to: 168.168.3.0/24'
via: '10.0.0.3'
virtual_rules:
- from: '168.168.2.42'
lookup: 'customroute'
```
### Detect application level failure
Expand Down
11 changes: 11 additions & 0 deletions manifests/vrrp/instance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
# 'metric' => '15' }`
# Supported properties: src, to, via, dev, scope, table, metric
#
# $virtual_rules:: Set floating rules.
#
# May be specified as a hash (or array of hashes)
# containing extra properties
# e.g. `{ 'from' => '10.0.0.1',
# 'via' => '10.0.0.254',
# 'lookup' => 'customroute',
# 'metric' => '15' }`
# Supported properties: from, to, dev, lookup, metric
#
# $virtual_ipaddress_excluded:: For cases with large numbers (eg 200) of IPs
# on the same interface. To decrease the number
# of packets sent in adverts, you can exclude
Expand Down Expand Up @@ -167,6 +177,7 @@
$virtual_ipaddress_int = undef,
$virtual_ipaddress_excluded = undef,
$virtual_routes = undef,
Optional[Array[Keepalived::Vrrp::Instance::VRule]] $virtual_rules = undef,
$smtp_alert = false,
$nopreempt = false,
$preempt_delay = undef,
Expand Down
21 changes: 21 additions & 0 deletions spec/defines/keepalived_vrrp_instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,27 @@
}
end

describe 'with virtual_rules as array of hashes' do
let(:params) do
mandatory_params.merge(
virtual_rules: [{ 'from' => '10.0.1.24', 'lookup' => 'customroute1' },
{ 'from' => '10.0.2.24', 'lookup' => 'customroute2' }]
)
end

it { is_expected.to create_keepalived__vrrp__instance('_NAME_') }
it {
is_expected.to \
contain_concat__fragment('keepalived.conf_vrrp_instance__NAME_').with(
'content' => %r{^\s+from 10\.0\.1\.24 lookup customroute1}
)
is_expected.to \
contain_concat__fragment('keepalived.conf_vrrp_instance__NAME_').with(
'content' => %r{^\s+from 10\.0\.2\.24 lookup customroute2}
)
}
end

# device in hash overrides anything
describe 'with virtual_routes as hash containing device parameter' do
let(:params) do
Expand Down
8 changes: 8 additions & 0 deletions templates/vrrp_instance.erb
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ vrrp_instance <%= @_name %> {
}
<%- end -%>
<%- if @virtual_rules -%>
virtual_rules {
<%- @virtual_rules.each do |rule| -%>
<%= rule['rule'] %> <%= rule.sort_by{ |k,v| k }.entries.join ' ' %>
<%- end -%>
}
<%- end -%>
<%- if @multicast_source_ip -%>
mcast_src_ip <%= @multicast_source_ip %>
<%- end -%>
Expand Down
6 changes: 6 additions & 0 deletions types/vrrp/instance/vrule.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type Keepalived::Vrrp::Instance::VRule = Struct[
Optional[from] => String,
Optional[to] => String,
Optional[dev] => String,
Optional[lookup] => String
]

0 comments on commit 2db0f02

Please sign in to comment.