From 9a3c5afc536afc40db37810cc0c9435f917f427a Mon Sep 17 00:00:00 2001 From: Pat Riehecky Date: Tue, 11 Apr 2017 14:16:42 -0500 Subject: [PATCH] Added resource args for use with an ENC --- README.md | 9 +++++++++ manifests/init.pp | 20 ++++++++++++++++++++ spec/classes/dhcp_spec.rb | 27 +++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/README.md b/README.md index c40c57f7b..9ad7d4bfb 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,8 @@ class { 'dhcp': Define the pool attributes. This example will create a pool, which serves IPs of two different ranges in the same network. +May be passed as a hash into the DHCP class. + ```puppet dhcp::pool{ 'ops.dc1.example.net': network => '10.0.1.0', @@ -61,6 +63,7 @@ dhcp::pool{ 'ops.dc1.example.net': Define a subnet that will be ignored - useful for making the DHCP server only respond to requests forwarded by switches etc. +May be passed as a hash into the DHCP class. ```puppet dhcp::ignoredsubnet{ 'eth0': network => '10.0.0.0', @@ -72,6 +75,7 @@ dhcp::ignoredsubnet{ 'eth0': Create host reservations. +May be passed as a hash into the DHCP class. ```puppet dhcp::host { 'server1': comment => 'Optional descriptive comment', @@ -149,6 +153,11 @@ The following is the list of all parameters available for this class. | `service_ensure` | Enum | `running` | | `servicename` | String | `$dhcp::params::servicename` | | `use_ldap` | Boolean | `false` | +| `dhcp_classes` | Hash | `{}` | +| `hosts` | Hash | `{}` | +| `ignoredsubnets` | Hash | `{}` | +| `pools` | Hash | `{}` | +| `pools6` | Hash | `{}` | ## Contributors diff --git a/manifests/init.pp b/manifests/init.pp index 508af34c1..c943ed4e7 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -54,6 +54,11 @@ Boolean $use_ldap = false, String $option_code150_label = 'pxegrub', String $option_code150_value = 'text', + Hash[String, Hash] $dhcp_classes = {}, + Hash[String, Hash] $hosts = {}, + Hash[String, Hash] $ignoredsubnets = {}, + Hash[String, Hash] $pools = {}, + Hash[String, Hash] $pools6 = {}, ) inherits dhcp::params { if $dnsdomain == undef { @@ -242,6 +247,21 @@ order => '01', } + # Create any DHCP classes requested + create_resources('dhcp::dhcp_class', $dhcp_classes) + + # Create any DHCP hosts requested + create_resources('dhcp::host', $hosts) + + # Ignore any DHCP subnets requested + create_resources('dhcp::ignoredsubnet', $ignoredsubnets) + + # Setup any DHCP pools for IPv6 + create_resources('dhcp::pool6', $pools6) + + # Setup any DHCP pools for IPv4 + create_resources('dhcp::pool', $pools) + # check if this is really a bool if $use_ldap { if ($ldap_password == '') { diff --git a/spec/classes/dhcp_spec.rb b/spec/classes/dhcp_spec.rb index d043a5b6e..8849b5b0c 100644 --- a/spec/classes/dhcp_spec.rb +++ b/spec/classes/dhcp_spec.rb @@ -155,6 +155,33 @@ end end + context 'resources' do + let :params do + default_params.merge('interfaces' => ['eth0'], + 'pools' => { 'ops.dc1.example.net' => { 'network' => '10.0.1.0', + 'mask' => '255.255.255.0', + 'range' => ['10.0.1.10 10.0.1.100', '10.0.1.200 10.0.1.250'], + 'gateway' => '10.0.1.1' } }, + 'pools6' => { 'ipv6.dc1.example.net' => { 'network' => '2001:db8::', + 'prefix' => 64, + 'range' => '2001:db8::100 2001:db8::110' } }, + 'ignoredsubnets' => { 'eth0' => { 'network' => '10.0.0.0', + 'mask' => '255.255.255.0' } }, + 'hosts' => { 'server1' => { 'comment' => 'Optional descriptive comment', + 'mac' => '00:50:56:00:00:01', + 'ip' => '10.0.1.51' } }, + 'dhcp_classes' => { 'vendor-class-identifier' => { 'parameters' => ['match option vendor-class-identifier'] } }) + end + + it 'has resources' do + is_expected.to contain_concat__fragment('dhcp_pool_ops.dc1.example.net') + is_expected.to contain_concat__fragment('dhcp_pool_ipv6.dc1.example.net') + is_expected.to contain_concat__fragment('dhcp_ignoredsubnet_eth0') + is_expected.to contain_concat__fragment('dhcp_host_server1') + is_expected.to contain_concat__fragment('dhcp_class_vendor-class-identifier') + end + end + context 'ntp' do let :params do default_params.merge(interfaces: ['eth0'])