Skip to content

Commit

Permalink
Fixes #104 vlan in device config
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Kapellen committed Nov 30, 2017
1 parent 106d300 commit 63dfaa4
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 17 deletions.
14 changes: 4 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,26 +247,21 @@ Static interface routes (host route):

Normal interface - VLAN - no IP:

class { 'network::global':
vlan => 'yes',
}

network::if { 'eth0.330':
ensure => 'up',
}
vlan => 'yes',
}

Normal interface - VLAN - static IPv4:

class { 'network::global':
vlan => 'yes',
}

network::if::static { 'eth0.330':
ensure => 'up',
ipaddress => '10.2.3.248',
netmask => '255.255.255.0',
vlan => 'yes',
}


Promiscuous interface:
To set a static or dynamic interface to promiscuous mode (RedHat only), add:
promisc => true
Expand Down Expand Up @@ -333,7 +328,6 @@ Notes
* It is assumed that if you create a bond that you also create the slave interface(s).
* It is assumed that if you create an alias that you also create the parent interface.
* network::route requires the referenced device to also be defined via network::if or network::bond.
* For VLANs to work, `Class['network::global']` must have parameter `vlan` set to `yes`.
* To enable IPv6 you have to set both `ipv6networking` in `Class['network::global']` to `true` and `ipv6init` in `network::if::static` to `true`.

Issues
Expand Down
7 changes: 3 additions & 4 deletions manifests/global.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# $ipv6defaultdev - optional - Determines the device to use as the default gateway
# for IPV6 traffic.
# $nisdomain - optional - Configures the NIS domainname.
# $vlan - optional - yes|no to enable VLAN kernel module
# $vlan - optional - 'yes' or 'no' [deprecated] use on device level
# $ipv6networking - optional - enables / disables IPv6 globally
# $nozeroconf - optional
# $restart - optional - defaults to true
Expand All @@ -43,7 +43,6 @@
# ipv6gateway => '123:4567:89ab:cdef:123:4567:89ab:1',
# ipv6defaultdev => 'eth0',
# nisdomain => 'domain.tld',
# vlan => 'yes',
# ipv6networking => true,
# nozeroconf => 'yes',
# requestreopen => false,
Expand All @@ -65,10 +64,10 @@
$hostname = undef,
$gateway = undef,
$gatewaydev = undef,
$vlan = undef,
$ipv6gateway = undef,
$ipv6defaultdev = undef,
$nisdomain = undef,
$vlan = undef,
$ipv6networking = false,
$nozeroconf = undef,
$restart = true,
Expand All @@ -85,7 +84,7 @@
validate_bool($ipv6networking)
validate_bool($restart)
validate_bool($requestreopen)

# Validate our regular expressions
if $vlan {
$states = [ '^yes$', '^no$' ]
Expand Down
9 changes: 9 additions & 0 deletions manifests/if/static.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
# $defroute - optional
# $restart - optional - defaults to true
# $arpcheck - optional - defaults to true
# $vlan - optional - yes|no defaults to no
#
# === Actions:
#
Expand Down Expand Up @@ -82,6 +83,7 @@
$metric = undef,
$restart = true,
$arpcheck = true,
$vlan = undef,
) {
# Validate our data
if $ipaddress {
Expand Down Expand Up @@ -119,6 +121,12 @@
validate_bool($flush)
validate_bool($arpcheck)

# Validate our regular expressions
if $vlan {
$states = [ '^yes$', '^no$' ]
validate_re($vlan, $states, '$vlan must be either "yes" or "no".')
}

network_if_base { $title:
ensure => $ensure,
ipv6init => $ipv6init,
Expand Down Expand Up @@ -148,5 +156,6 @@
metric => $metric,
restart => $restart,
arpcheck => $arpcheck,
vlan => $vlan,
}
} # define network::if::static
6 changes: 6 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
# $promisc - optional - defaults to false
# $restart - optional - defaults to true
# $arpcheck - optional - defaults to true
# $vlan - optional - defaults to 'no'
#
# === Actions:
#
Expand Down Expand Up @@ -140,6 +141,7 @@
$promisc = false,
$restart = true,
$arpcheck = true,
$vlan = undef,
) {
# Validate our booleans
validate_bool($noaliasrouting)
Expand All @@ -158,6 +160,10 @@
# Validate our regular expressions
$states = [ '^up$', '^down$' ]
validate_re($ensure, $states, '$ensure must be either "up" or "down".')
if($vlan) {
$vlanstates = [ '^yes$', '^no$' ]
validate_re($vlan, $vlanstates, '$vlan must be either "yes" or "no".')
}

include '::network'

Expand Down
4 changes: 2 additions & 2 deletions spec/classes/network_global_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@
}
end
end

context 'ipv6networking = foo' do
context 'ipv6networking = foo' do
let(:params) {{ :ipv6networking => 'foo' }}

it 'should fail' do
Expand Down
6 changes: 5 additions & 1 deletion spec/defines/network_if_static_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
:metric => '10',
:zone => 'trusted',
:arpcheck => false,
:vlan => 'yes',
}
end
let :facts do {
Expand Down Expand Up @@ -212,7 +213,8 @@
'DEFROUTE=yes',
'ZONE=trusted',
'METRIC=10',
'ARPCHECK=no',
'ARPCHECK=no',
'VLAN=yes',
'NM_CONTROLLED=no',
])
end
Expand All @@ -225,6 +227,7 @@
:ensure => 'up',
:ipaddress => '1.2.3.4',
:netmask => '255.255.255.0',
:vlan => 'yes',
}
end
let :facts do {
Expand All @@ -250,6 +253,7 @@
'TYPE=Ethernet',
'IPADDR=1.2.3.4',
'NETMASK=255.255.255.0',
'VLAN=yes',
'NM_CONTROLLED=no',
])
end
Expand Down
2 changes: 2 additions & 0 deletions templates/ifcfg-eth.erb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,6 @@ check_link_down() {
<% end -%>
<% if !@arpcheck %>ARPCHECK=no
<% end -%>
<% if @vlan %>VLAN=<%= @vlan %>
<% end -%>
NM_CONTROLLED=no

0 comments on commit 63dfaa4

Please sign in to comment.