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

Substantial refactor #18

Open
wants to merge 5 commits into
base: master
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
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Copyright (C) 2011 Mike Arnold <[email protected]>
Copyright (C) 2013 Garrett Honeycutt <[email protected]>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
TODO
====

1. Change definition network_if_base $ensure to also take "absent" as a
1. Change definition network::if::base $ensure to also take "absent" as a
parameter. This should remove all traces of the ifconfig file from the system
and remove the interface.

Expand Down
2 changes: 1 addition & 1 deletion manifests/bond/alias.pp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# Validate our data
if ! is_ip_address($ipaddress) { fail("${ipaddress} is not an IP address.") }

network_if_base { $title:
network::if::base { $title:
ensure => $ensure,
ipaddress => $ipaddress,
netmask => $netmask,
Expand Down
2 changes: 1 addition & 1 deletion manifests/bond/dynamic.pp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
$states = [ '^up$', '^down$' ]
validate_re($ensure, $states, '$ensure must be either "up" or "down".')

network_if_base { $title:
network::if::base { $title:
ensure => $ensure,
ipaddress => '',
netmask => '',
Expand Down
9 changes: 6 additions & 3 deletions manifests/bond/slave.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
define network::bond::slave (
$macaddress,
$master,
$ethtool_opts = ''
$ethtool_opts = '',
) {

# Validate our data
if ! is_mac_address($macaddress) { fail("${macaddress} is not a MAC address.") }
if ! is_mac_address($macaddress) {
fail("${macaddress} is not a MAC address.")
}

$interface = $name

Expand All @@ -39,4 +42,4 @@
# TODO: need to know $ensure since one of these execs is not defined.
#notify => [ Exec["ifup-${master}"], Exec["ifdown-${master}"], ],
}
} # define network::bond::slave
}
13 changes: 8 additions & 5 deletions manifests/bond/static.pp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@
$domain = ''
) {
# Validate our regular expressions
$states = [ '^up$', '^down$' ]
validate_re($ensure, $states, '$ensure must be either "up" or "down".')
$states_re = [ '^up$', '^down$' ]
validate_re($ensure, $states_re, "network::bond::static::${name} ensure is <${ensure}> and must be either \'up\' or \'down\'.")

# Validate our data
if ! is_ip_address($ipaddress) { fail("${ipaddress} is not an IP address.") }
if ! is_ip_address($ipaddress) {
fail("${ipaddress} is not an IP address.")
}

network_if_base { $title:
network::if::base { $title:
ensure => $ensure,
ipaddress => $ipaddress,
netmask => $netmask,
Expand Down Expand Up @@ -76,4 +79,4 @@
#onlyif => 'match */modulename[. = 'bonding'] size == 0',
before => $ifstate
}
} # define network::bond::static
}
7 changes: 4 additions & 3 deletions manifests/if/alias.pp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@
$peerdns = false, # TODO: strip this out like in network::bond::alias?
$dns1 = '',
$dns2 = '',
$domain = ''
$domain = '',
) {

# Validate our data
if ! is_ip_address($ipaddress) { fail("${ipaddress} is not an IP address.") }

network_if_base { $title:
network::if::base { $title:
ensure => $ensure,
ipaddress => $ipaddress,
netmask => $netmask,
Expand All @@ -54,4 +55,4 @@
dns2 => $dns2,
domain => $domain,
}
} # define network::if::alias
}
131 changes: 131 additions & 0 deletions manifests/if/base.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# == Definition: network::if::base
#
# This definition is private, i.e. it is not intended to be called directly
# by users. It can be used to write out the following device files:
# /etc/sysconfig/networking-scripts/ifcfg-eth
# /etc/sysconfig/networking-scripts/ifcfg-eth:alias
# /etc/sysconfig/networking-scripts/ifcfg-bond(master)
#
# Parameters:
# $ensure - required - up|down
# $ipaddress - required
# $netmask - required
# $macaddress - required
# $gateway - optional
# $bootproto - optional
# $mtu - optional
# $ethtool_opts - optional
# $bonding_opts - optional
# $isalias - optional
# $peerdns - optional
# $dns1 - optional
# $dns2 - optional
# $domain - optional
#
# Actions:
# Performs 'ifup/ifdown $name' after any changes to the ifcfg file.
#
# Requires:
#
# Sample Usage:
#
# TODO:
# METRIC=
# HOTPLUG=yes|no
# USERCTL=yes|no
# WINDOW=
# SCOPE=
# SRCADDR=
# NOZEROCONF=yes
# PERSISTENT_DHCLIENT=yes|no|1|0
# DHCPRELEASE=yes|no|1|0
# DHCLIENT_IGNORE_GATEWAY=yes|no|1|0
# LINKDELAY=
# REORDER_HDR=yes|no
#
define network::if::base (
$ensure,
$ipaddress,
$netmask,
$macaddress,
$gateway = '',
$bootproto = 'none',
$mtu = '',
$ethtool_opts = '',
$bonding_opts = '',
$isalias = false,
$peerdns = false,
$dns1 = '',
$dns2 = '',
$domain = '',
) {

# Validate our booleans
validate_bool($isalias)
validate_bool($peerdns)
# Validate our regular expressions
$states = [ '^up$', '^down$' ]
validate_re($ensure, $states, '$ensure must be either "up" or "down".')

$interface = $name

# Deal with the case where $dns2 is non-empty and $dns1 is empty.
if $dns2 != '' {
if $dns1 == '' {
$dns1_real = $dns2
$dns2_real = ''
} else {
$dns1_real = $dns1
$dns2_real = $dns2
}
} else {
$dns1_real = $dns1
$dns2_real = $dns2
}

if $isalias {
$onparent = $ensure ? {
'up' => 'yes',
'down' => 'no',
default => undef,
}
$iftemplate = template('network/ifcfg-alias.erb')
} else {
$onboot = $ensure ? {
'up' => 'yes',
'down' => 'no',
default => undef,
}
$iftemplate = template('network/ifcfg-eth.erb')
}

file { "ifcfg-${interface}":
ensure => 'present',
mode => '0644',
owner => 'root',
group => 'root',
path => "/etc/sysconfig/network-scripts/ifcfg-${interface}",
content => $iftemplate,
}

case $ensure {
'up': {
exec { "ifup-${interface}":
command => "/sbin/ifdown ${interface}; /sbin/ifup ${interface}",
subscribe => File["ifcfg-${interface}"],
refreshonly => true,
}
}

'down': {
exec { "ifdown-${interface}":
command => "/sbin/ifdown ${interface}",
subscribe => File["ifcfg-${interface}"],
refreshonly => true,
}
}
default: {
fail("network::if::base::${name}::ensure is <${ensure}> and must be \'up\' or \'down\'.")
}
}
}
7 changes: 4 additions & 3 deletions manifests/if/dynamic.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
$macaddress = '',
$bootproto = 'dhcp',
$mtu = '',
$ethtool_opts = ''
$ethtool_opts = '',
) {

# Validate our regular expressions
$states = [ '^up$', '^down$' ]
validate_re($ensure, $states, '$ensure must be either "up" or "down".')
Expand All @@ -44,7 +45,7 @@
$macaddy = $macaddress
}

network_if_base { $title:
network::if::base { $title:
ensure => $ensure,
ipaddress => '',
netmask => '',
Expand All @@ -55,4 +56,4 @@
ethtool_opts => $ethtool_opts,
bonding_opts => '',
}
} # define network::if::dynamic
}
14 changes: 9 additions & 5 deletions manifests/if/static.pp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#
define network::if::static (
$ensure,
$bootproto = 'static',
$ipaddress,
$netmask,
$gateway = '',
Expand All @@ -40,24 +41,27 @@
$peerdns = false,
$dns1 = '',
$dns2 = '',
$domain = ''
$domain = '',
) {

# Validate our data
if ! is_ip_address($ipaddress) { fail("${ipaddress} is not an IP address.") }
if ! is_ip_address($ipaddress) {
fail("${ipaddress} is not an IP address.")
}

if ! is_mac_address($macaddress) {
$macaddy = getvar("::macaddress_${title}")
} else {
$macaddy = $macaddress
}

network_if_base { $title:
network::if::base { $title:
ensure => $ensure,
ipaddress => $ipaddress,
netmask => $netmask,
gateway => $gateway,
macaddress => $macaddy,
bootproto => 'none',
bootproto => $bootproto,
mtu => $mtu,
ethtool_opts => $ethtool_opts,
bonding_opts => '',
Expand All @@ -66,4 +70,4 @@
dns2 => $dns2,
domain => $domain,
}
} # define network::if::static
}
Loading