From 4cc54cff2d04eedb672c7cc6b92a5edcccac63c9 Mon Sep 17 00:00:00 2001 From: Raphaël Pinson Date: Thu, 11 Apr 2013 12:34:23 +0200 Subject: Add spec tests for the dhcp class --- manifests/hosts.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'manifests/hosts.pp') diff --git a/manifests/hosts.pp b/manifests/hosts.pp index b159449..426d661 100644 --- a/manifests/hosts.pp +++ b/manifests/hosts.pp @@ -42,7 +42,7 @@ define dhcp::hosts ( $template = 'dhcp/host.conf.erb', ) { - include dhcp::params + include ::dhcp::params concat::fragment {"dhcp.host.${name}": target => "${dhcp::params::config_dir}/hosts.d/${subnet}.conf", -- cgit v1.2.3 From f4e7bdf477586e34e47a972172c15809ac92fe3c Mon Sep 17 00:00:00 2001 From: Raphaël Pinson Date: Fri, 12 Apr 2013 10:38:14 +0200 Subject: Improve template host.conf.erb with validations and add spec for dhcp::hosts --- manifests/hosts.pp | 26 ++- spec/defines/dhcp_hosts_spec.rb | 411 ++++++++++++++++++++++++++++++++++++++++ templates/host.conf.erb | 32 ++-- 3 files changed, 451 insertions(+), 18 deletions(-) create mode 100644 spec/defines/dhcp_hosts_spec.rb (limited to 'manifests/hosts.pp') diff --git a/manifests/hosts.pp b/manifests/hosts.pp index 426d661..f8e5faf 100644 --- a/manifests/hosts.pp +++ b/manifests/hosts.pp @@ -1,4 +1,4 @@ -# = Definition: dhcp::hosts +# Definition: dhcp::hosts # # Creates a dhcp configuration for given hosts # @@ -38,15 +38,27 @@ define dhcp::hosts ( $hash_data, $subnet, - $global_options = false, - $template = 'dhcp/host.conf.erb', + $ensure = present, + $global_options = [], + $template = "${module_name}/host.conf.erb", ) { include ::dhcp::params - concat::fragment {"dhcp.host.${name}": - target => "${dhcp::params::config_dir}/hosts.d/${subnet}.conf", - content => template($template), - notify => Service['dhcpd'], + validate_string($ensure) + validate_re($ensure, ['present', 'absent'], + "\$ensure must be either 'present' or 'absent', got '${ensure}'") + validate_hash($hash_data) + validate_string($subnet) + validate_re($subnet, '^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$') + validate_array($global_options) + validate_string($template) + + if ($ensure == 'present') { + concat::fragment {"dhcp.host.${name}": + target => "${dhcp::params::config_dir}/hosts.d/${subnet}.conf", + content => template($template), + notify => Service['dhcpd'], + } } } diff --git a/spec/defines/dhcp_hosts_spec.rb b/spec/defines/dhcp_hosts_spec.rb new file mode 100644 index 0000000..658be20 --- /dev/null +++ b/spec/defines/dhcp_hosts_spec.rb @@ -0,0 +1,411 @@ +require 'spec_helper' + +describe 'dhcp::hosts' do + let (:title) { 'My hosts' } + let (:facts) { { + :operatingsystem => 'Debian', + :osfamily => 'Debian', + :lsbdistcodename => 'squeeze', + } } + + context 'when passing wrong value for ensure' do + let (:params) { { + :hash_data => {}, + :subnet => '1.2.3.4', + :ensure => 'running' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /\$ensure must be either 'present' or 'absent', got 'running'/) + end + end + + context 'when hash_data is not passed' do + let (:params) { { + :subnet => '1.2.3.4', + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /Must pass hash_data to Dhcp::Hosts/) + end + end + + context 'when passing wrong type for hash_data' do + let (:params) { { + :hash_data => 'foo', + :subnet => '1.2.3.4', + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /"foo" is not a Hash\./) + end + end + + context 'when subnet is not passed' do + let (:params) { { + :hash_data => {}, + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /Must pass subnet to Dhcp::Hosts/) + end + end + + context 'when passing wrong type for subnet' do + let (:params) { { + :hash_data => {}, + :subnet => true + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /true is not a string\./) + end + end + + context 'when passing wrong value for subnet' do + let (:params) { { + :hash_data => {}, + :subnet => 'foo' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /"foo" does not match/) + end + end + + context 'when passing wrong type for global_options' do + let (:params) { { + :hash_data => {}, + :subnet => '1.2.3.4', + :global_options => 'foo' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /"foo" is not an Array\./) + end + end + + context 'when passing wrong type for template' do + let (:params) { { + :hash_data => {}, + :subnet => '1.2.3.4', + :template => true + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /true is not a string\./) + end + end + + context 'when passing one entry in hash_data' do + context 'when passing wrong type for an host data' do + let (:params) { { + :hash_data => { + 'host1' => true, + }, + :subnet => '1.2.3.4' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /true is not a Hash/) + end + end + + context 'when interfaces is not passed' do + let (:params) { { + :hash_data => { + 'host1' => { + }, + }, + :subnet => '1.2.3.4' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /Missing interfaces hash for host 'host1'/) + end + end + + context 'when passing wrong value for an interface' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth 0' => '00:11:22:33:44:55', + }, + }, + }, + :subnet => '1.2.3.4' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /"eth 0" does not match/) + end + end + + context 'when passing wrong type for a mac address' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => true, + }, + }, + }, + :subnet => '1.2.3.4' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /true is not a string\./) + end + end + + context 'when passing wrong value for a mac address' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => 'my mac', + }, + }, + }, + :subnet => '1.2.3.4' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /"my mac" does not match/) + end + end + + context 'when passing wrong type for fixed_address' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + }, + 'fixed_address' => true, + }, + }, + :subnet => '1.2.3.4' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /true is not a string/) + end + end + + context 'when passing wrong value for fixed_address' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + }, + 'fixed_address' => 'my wrong value', + }, + }, + :subnet => '1.2.3.4' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /"my wrong value" does not match/) + end + end + + context 'when not passing fixed_address' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + }, + }, + }, + :subnet => '1.2.3.4' + } } + + it { should contain_concat__fragment('dhcp.host.My hosts').with( + :content => /fixed-address host1;/ + ) } + end + + context 'when not passing options' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + }, + }, + }, + :subnet => '1.2.3.4', + :global_options => ['foo', 'bar'], + } } + + it { should contain_concat__fragment('dhcp.host.My hosts').with( + :content => /foo;\nbar;\n/ + ) } + end + + context 'when overriding options' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + }, + 'options' => ['baz'], + }, + }, + :subnet => '1.2.3.4', + :global_options => ['foo', 'bar'], + } } + + it { should contain_concat__fragment('dhcp.host.My hosts').with( + :content => /baz;\n/ + ) } + end + + context 'when passing wrong type for options' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + }, + 'options' => true, + }, + }, + :subnet => '1.2.3.4', + :global_options => ['foo', 'bar'], + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /true is not an Array\./) + end + end + + context 'when passing wrong value for fixed_address' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + }, + 'fixed_address' => 'my wrong value', + }, + }, + :subnet => '1.2.3.4' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /"my wrong value" does not match/) + end + end + + context 'when not passing fixed_address' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + }, + }, + }, + :subnet => '1.2.3.4' + } } + + it { should contain_concat__fragment('dhcp.host.My hosts').with( + :content => /fixed-address host1;/ + ) } + end + + context 'when not passing options' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + }, + }, + }, + :subnet => '1.2.3.4', + :global_options => ['foo', 'bar'], + } } + + it { should contain_concat__fragment('dhcp.host.My hosts').with( + :content => /foo;\nbar;\n/ + ) } + end + + context 'when passing two hosts' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + 'wlan0' => '00:aa:bb:44:55:ff', + }, + }, + 'host2' => { + 'interfaces' => { + 'eth1' => '00:11:af:33:44:55', + }, + 'fixed_address' => 'foo.example.com', + 'options' => ['opt1'], + }, + }, + :subnet => '1.2.3.4' + } } + + it { should contain_concat__fragment('dhcp.host.My hosts').with_content( + /host host1-eth0 \{\n hardware ethernet 00:11:22:33:44:55;\n fixed-address host1;\n\}/).with_content( + /host host1-wlan0 \{\n hardware ethernet 00:aa:bb:44:55:ff;\n fixed-address host1;\n\}/).with_content( + /host host2-eth1 \{\n hardware ethernet 00:11:af:33:44:55;\n fixed-address foo\.example\.com;\n opt1;\n\}/) + } + end + end + + context 'when passing two entries in hash_data' do + end + + context 'when passing global_options' do + end + + context 'when overriding template' do + end +end diff --git a/templates/host.conf.erb b/templates/host.conf.erb index e6a7073..398d798 100644 --- a/templates/host.conf.erb +++ b/templates/host.conf.erb @@ -1,16 +1,26 @@ -<%- @hash_data.sort.each do |host, datas| -%> -<%- datas.fetch('interfaces').sort.each do |if_name, if_mac| -%> +<%- @hash_data.sort.each do |host, data| + scope.function_validate_hash([data]) -%> +<%- + raise Puppet::ParseError, "Missing interfaces hash for host '#{host}'" unless data.has_key? 'interfaces' + data.fetch('interfaces').sort.each do |if_name, if_mac| + scope.function_validate_re([if_name, '^\S+$']) + scope.function_validate_string([if_mac]) + scope.function_validate_re([if_mac, '^[a-f0-9:.]+$']) + -%> host <%= host %>-<%= if_name %> { hardware ethernet <%= if_mac %>; -<% if datas.fetch('fixed_address', false) -%> - fixed-address <%= datas.fetch('fixed_address') %>; -<% else -%> - fixed-address <%= host %>; -<% end -%> -<% if datas.fetch('option', false) -%> - <%= datas.fetch('option') %> -<% elsif @global_options -%> - <%= @global_options %> +<% + fixed_address = data.fetch('fixed_address', nil) || host + scope.function_validate_string([fixed_address]) + scope.function_validate_re([fixed_address, '^\S+$']) + -%> + fixed-address <%= fixed_address %>; +<% + options = data.fetch('options', nil) || @global_options + scope.function_validate_array([options]) + unless options.empty? + -%> + <%= options.join(";\n") %>; <% end -%> } <% end -%> -- cgit v1.2.3 From f7025518512c0bf8d63f413f7be78347fedee9f4 Mon Sep 17 00:00:00 2001 From: Raphaël Pinson Date: Fri, 12 Apr 2013 10:50:24 +0200 Subject: Test target for concat::fragment in dhcp::hosts --- manifests/hosts.pp | 8 +++----- spec/defines/dhcp_hosts_spec.rb | 7 ++++++- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'manifests/hosts.pp') diff --git a/manifests/hosts.pp b/manifests/hosts.pp index f8e5faf..676d507 100644 --- a/manifests/hosts.pp +++ b/manifests/hosts.pp @@ -4,15 +4,14 @@ # # Arguments # $template: dhcp host template - default: 'dhcp/host.conf.erb' -# $global_options: global options for the whole bunch of hosts. +# $global_options: an array of global options for the whole bunch of hosts. # you may override it per host, setting the host "options" # directly in the hash. # $subnet: targeted subnet # $hash_data: hash containing data - default form: # { # => { -# options => false, -# fixed_address => false, +# options => ['opt1', 'opt2'], # interfaces => { # eth0 => 'mac-address', # eth1 => 'mac-address', @@ -22,8 +21,7 @@ # } # }, # => { -# options => false, -# fixed_address => false, +# fixed_address => 'foo.example.com', # interfaces => { # eth0 => 'mac-address', # eth1 => 'mac-address', diff --git a/spec/defines/dhcp_hosts_spec.rb b/spec/defines/dhcp_hosts_spec.rb index c8face6..f5f44ca 100644 --- a/spec/defines/dhcp_hosts_spec.rb +++ b/spec/defines/dhcp_hosts_spec.rb @@ -255,6 +255,7 @@ describe 'dhcp::hosts' do } } it { should contain_concat__fragment('dhcp.host.My hosts').with( + :target => '/etc/dhcp/hosts.d/1.2.3.4.conf', :content => /fixed-address host1;/ ) } end @@ -273,6 +274,7 @@ describe 'dhcp::hosts' do } } it { should contain_concat__fragment('dhcp.host.My hosts').with( + :target => '/etc/dhcp/hosts.d/1.2.3.4.conf', :content => /foo;\nbar;\n/ ) } end @@ -292,6 +294,7 @@ describe 'dhcp::hosts' do } } it { should contain_concat__fragment('dhcp.host.My hosts').with( + :target => '/etc/dhcp/hosts.d/1.2.3.4.conf', :content => /baz;\n/ ) } end @@ -331,6 +334,7 @@ describe 'dhcp::hosts' do } } it { should contain_concat__fragment('dhcp.host.My hosts').with( + :target => '/etc/dhcp/hosts.d/1.2.3.4.conf', :content => /foo;\nbar;\n/ ) } end @@ -355,7 +359,8 @@ describe 'dhcp::hosts' do :subnet => '1.2.3.4' } } - it { should contain_concat__fragment('dhcp.host.My hosts').with_content( + it { should contain_concat__fragment('dhcp.host.My hosts').with( + :target => '/etc/dhcp/hosts.d/1.2.3.4.conf').with_content( /host host1-eth0 \{\n hardware ethernet 00:11:22:33:44:55;\n fixed-address host1;\n\}/).with_content( /host host1-wlan0 \{\n hardware ethernet 00:aa:bb:44:55:ff;\n fixed-address host1;\n\}/).with_content( /host host2-eth1 \{\n hardware ethernet 00:11:af:33:44:55;\n fixed-address foo\.example\.com;\n opt1;\n\}/) -- cgit v1.2.3 From f28c3616cefa8f2c53fd04cbc2b3a58b0cb4f0be Mon Sep 17 00:00:00 2001 From: Raphaël Pinson Date: Fri, 12 Apr 2013 10:56:56 +0200 Subject: Pass $ensure to concat::fragment in dhcp::hosts --- manifests/hosts.pp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'manifests/hosts.pp') diff --git a/manifests/hosts.pp b/manifests/hosts.pp index 676d507..9e2b284 100644 --- a/manifests/hosts.pp +++ b/manifests/hosts.pp @@ -52,11 +52,10 @@ define dhcp::hosts ( validate_array($global_options) validate_string($template) - if ($ensure == 'present') { - concat::fragment {"dhcp.host.${name}": - target => "${dhcp::params::config_dir}/hosts.d/${subnet}.conf", - content => template($template), - notify => Service['dhcpd'], - } + concat::fragment {"dhcp.host.${name}": + ensure => $ensure, + target => "${dhcp::params::config_dir}/hosts.d/${subnet}.conf", + content => template($template), + notify => Service['dhcpd'], } } -- cgit v1.2.3 From 928dbaa62bcc37092ddec36b1f715365576eae6d Mon Sep 17 00:00:00 2001 From: Raphaël Pinson Date: Fri, 12 Apr 2013 14:11:44 +0200 Subject: doc --- README.md | 8 +++++++ manifests/hosts.pp | 38 +++++++++++++++++++++++++------ manifests/init.pp | 22 ++++++++++++++++++ manifests/server.pp | 54 +++++++++++++++++++++++---------------------- manifests/shared_network.pp | 20 ++++++++++++----- manifests/subnet.pp | 34 ++++++++++++++-------------- 6 files changed, 120 insertions(+), 56 deletions(-) (limited to 'manifests/hosts.pp') diff --git a/README.md b/README.md index 7a54b86..eb129db 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,14 @@ This module is provided by [Camptocamp](http://www.camptocamp.com/) * dhcp * dhcp::server +### dhcp + +The `dhcp` class is a wrapper around `dhcp::server`: + + include ::dhcp + +### dhcp::server + ## Definitions * dhcp::hosts diff --git a/manifests/hosts.pp b/manifests/hosts.pp index 9e2b284..1767a90 100644 --- a/manifests/hosts.pp +++ b/manifests/hosts.pp @@ -2,13 +2,13 @@ # # Creates a dhcp configuration for given hosts # -# Arguments -# $template: dhcp host template - default: 'dhcp/host.conf.erb' -# $global_options: an array of global options for the whole bunch of hosts. -# you may override it per host, setting the host "options" -# directly in the hash. -# $subnet: targeted subnet -# $hash_data: hash containing data - default form: +# Parameters: +# ['template'] - DHCP host template - default: 'dhcp/host.conf.erb' +# ['global_options'] - An array of global options for the whole bunch of +# hosts. You may override it per host, setting the +# host "options" directly in the hash. +# ['subnet'] - Targeted subnet +# ['hash_data'] - Hash containing data - default form: # { # => { # options => ['opt1', 'opt2'], @@ -33,6 +33,30 @@ # …, # } # +# Sample usage: +# ::dhcp::hosts { 'workstations': +# subnet => '192.168.1.0', +# 'hash_data' => { +# 'host1' => { +# 'interfaces' => { +# 'eth0' => '00:11:22:33:44:55', +# 'wlan0' => '00:aa:bb:44:55:ff', +# }, +# }, +# 'host2' => { +# 'interfaces' => { +# 'eth1' => '00:11:af:33:44:55', +# }, +# 'fixed_address' => 'foo.example.com', +# 'options' => ['opt1'], +# }, +# }, +# } +# +# Requires: +# - puppetlabs/stdlib +# - ripienaar/concat +# define dhcp::hosts ( $hash_data, $subnet, diff --git a/manifests/init.pp b/manifests/init.pp index e1e05b3..9af496f 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,3 +1,25 @@ +# Class: dhcp +# +# This class provides a simple way to install a DHCP server +# It will install and configure the necessary packages. +# +# Parameters: +# ['server'] - Whether to install the DHCP server +# (default: true) +# ['server_ddns_update'] - Set ddns_update on dhcp::server +# ['server_authoritative'] - Set authoritative on dhcp::server +# ['server_opts'] - Set opts for dhcp::server +# +# Actions: +# - Deploys a DHCP server +# +# Sample usage: +# include ::dhcp +# +# Requires: +# - puppetlabs/stdlib +# - ripienaar/concat +# class dhcp ( $server = true, $server_ddns_update = undef, diff --git a/manifests/server.pp b/manifests/server.pp index 1c77cf2..a44cfe1 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -1,35 +1,37 @@ -# = Class: dhcp::server -# Simple OS wrapper. Include this to install a dhcp server on your host. +# Class: dhcp::server # -# Requires: -# module "common": git://github.com/camptocamp/puppet-common.git +# Installs and configures a DHCP server. # -# facultative argument: -# *$ddns_update* : ddns-update-style option (defaults to 'none') -# *$authoritative* : a boolean setting whether the DHCP server is -# authoritative (defaults to false) -# *$opts* : an array of DHCPD valid options +# Parameters: +# ['ddns_update'] : ddns-update-style option (defaults to 'none') +# ['authoritative'] : a boolean setting whether the DHCP server is +# authoritative (defaults to false) +# ['opts'] : an array of DHCPD valid options # -# Example: -# node "dhcp.toto.ltd" { -# class { 'dhcp::server': -# opts => ['domain-name "toto.ltd"', -# 'domain-name-servers 192.168.21.1'], -# } +# Sample usage: +# node "dhcp.toto.ltd" { +# class { 'dhcp::server': +# opts => ['domain-name "toto.ltd"', +# 'domain-name-servers 192.168.21.1'], +# } # -# dhcp::subnet {"10.27.20.0": -# ensure => present, -# broadcast => "10.27.20.255", -# other_opts => ['filename "pxelinux.0";', 'next-server 10.27.10.1;'], -# } +# dhcp::subnet {"10.27.20.0": +# ensure => present, +# broadcast => "10.27.20.255", +# other_opts => ['filename "pxelinux.0";', 'next-server 10.27.10.1;'], +# } # -# dhcp::host {"titi-eth0": -# ensure => present, -# mac => "0e:18:fa:fe:d9:00", -# subnet => "10.27.20.0", -# fixed_address => "10.27.10.52", +# dhcp::host {"titi-eth0": +# ensure => present, +# mac => "0e:18:fa:fe:d9:00", +# subnet => "10.27.20.0", +# fixed_address => "10.27.10.52", +# } # } -# } +# +# Requires: +# - puppetlabs/stdlib +# - ripienaar/concat # class dhcp::server ( $ddns_update = 'none', diff --git a/manifests/shared_network.pp b/manifests/shared_network.pp index 38f14fb..766f432 100644 --- a/manifests/shared_network.pp +++ b/manifests/shared_network.pp @@ -1,12 +1,22 @@ -# == Definition: dhcp::shared-network +# Definition: dhcp::shared-network +# # Creates a shared-network # -# Arguments: -# *$subnets* : subnet list to be included in the shared-network +# Parameters: +# ['subnets'] - An array of subnets to be included in the shared-network. +# +# Sample usage: +# ::dhcp::shared_network { 'office': +# subnets => ['192.168.1.0', '192.168.2.0'], +# } +# +# Requires: +# - puppetlabs/stdlib +# - ripienaar/concat # # Warnings: -# - subnets must exists -# - subnets must have $is_shared set to true (default is false) +# - subnets must exists +# - subnets must have $is_shared set to true (default is false) # define dhcp::shared_network( $ensure = present, diff --git a/manifests/subnet.pp b/manifests/subnet.pp index b9826da..b70a233 100644 --- a/manifests/subnet.pp +++ b/manifests/subnet.pp @@ -1,29 +1,27 @@ -# = Definition: dhcp::subnet -# Creates a subnet -# -# Arguments: -# *$broadcast* : subnet broadcast (mandatory) -# *$netmask* : subnet netmask (if not set, takes eth0 netmask) -# *$routers* : subnet routers (array) (if not set, takes eth0 IP) -# *$subnet_mask* : netmask sent to dhcp guests (if not set, takes -# $netmask, or netmask_eth0) -# *$domain_name* : subnet domain name (if not set, takes server domain) -# *$other_opts* : any other DHCPD option, as an array -# *$is_shared* : whether it's part of a shared network or not. Default: false +# Definition: dhcp::subnet # -# Example: +# Creates a subnet # -# node "dhcp.domain.ltd" { -# $dhcpd_domain_name = 'domain.ltd' -# $dhcpd_dns_servers = '10.27.21.1, 10.26.21.1' -# include dhcp +# Parameters: +# ['broadcast'] : subnet broadcast (mandatory) +# ['netmask'] : subnet netmask +# (default: $::netmask_eth0) +# ['routers'] : An array of subnet routers +# (default: $::netmask) +# ['subnet_mask'] : netmask sent to dhcp guests +# (default: the value of $netmask) +# ['domain_name'] : subnet domain name +# (default: $::domain) +# ['other_opts'] : An array of additional DHCPD options +# ['is_shared'] : whether it's part of a shared network or not +# (default: false) # +# Sample usage: # dhcp::subnet {"10.27.20.0": # ensure => present, # broadcast => "10.27.20.255", # other_opts => ['filename "pxelinux.0";', 'next-server 10.27.10.1;'], # } -# } # define dhcp::subnet( $broadcast, -- cgit v1.2.3 From 6fd559e9c99e85426d41358a5ed95c522c8031bc Mon Sep 17 00:00:00 2001 From: Raphaël Pinson Date: Fri, 12 Apr 2013 14:20:38 +0200 Subject: README --- README.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ manifests/hosts.pp | 2 +- 2 files changed, 49 insertions(+), 1 deletion(-) (limited to 'manifests/hosts.pp') diff --git a/README.md b/README.md index eb129db..eb8ae5b 100644 --- a/README.md +++ b/README.md @@ -17,12 +17,60 @@ The `dhcp` class is a wrapper around `dhcp::server`: ### dhcp::server +Installs a DHCP server: + + class { 'dhcp::server': + opts => ['domain-name "toto.ltd"', + 'domain-name-servers 192.168.21.1'], + } + ## Definitions * dhcp::hosts * dhcp::shared\_network * dhcp::subnet +### dhcp::hosts + +Creates a DHCP configuration for the given hosts: + + dhcp::hosts { 'workstations': + subnet => '192.168.1.0', + 'hash_data' => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + 'wlan0' => '00:aa:bb:44:55:ff', + }, + }, + 'host2' => { + 'interfaces' => { + 'eth1' => '00:11:af:33:44:55', + }, + 'fixed_address' => 'foo.example.com', + 'options' => ['opt1'], + }, + }, + } + +### dhcp::shared\_network + +Creates a shared-network entry: + + dhcp::shared_network { 'office': + subnets => ['192.168.1.0', '192.168.2.0'], + } + +### dhcp::subnet + +Creates a subnet: + + dhcp::subnet {"10.27.20.0": + ensure => present, + broadcast => "10.27.20.255", + other_opts => ['filename "pxelinux.0";', 'next-server 10.27.10.1;'], + } + ## Contributing Please report bugs and feature request using [GitHub issue diff --git a/manifests/hosts.pp b/manifests/hosts.pp index 1767a90..9c5d1b3 100644 --- a/manifests/hosts.pp +++ b/manifests/hosts.pp @@ -1,6 +1,6 @@ # Definition: dhcp::hosts # -# Creates a dhcp configuration for given hosts +# Creates a dhcp configuration for the given hosts # # Parameters: # ['template'] - DHCP host template - default: 'dhcp/host.conf.erb' -- cgit v1.2.3