Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow dhcp::host to set "on EVENT" handlers #216

Merged
merged 1 commit into from
Mar 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,20 @@ dhcp::host { 'server1':
ip => '10.0.1.51',
# Optionally override subnet/global settings for some hosts.
default_lease_time => 600,
max_lease_time => 900
max_lease_time => 900,
# Optionally declare event statements in any combination.
on_commit => [
'set ClientIP = binary-to-ascii(10, 8, ".", leased-address)',
'execute("/usr/local/bin/my_dhcp_helper.sh", ClientIP)'
],
on_release => [
'set ClientIP = binary-to-ascii(10, 8, ".", leased-address)',
'log(concat("Released IP: ", ClientIP))'
],
on_expiry => [
'set ClientIP = binary-to-ascii(10, 8, ".", leased-address)',
'log(concat("Expired IP: ", ClientIP))'
]
}
```

Expand Down
3 changes: 3 additions & 0 deletions manifests/host.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
Boolean $ignored = false,
Optional[Integer] $default_lease_time = undef,
Optional[Integer] $max_lease_time = undef,
Array[String[1]] $on_commit = [],
Array[String[1]] $on_release = [],
Array[String[1]] $on_expiry = [],
) {

$host = $name
Expand Down
26 changes: 25 additions & 1 deletion spec/defines/host_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,19 @@
let(:params) do
default_params.merge(
'default_lease_time' => 600,
'max_lease_time' => 900
'max_lease_time' => 900,
'on_commit' => [
'set ClientIP = binary-to-ascii(10, 8, ".", leased-address)',
'execute("/usr/local/bin/my_dhcp_helper.sh", ClientIP)'
],
'on_release' => [
'set ClientIP = binary-to-ascii(10, 8, ".", leased-address)',
'log(concat("Released IP: ", ClientIP))'
],
'on_expiry' => [
'set ClientIP = binary-to-ascii(10, 8, ".", leased-address)',
'log(concat("Expired IP: ", ClientIP))'
]
)
end

Expand All @@ -80,6 +92,18 @@
" ddns-hostname \"#{title}\";",
' default-lease-time 600;',
' max-lease-time 900;',
' on commit {',
' set ClientIP = binary-to-ascii(10, 8, ".", leased-address);',
' execute("/usr/local/bin/my_dhcp_helper.sh", ClientIP);',
' }',
' on release {',
' set ClientIP = binary-to-ascii(10, 8, ".", leased-address);',
' log(concat("Released IP: ", ClientIP));',
' }',
' on expiry {',
' set ClientIP = binary-to-ascii(10, 8, ".", leased-address);',
' log(concat("Expired IP: ", ClientIP));',
' }',
'}'
]
expect(content.split("\n")).to match_array(expected_lines)
Expand Down
21 changes: 21 additions & 0 deletions templates/dhcpd.host.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,25 @@ host <%= @host %> {
option <%= option %> <%= @options[option] %>;
<% end -%>
<% end -%>
<% if not @on_commit.empty? -%>
on commit {
<% @on_commit.each do |statement| -%>
<%= statement %>;
<% end -%>
}
<% end -%>
<% if not @on_release.empty? -%>
on release {
<% @on_release.each do |statement| -%>
<%= statement %>;
<% end -%>
}
<% end -%>
<% if not @on_expiry.empty? -%>
on expiry {
<% @on_expiry.each do |statement| -%>
<%= statement %>;
<% end -%>
}
<% end -%>
}