Skip to content

Commit

Permalink
Fixing theforeman#62 - add support for dhcp6
Browse files Browse the repository at this point in the history
  • Loading branch information
dmcanally committed Nov 28, 2017
1 parent f782602 commit 0947278
Show file tree
Hide file tree
Showing 8 changed files with 232 additions and 4 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ Define the server and the zones it will be responsible for.
pxefilename => 'pxelinux.0',
}

DHCPD6 can be deployed by defining the following class. Note, class dhcp is required.

class { 'dhcp::dhcp6':
dnsdomain => [
'dc1.example.net',
],
nameservers => ['3ffe:501:ffff:100:200:ff:fe00:3f3e'],
}

### dhcp::pool
Define the pool attributes

Expand Down Expand Up @@ -63,6 +72,16 @@ For the support of static routes (RFC3442):
{ 'mask' => '0', 'gateway' => $gw } ],
}

### dhcp::pool6
An example for defining an ipv6 subnet:

dhcp::pool6{ 'v6domain.example.net':
network => '3ffe:501:ffff::',
prefix => 64,
search_domains => ['domain.example.net'],
range => '3ffe:501:ffff::1fff 3ffe:501:ffff::ffff',
}

### dhcp::host
Create host reservations.

Expand All @@ -72,6 +91,16 @@ Create host reservations.
'server3': mac => "00:50:56:00:00:03", ip => "10.0.1.53";
}

### dhcp::host6
Create ipv6 host reservation

dhcp::host6 {
'server1': mac => "00:50:56:00:00:01", ip => "3ffe:501:ffff::51";
'server2': mac => "00:50:56:00:00:01", ip => "3ffe:501:ffff::52";
'server3': mac => "00:50:56:00:00:01", ip => "3ffe:501:ffff::53";
}


## Contributors

Original authors:
Expand Down
67 changes: 67 additions & 0 deletions manifests/dhcp6.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# class dhcp::dhcp6
class dhcp::dhcp6 (
Array[String] $dnsdomain = $dhcp::params::dnsdomain,
Array[String] $nameservers = ['2001:4860:4860::8888', '2001:4860:4860::8844'],
Integer[0] $default_lease_time6 = 2592000,
Integer[0] $default_preferred_lifetime6 = 604800,
Integer[0] $default_renewal_time6 = 3600,
Integer[0] $default_rebinding_time6 = 7200,
Integer[0] $default_info_refresh_time6 = 21600,
Boolean $leasequery6 = true,
Boolean $rapid_commit6 = false,
Integer[0] $default_preference6 = 10,
Stdlib::Absolutepath $dhcp_dir = $dhcp::params::dhcp_dir,
Stdlib::Absolutepath $default_leasefile_path6 = $dhcp::params::default_leasefile_path6,
String $packagename = $dhcp::params::packagename,
String $servicename6 = $dhcp::params::servicename6,
Variant[Array[String], Optional[String]] $options = undef,
String $dhcp_root_group = $dhcp::params::root_group,
Hash[String, Hash] $pools6 = {},
Hash[String, Hash] $hosts6 = {},
Variant[Array[String], Optional[String]] $includes = undef,
) inherits dhcp::params {

concat { "${dhcp_dir}/dhcpd6.conf":
owner => 'root',
group => $dhcp_root_group,
mode => '0644',
require => Package[$packagename],
notify => Service[$servicename6],
}

concat::fragment { 'dhcp6.conf+01_main.dhcp':
target => "${dhcp_dir}/dhcpd6.conf",
content => template('dhcp/dhcpd6.conf.erb'),
order => '01',
}

if $includes {
concat::fragment { 'dhcp6.conf+20_includes':
target => "${dhcp_dir}/dhcpd6.conf",
content => template('dhcp/dhcpd6.conf.includes.erb'),
order => '20',
}
}

concat { "${dhcp_dir}/dhcpd6.hosts":
owner => 'root',
group => $dhcp_root_group,
mode => '0644',
require => Package[$packagename],
notify => Service[$servicename6],
}

concat::fragment { 'dhcp6.hosts+01_main.hosts':
target => "${dhcp_dir}/dhcpd6.hosts",
content => "# static DHCP hosts\n",
order => '01',
}

create_resources('dhcp::pool6', $pools6)
create_resources('dhcp::host6', $hosts6)

service { $servicename6:
ensure => running,
enable => true,
}
}
15 changes: 15 additions & 0 deletions manifests/host6.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#class dhcp::host6
define dhcp::host6 (
String $ip,
Dhcp::Macaddress $mac,
Optional[String] $comment=undef,
) {

$host = $name

concat::fragment { "dhcp.hosts+10_${name}.hosts":
target => "${::dhcp::dhcp_dir}/dhcpd6.hosts",
content => template('dhcp/dhcpd6.host.erb'),
order => "10-${name}",
}
}
10 changes: 6 additions & 4 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@
}

'RedHat': {
$dhcp_dir = '/etc/dhcp'
$packagename = 'dhcp'
$servicename = 'dhcpd'
$root_group = 'root'
$dhcp_dir = '/etc/dhcp'
$default_leasefile_path6 = '/var/lib/dhcpd/dhcpd6.leases'
$packagename = 'dhcp'
$servicename = 'dhcpd'
$servicename6 = 'dhcpd6'
$root_group = 'root'
if $::operatingsystemrelease =~ /^[0-6]\./ {
$bootfiles = {
'00:07' => 'grub/grubx64.efi',
Expand Down
26 changes: 26 additions & 0 deletions manifests/pool6.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# class dhcp::pool6
define dhcp::pool6 (
String $network,
Integer[0] $prefix,
Variant[Array[String], Optional[String]] $pool_parameters = undef,
Variant[Array[Dhcp::Range], String, Optional[Dhcp::Range], Enum[''], Boolean] $range = undef,
Optional[String] $failover = undef,
Variant[Array[String], Optional[String]] $options = undef,
Variant[Array[String], Optional[String]] $parameters = undef,
Optional[Integer[0]] $mtu = undef,
Variant[Array[String], Optional[String]] $nameservers = undef,
Optional[String] $pxeserver = undef,
Optional[String] $pxefilename = undef,
Optional[String] $domain_name = undef,
Variant[Array[String], Optional[String]] $search_domains = undef,
Optional[String] $raw_append = undef,
Optional[String] $raw_prepend = undef,
) {

concat::fragment { "dhcp6.conf+70_${name}.dhcp":
target => "${::dhcp::dhcp_dir}/dhcpd6.conf",
content => template('dhcp/dhcpd6.pool.erb'),
order => "70-${name}",
}

}
33 changes: 33 additions & 0 deletions templates/dhcpd6.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# dhcpd6.conf

default-lease-time <%= @default_lease_time6 %>;
preferred-lifetime <%= @default_preferred_lifetime6 %>;
option dhcp-renewal-time <%= @default_renewal_time6 %>;
option dhcp-rebinding-time <%= @default_rebinding_time6 %>;
option dhcp6.info-refresh-time <%= @default_info_refresh_time6 %>;

<% if @leasequery6 -%>
allow leasequery;
<% end -%>

<% if @default_preference6 -%>
option dhcp6.preference 255;
<% end -%>

<% if @rapid_commit6 -%>
option dhcp6.rapid-commit;
<% end -%>

<% if @nameservers and @nameservers.is_a? Array -%>
option dhcp6.name-servers <%= @nameservers.sort.join(', ') %>;
<% elsif @nameservers -%>
option dhcp6.name-servers <%= @nameservers %>;
<% end -%>
<% if @search_domains and @search_domains.is_a? Array -%>
option dhcp6.domain-search "<%= @search_domains.sort.join('", "') %>";
<% elsif @search_domains -%>
option dhcp6.domain-search "<%= @search_domains.split(/[, ]+/).join('", "') %>";
<% end -%>

# The path of the lease file
dhcpv6-lease-file-name "<%= @default_leasefile_path6 %>";
4 changes: 4 additions & 0 deletions templates/dhcpd6.host.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
host <%= @host %> {
hardware ethernet <%= @mac %>;
fixed-address6 <%= @ip %>;
}
52 changes: 52 additions & 0 deletions templates/dhcpd6.pool.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# <%= @name %>
subnet6 <%= @network %>/<%= @prefix %> {
<% if @raw_prepend -%>
<%= @raw_prepend %>
<% end -%>
<% if (@range && @range.is_a?(String) && [email protected]?) || (@range && @range.is_a?(Array)) -%>
<% if @pool_parameters.is_a? Array -%>
<% @pool_parameters.each do |param| -%>
<%= param %>;
<% end -%>
<% elsif @pool_parameters && !@pool_parameters.strip.empty? -%>
<%= @pool_parameters %>;
<% end -%>
<% if @range and @range.is_a? Array -%>
<% @range.each do |rng| -%>
range6 <%= rng %>;
<% end -%>
<% elsif @range && [email protected]? -%>
range6 <%= @range %>;
<% end -%>
<% end -%>
<% if @domain_name && !@domain_name.strip.empty? -%>
option dhcp6.domain-name "<%= @domain_name %>";
<% end -%>
<% if @options.is_a? Array -%>
<% @options.each do |opt| -%>
option <%= opt %>;
<% end -%>
<% elsif @options && [email protected]? -%>
option <%= @options %>;
<% end -%>
<% if @parameters.is_a? Array -%>
<% @parameters.each do |param| -%>
<%= param %>;
<% end -%>
<% elsif @parameters && [email protected]? -%>
<%= @parameters %>;
<% end -%>
<% if @nameservers and @nameservers.is_a? Array -%>
option dhcp6.name-servers <%= @nameservers.sort.join(', ') %>;
<% elsif @nameservers -%>
option dhcp6.name-servers <%= @nameservers %>;
<% end -%>
<% if @search_domains and @search_domains.is_a? Array -%>
option dhcp6.domain-search "<%= @search_domains.sort.join('", "') %>";
<% elsif @search_domains -%>
option dhcp6.domain-search "<%= @search_domains.split(/[, ]+/).join('", "') %>";
<% end -%>
<% if @raw_append -%>
<%= @raw_append %>
<% end -%>
}

0 comments on commit 0947278

Please sign in to comment.