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

Add support for persistent dhclient #147

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ Normal interface - dhcp:
ethtool_opts => 'autoneg off speed 100 duplex full',
}

Normal interface - dhcp (persistent dhclient):

network::if::dynamic { 'eth2':
ensure => 'up',
persistent_dhclient => true,
}

Normal interface - bootp (minimal):

network::if::dynamic { 'eth2':
Expand Down
67 changes: 35 additions & 32 deletions manifests/if/dynamic.pp
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,21 @@
#
define network::if::dynamic (
$ensure,
$macaddress = undef,
$manage_hwaddr = true,
$bootproto = 'dhcp',
$userctl = false,
$mtu = undef,
$dhcp_hostname = undef,
$ethtool_opts = undef,
$peerdns = false,
$linkdelay = undef,
$check_link_down = false,
$defroute = undef,
$zone = undef,
$metric = undef,
$restart = true,
$macaddress = undef,
$manage_hwaddr = true,
$bootproto = 'dhcp',
$userctl = false,
$mtu = undef,
$dhcp_hostname = undef,
$persistent_dhclient = false,
$ethtool_opts = undef,
$peerdns = false,
$linkdelay = undef,
$check_link_down = false,
$defroute = undef,
$zone = undef,
$metric = undef,
$restart = true,
) {
# Validate our regular expressions
$states = [ '^up$', '^down$' ]
Expand All @@ -77,25 +78,27 @@
validate_bool($userctl)
validate_bool($peerdns)
validate_bool($manage_hwaddr)
validate_bool($persistent_dhclient)

network_if_base { $title:
ensure => $ensure,
ipaddress => '',
netmask => '',
gateway => '',
macaddress => $macaddy,
manage_hwaddr => $manage_hwaddr,
bootproto => $bootproto,
userctl => $userctl,
mtu => $mtu,
dhcp_hostname => $dhcp_hostname,
ethtool_opts => $ethtool_opts,
peerdns => $peerdns,
linkdelay => $linkdelay,
check_link_down => $check_link_down,
defroute => $defroute,
zone => $zone,
metric => $metric,
restart => $restart,
ensure => $ensure,
ipaddress => '',
netmask => '',
gateway => '',
macaddress => $macaddy,
manage_hwaddr => $manage_hwaddr,
bootproto => $bootproto,
userctl => $userctl,
mtu => $mtu,
dhcp_hostname => $dhcp_hostname,
persistent_dhclient => $persistent_dhclient,
ethtool_opts => $ethtool_opts,
peerdns => $peerdns,
linkdelay => $linkdelay,
check_link_down => $check_link_down,
defroute => $defroute,
zone => $zone,
metric => $metric,
restart => $restart,
}
} # define network::if::dynamic
130 changes: 67 additions & 63 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,36 @@
#
# === Parameters:
#
# $ensure - required - up|down
# $ipaddress - optional
# $netmask - optional
# $macaddress - required
# $manage_hwaddr - optional - defaults to true
# $gateway - optional
# $noaliasrouting - optional - defaults to false
# $bootproto - optional
# $userctl - optional - defaults to false
# $mtu - optional
# $dhcp_hostname - optional
# $ethtool_opts - optional
# $bonding_opts - optional
# $isalias - optional
# $peerdns - optional
# $dns1 - optional
# $dns2 - optional
# $domain - optional
# $bridge - optional
# $scope - optional
# $linkdelay - optional
# $check_link_down - optional
# $flush - optional
# $zone - optional
# $metric - optional
# $defroute - optional
# $promisc - optional - defaults to false
# $restart - optional - defaults to true
# $arpcheck - optional - defaults to true
# $ensure - required - up|down
# $ipaddress - optional
# $netmask - optional
# $macaddress - required
# $manage_hwaddr - optional - defaults to true
# $gateway - optional
# $noaliasrouting - optional - defaults to false
# $bootproto - optional
# $userctl - optional - defaults to false
# $mtu - optional
# $dhcp_hostname - optional
# $persistent_dhclient - optional - defaults to false
# $ethtool_opts - optional
# $bonding_opts - optional
# $isalias - optional
# $peerdns - optional
# $dns1 - optional
# $dns2 - optional
# $domain - optional
# $bridge - optional
# $scope - optional
# $linkdelay - optional
# $check_link_down - optional
# $flush - optional
# $zone - optional
# $metric - optional
# $defroute - optional
# $promisc - optional - defaults to false
# $restart - optional - defaults to true
# $arpcheck - optional - defaults to true
#
# === Actions:
#
Expand All @@ -91,7 +92,6 @@
# SCOPE=
# SRCADDR=
# NOZEROCONF=yes
# PERSISTENT_DHCLIENT=yes|no|1|0
# DHCPRELEASE=yes|no|1|0
# DHCLIENT_IGNORE_GATEWAY=yes|no|1|0
# REORDER_HDR=yes|no
Expand All @@ -107,39 +107,40 @@
define network_if_base (
$ensure,
$macaddress,
$ipaddress = undef,
$netmask = undef,
$manage_hwaddr = true,
$gateway = undef,
$noaliasrouting = false,
$ipv6address = undef,
$ipv6gateway = undef,
$ipv6init = false,
$ipv6autoconf = false,
$ipv6secondaries = undef,
$bootproto = 'none',
$userctl = false,
$mtu = undef,
$dhcp_hostname = undef,
$ethtool_opts = undef,
$bonding_opts = undef,
$isalias = false,
$peerdns = false,
$ipv6peerdns = false,
$dns1 = undef,
$dns2 = undef,
$domain = undef,
$bridge = undef,
$linkdelay = undef,
$scope = undef,
$check_link_down = false,
$flush = false,
$defroute = undef,
$zone = undef,
$metric = undef,
$promisc = false,
$restart = true,
$arpcheck = true,
$ipaddress = undef,
$netmask = undef,
$manage_hwaddr = true,
$gateway = undef,
$noaliasrouting = false,
$ipv6address = undef,
$ipv6gateway = undef,
$ipv6init = false,
$ipv6autoconf = false,
$ipv6secondaries = undef,
$bootproto = 'none',
$userctl = false,
$mtu = undef,
$dhcp_hostname = undef,
$persistent_dhclient = false,
$ethtool_opts = undef,
$bonding_opts = undef,
$isalias = false,
$peerdns = false,
$ipv6peerdns = false,
$dns1 = undef,
$dns2 = undef,
$domain = undef,
$bridge = undef,
$linkdelay = undef,
$scope = undef,
$check_link_down = false,
$flush = false,
$defroute = undef,
$zone = undef,
$metric = undef,
$promisc = false,
$restart = true,
$arpcheck = true,
) {
# Validate our booleans
validate_bool($noaliasrouting)
Expand All @@ -163,6 +164,9 @@

$interface = $name

# Normalize $persistent_dhclient value
$persistent_dhclient_real = bool2num($persistent_dhclient)

# Deal with the case where $dns2 is non-empty and $dns1 is empty.
if $dns2 {
if !$dns1 {
Expand Down
30 changes: 30 additions & 0 deletions spec/defines/network_if_dynamic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,35 @@
it { should contain_service('network') }
end

context 'optional parameters - persistent_dhclient' do
let(:title) { 'eth0' }
let :params do {
:ensure => 'up',
:macaddress => 'bb:cc:bb:cc:bb:cc',
:bootproto => 'dhcp',
:persistent_dhclient => true
}
end
let :facts do {
:osfamily => 'RedHat'
}
end
it { should contain_file('ifcfg-eth0').with(
:ensure => 'present',
:mode => '0644',
:owner => 'root',
:group => 'root',
:path => '/etc/sysconfig/network-scripts/ifcfg-eth0',
:notify => 'Service[network]'
)}
it 'should contain File[ifcfg-eth0] with required contents' do
verify_contents(catalogue, 'ifcfg-eth0', [
'DEVICE=eth0',
'HWADDR=bb:cc:bb:cc:bb:cc',
'PERSISTENT_DHCLIENT=1'
])
end
it { should contain_service('network') }
end

end
3 changes: 3 additions & 0 deletions templates/ifcfg-eth.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
###
DEVICE=<%= @interface %>
BOOTPROTO=<%= @bootproto %>
<% if @bootproto == 'dhcp' -%>
PERSISTENT_DHCLIENT=<%= @persistent_dhclient_real %>
<% end -%>
<% if @manage_hwaddr and @macaddress and @macaddress != '' -%>
HWADDR=<%= @macaddress %>
<% end -%>
Expand Down