diff --git a/manifests/iface.pp b/manifests/iface.pp index 48bcd16..f904124 100644 --- a/manifests/iface.pp +++ b/manifests/iface.pp @@ -1,324 +1,324 @@ # == Define: iface # # Resource to define an interface configuration stanza within interfaces(5). # # == Parameters # # [*ifname*] => *(namevar)* - string # Name of the interface to be configured. # # [*method*] - string # Configuration method to be used. Supported methods are: # * loopback # * dhcp # * static # * manual # * wvdial # # [*auto*] - bool # Sets the interface on automatic setup on startup. This is affected by # ifup -a and ifdown -a commands. # # [*allows*] - array # Adds an allow- entry to the interface stanza. # # [*family*] - string # Address family. Currently, only inet family is supported. Support for # inet6 is comming soon. # # [*order*] - int # Order of the entry to be created in /etc/network/interfaces. Innate # odering is preset with default value of 10 for loopback and 20 for dhcp # and static stanzas. The order attribute of the resource is added to the # default value. # # [*hwaddress*] - string # The MAC address of the interface. This value is validated as standard # IEEE MAC address of 6 bytes, written hexadecimal, delimited with # colons (:) or dashes (-). # # [*hostname*] - string # The hostname to be submitted with dhcp requests. # # [*leasetime*] - int # The requested leasetime of dhcp leases. # # [*vendor*] - string # The vendor id to be submitted with dhcp requests. # # [*client*] - string # The client id to be submitted with dhcp requests. # # [*metric*] - int # Routing metric for routes added resolved on this interface. # # [*address*] - string # IP address formatted as dotted-quad for IPv4. # # [*netmask*] - string # Netmask as dotted-quad or CIDR prefix length. # # [*broadcast*] - string # Broadcast address as dotted-quad or + or -. # # [*gateway*] - string # Default route to be brought up with this interface. # # [*pointopoint*] - stirng # Address of the ppp endpoint as dotted-quad. # # [*mtu*] - int # Size of the maximum transportable unit over this interface. # # [*scope*] - string # Scope of address validity. Values allowed are global, link or host. # # [*pre_ups*] - array # Array of commands to be run prior to bringing this interface up. # # [*ups*] - array # Array of commands to be run after bringing this interface up. # # [*downs*] - array # Array of commands to be run prior to bringing this interface down. # # [*post_downs*] - array # Array of commands to be run after bringing this interface down. # # [*aux_ops*] - hash # Hash of key-value pairs with auxiliary options for this interface. # To be used by other debnet types only. # # [*tx_queue*] - int # Feature helper for setting tx queue on the interface. # # [*routes*] - hash # Feature helper for setting static routes via the interface. # # [*dns_nameserver*] - array # Feature helper to add a list of nameservers to be configures via resolvconf # while the interface is set up. # # [*dns_search*] - array # Feature helper to add a list of domain names as dns search via resolvconf # while the interface is set up. # # === Authors # # Tibor Repasi # # === Copyright # # Copyright 2016 Tibor Repasi # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # define debnet::iface ( $method, $ifname = $title, $auto = true, $allows = [], $family = 'inet', $order = 0, $iface_d = undef, # options for multiple methods $metric = undef, $hwaddress = undef, # options for method dhcp $hostname = undef, $leasetime = undef, $vendor = undef, $client = undef, # options for method static $address = undef, $netmask = undef, $broadcast = undef, $gateway = undef, $pointopoint = undef, $mtu = undef, $scope = undef, # up and down commands $pre_ups = [], $ups = [], $downs = [], $post_downs = [], # auxiliary options $aux_ops = {}, # feature-helpers $tx_queue = undef, $routes = {}, $dns_nameservers = undef, $dns_search = undef, ) { include debnet validate_string($ifname) validate_bool($auto) validate_array($allows) validate_re($family, '^inet$' ) validate_re($method, '^loopback$|^dhcp$|^static$|^manual$|^wvdial$') validate_hash($aux_ops) validate_array($pre_ups) validate_array($ups) validate_array($downs) validate_array($post_downs) if $tx_queue { if is_string($tx_queue) { validate_re($tx_queue, '^\d+$') } else { validate_integer($tx_queue) } } if $routes { validate_hash($routes) } if $dns_nameservers { validate_array($dns_nameservers) } if $dns_search { validate_array($dns_search) } if $iface_d { - if $::lsbdistid == 'Debian' and $::lsbmajdistrelease < 8 { + if $::lsbdistid == 'Debian' and $::lsbmajdistrelease =~ /!^8.*/ { fail('This feature is not available prior to Debian release 8.') } validate_re($iface_d, '^[a-zA-Z][a-zA-Z0-9_]*$') $cfgtgt = "${debnet::params::interfaces_dir}/${iface_d}" } else { $cfgtgt = $debnet::params::interfaces_file } validate_absolute_path($cfgtgt) if !defined(Concat[$cfgtgt]) { concat { $cfgtgt: owner => 'root', group => 'root', mode => '0644', ensure_newline => true, order => 'numeric', } - concat::fragment { $debnet::params::interfaces_file: + concat::fragment { "${cfgtgt}_header": target => $cfgtgt, content => template('debnet/header.erb'), order => 10, } } case $method { 'loopback' : { concat::fragment { 'lo_stanza': target => $cfgtgt, content => template('debnet/loopback.erb'), order => 20 + $order, } } 'dhcp' : { if !defined(Package[$debnet::params::dhclient_pkg]) { package { $debnet::params::dhclient_pkg: ensure => 'installed', } } if $hostname { validate_re($hostname, '^(?![0-9]+$)(?!-)[a-zA-Z0-9-]{,63}(? $cfgtgt, content => template( 'debnet/iface_header.erb', 'debnet/inet_dhcp.erb', 'debnet/iface_aux.erb', 'debnet/iface_routes.erb'), order => 30 + $order, } } 'static' : { validate_re($address, '^(:?[0-9]{1,3}\.){3}[0-9]{1,3}$') if is_string($netmask) { validate_re($netmask, '^([0-9]{1,3}\.){3}[0-9]{1,3}$|^[0-9]{1,2}$') } else { validate_integer($netmask) } if $broadcast { validate_re($broadcast, '^([0-9]{1,3}\.){3}[0-9]{1,3}$|^[+-]$') } if $metric { validate_re($metric, '^\d+$') } if $gateway { validate_re($gateway, '(:?[0-9]{1,3}\.){3}[0-9]{1,3}$') } if $pointopoint { validate_re($pointopoint, '(:?[0-9]{1,3}\.){3}[0-9]{1,3}$') } if $hwaddress { validate_re($hwaddress, '^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$') } if $mtu { validate_re($mtu, '^\d+$') } if $scope { validate_re($scope, '^global$|^link$|^host$') } concat::fragment { "${ifname}_stanza": target => $cfgtgt, content => template( 'debnet/iface_header.erb', 'debnet/inet_static.erb', 'debnet/iface_aux.erb', 'debnet/iface_routes.erb'), order => 40 + $order, } } 'manual' : { concat::fragment { "${ifname}_stanza": target => $cfgtgt, content => template( 'debnet/iface_header.erb', 'debnet/inet_misc.erb', 'debnet/iface_aux.erb'), order => 50 + $order, } } 'wvdial' : { if !defined(Package[$debnet::params::wvdial_pkg]) { package { $debnet::params::wvdial_pkg: ensure => 'installed', } } concat::fragment { "${ifname}_stanza": target => $cfgtgt, content => template( 'debnet/iface_header.erb', 'debnet/inet_misc.erb', 'debnet/iface_aux.erb', 'debnet/iface_routes.erb'), order => 60 + $order, } } default: { err('unrecognized method') } } } diff --git a/manifests/iface/bond.pp b/manifests/iface/bond.pp index e0383e6..2e3a78c 100644 --- a/manifests/iface/bond.pp +++ b/manifests/iface/bond.pp @@ -1,284 +1,287 @@ # == Define: iface::bond # # Resource to define a bonding interface configuration stanza within # interfaces(5). # # == Parameters # # [*ifname*] => *(namevar)* - string # Name of the interface to be configured. # # [*method*] - string # Configuration method to be used. # # [*auto*] - bool # Sets the interface on automatic setup on startup. This is affected by # ifup -a and ifdown -a commands. # # [*allows*] - array # Adds an allow- entry to the interface stanza. # # [*family*] - string # Address family. Currently, only inet family is supported. Support for # inet6 is comming soon. # # [*order*] - int # Order of the entry to be created in /etc/network/interfaces. Innate # odering is preset with default value of 10 for loopback and 20 for dhcp # and static stanzas. The order attribute of the resource is added to the # default value. # # [*hwaddress*] - string # The MAC address of the interface. This value is validated as standard # IEEE MAC address of 6 bytes, written hexadecimal, delimited with # colons (:) or dashes (-). # # [*hostname*] - string # The hostname to be submitted with dhcp requests. # # [*leasetime*] - int # The requested leasetime of dhcp leases. # # [*vendor*] - string # The vendor id to be submitted with dhcp requests. # # [*client*] - string # The client id to be submitted with dhcp requests. # # [*metric*] - int # Routing metric for routes added resolved on this interface. # # [*address*] - string # IP address formatted as dotted-quad for IPv4. # # [*netmask*] - string # Netmask as dotted-quad or CIDR prefix length. # # [*broadcast*] - string # Broadcast address as dotted-quad or + or -. # # [*gateway*] - string # Default route to be brought up with this interface. # # [*pointopoint*] - stirng # Address of the ppp endpoint as dotted-quad. # # [*mtu*] - int # Size of the maximum transportable unit over this interface. # # [*scope*] - string # Scope of address validity. Values allowed are global, link or host. # # [*pre_ups*] - array # Array of commands to be run prior to bringing this interface up. # # [*ups*] - array # Array of commands to be run after bringing this interface up. # # [*downs*] - array # Array of commands to be run prior to bringing this interface down. # # [*post_downs*] - array # Array of commands to be run after bringing this interface down. # # [*aux_ops_*] - hash # Hash of key-value pairs with auxiliary options for this interface. # To be used by other debnet types only. # # [*aux_ops*] - hash # Hash of key-value pairs with auxiliary options for this interface. # To be used by other debnet types only. # # [*tx_queue*] - int # Feature helper for setting tx queue on the interface. # # [*routes*] - hash # Feature helper for setting static routes via the interface. # # [*dns_nameserver*] - array # Feature helper to add a list of nameservers to be configures via resolvconf # while the interface is set up. # # [*dns_search*] - array # Feature helper to add a list of domain names as dns search via resolvconf # while the interface is set up. # # === Authors # # Tibor Repasi # # === Copyright # # Copyright 2016 Tibor Repasi # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # define debnet::iface::bond( $method, $ifname = $title, $auto = true, $allows = [], $family = 'inet', $order = 0, + $iface_d = undef, # bond options $ports = [], $mode = 'active-backup', $miimon = 100, $use_carrier = true, $updelay = undef, $downdelay = undef, # options for multiple methods $metric = undef, $hwaddress = undef, # options for method dhcp $hostname = undef, $leasetime = undef, $vendor = undef, $client = undef, # options for method static $address = undef, $netmask = undef, $broadcast = undef, $gateway = undef, $pointopoint = undef, $mtu = undef, $scope = undef, # up and down commands $pre_ups = [], $ups = [], $downs = [], $post_downs = [], # auxiliary options $aux_ops_master = {}, $aux_ops_slaves = {}, # feature-helpers $tx_queue = undef, $routes = {}, $dns_nameservers = undef, $dns_search = undef, ) { include debnet if !defined(Package[$debnet::params::ifenslave_pkg]) { package { $debnet::params::ifenslave_pkg: ensure => 'installed', } } validate_array($ports) if size($ports) == 0 { fail('Bonding needs at least one port to be declared!') } # lint:ignore:80chars validate_re($mode, '^balance\-rr$|^active\-backup$|^balance\-xor$|^broadcast$|^802\.3ad$|^balance\-tlb$|^balance\-alb$') # lint:endignore if is_string($miimon) { validate_re($miimon, '^\d+$') } else { validate_integer($miimon) } $bondopts0 = { 'bond-slaves' => 'none', 'bond-primary' => $ports[1], 'bond-mode' => $mode, 'bond-miimon' => $miimon, } validate_bool($use_carrier) if $updelay { if is_string($updelay) { validate_re($updelay, '^\d+$') } else { validate_integer($updelay) } $bondopts1 = {'bond-updelay' => $updelay} } else { $bondopts1 = {} } if $downdelay { if is_string($downdelay) { validate_re($downdelay, '^\d+$') } else { validate_integer($downdelay) } $bondopts2 = {'bond-downdelay' => $downdelay} } else { $bondopts2 = {} } debnet::iface { $ports: method => 'manual', auto => $auto, allows => $allows, family => $family, order => 50 + $order, + iface_d => $iface_d, mtu => $mtu, pre_ups => $pre_ups, ups => $ups, downs => $downs, post_downs => $post_downs, aux_ops => merge( $aux_ops_slaves, { 'bond-master' => $ifname, 'bond-mode' => $mode, 'bond-primary' => $ports[1], } ), tx_queue => $tx_queue, } debnet::iface { $ifname: method => $method, auto => $auto, allows => $allows, family => $family, order => 60 + $order, + iface_d => $iface_d, metric => $metric, hwaddress => $hwaddress, hostname => $hostname, leasetime => $leasetime, vendor => $vendor, client => $client, address => $address, netmask => $netmask, broadcast => $broadcast, gateway => $gateway, pointopoint => $pointopoint, mtu => $mtu, scope => $scope, pre_ups => $pre_ups, ups => $ups, downs => $downs, post_downs => $post_downs, aux_ops => merge( $aux_ops_master, $bondopts0, $bondopts1, $bondopts2 ), tx_queue => $tx_queue, routes => $routes, dns_nameservers => $dns_nameservers, dns_search => $dns_search, } } \ No newline at end of file diff --git a/manifests/iface/bridge.pp b/manifests/iface/bridge.pp index 093808f..c3f1696 100644 --- a/manifests/iface/bridge.pp +++ b/manifests/iface/bridge.pp @@ -1,286 +1,288 @@ # == Define: iface::bridge # # Resource to define a bridge interface configuration stanza within # interfaces(5). # # == Parameters # # [*ifname*] => *(namevar)* - string # Name of the interface to be configured. # # [*method*] - string # Configuration method to be used. # # [*auto*] - bool # Sets the interface on automatic setup on startup. This is affected by # ifup -a and ifdown -a commands. # # [*allows*] - array # Adds an allow- entry to the interface stanza. # # [*family*] - string # Address family. Currently, only inet family is supported. Support for # inet6 is comming soon. # # [*order*] - int # Order of the entry to be created in /etc/network/interfaces. Innate # odering is preset with default value of 10 for loopback and 20 for dhcp # and static stanzas. The order attribute of the resource is added to the # default value. # # [*hwaddress*] - string # The MAC address of the interface. This value is validated as standard # IEEE MAC address of 6 bytes, written hexadecimal, delimited with # colons (:) or dashes (-). # # [*hostname*] - string # The hostname to be submitted with dhcp requests. # # [*leasetime*] - int # The requested leasetime of dhcp leases. # # [*vendor*] - string # The vendor id to be submitted with dhcp requests. # # [*client*] - string # The client id to be submitted with dhcp requests. # # [*metric*] - int # Routing metric for routes added resolved on this interface. # # [*address*] - string # IP address formatted as dotted-quad for IPv4. # # [*netmask*] - string # Netmask as dotted-quad or CIDR prefix length. # # [*broadcast*] - string # Broadcast address as dotted-quad or + or -. # # [*gateway*] - string # Default route to be brought up with this interface. # # [*pointopoint*] - stirng # Address of the ppp endpoint as dotted-quad. # # [*mtu*] - int # Size of the maximum transportable unit over this interface. # # [*scope*] - string # Scope of address validity. Values allowed are global, link or host. # # [*ports*] - array # Array of ports to be added to the bridge. # # [*stp*] - bool # Sets if bridge should implement spanning tree protocol. # # [*prio*] - int # Priority of the bridge for root selection within spanning tree. # # [*fwdelay*] - int # Sets the forward delay of the bridge in seconds. # # [*hello*] - int # Sets the bridge hello time in seconds. # # [*maxage*] - int # Maximum seconds of age of STP message. # # [*maxwait*] - int # Maximum seconds to wait for bridge interfaces to come up. # # [*pre_ups*] - array # Array of commands to be run prior to bringing this interface up. # # [*ups*] - array # Array of commands to be run after bringing this interface up. # # [*downs*] - array # Array of commands to be run prior to bringing this interface down. # # [*post_downs*] - array # Array of commands to be run after bringing this interface down. # # [*aux_ops*] - hash # Hash of key-value pairs with auxiliary options for this interface. # To be used by other debnet types only. # # [*tx_queue*] - int # Feature helper for setting tx queue on the interface. # # [*routes*] - hash # Feature helper for setting static routes via the interface. # # [*dns_nameserver*] - array # Feature helper to add a list of nameservers to be configures via resolvconf # while the interface is set up. # # [*dns_search*] - array # Feature helper to add a list of domain names as dns search via resolvconf # while the interface is set up. # # === Authors # # Tibor Repasi # # === Copyright # # Copyright 2016 Tibor Repasi # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # define debnet::iface::bridge( $method, $ifname = $title, $auto = true, $allows = [], $family = 'inet', $order = 0, + $iface_d = undef, # bridge options $ports = [], $stp = false, $prio = undef, $fwdelay = undef, $hello = undef, $maxage = undef, $maxwait = undef, # options for multiple methods $metric = undef, $hwaddress = undef, # options for method dhcp $hostname = undef, $leasetime = undef, $vendor = undef, $client = undef, # options for method static $address = undef, $netmask = undef, $broadcast = undef, $gateway = undef, $pointopoint = undef, $mtu = undef, $scope = undef, # up and down commands $pre_ups = [], $ups = [], $downs = [], $post_downs = [], # auxiliary options $aux_ops = {}, # feature-helpers $tx_queue = undef, $routes = {}, $dns_nameservers = undef, $dns_search = undef, ) { include debnet if !defined(Package[$debnet::params::bridge_utils_pkg]) { package { $debnet::params::bridge_utils_pkg: ensure => 'installed', } } if size($ports) > 0 { $brports = join($ports, ' ') debnet::iface { $ports: method => 'manual', tx_queue => $tx_queue, } } else { $brports = 'none' } $bropts0 = {'bridge_ports' => $brports} if $hwaddress { $bropts1 = {'bridge_hw' => $hwaddress} } else { $bropts1 = {} } $bropts2 = {'bridge_stp' => $stp ? { true => 'on', default => 'off'} } if $stp { if $prio { validate_re($prio, '^\d+$') $bropts3 = { 'bridge_bridgeprio' => $prio} } else { $bropts3 = {} } if $fwdelay { validate_re($fwdelay, '^\d+$') $bropts4 = { 'bridge_fd' => $fwdelay } } else { $bropts4 = {} } if $hello { validate_re($hello, '^\d+$') $bropts5 = { 'bridge_hello' => $hello } } else { $bropts5 = {} } if $maxage { validate_re($maxage, '^\d+$') $bropts6 = { 'bridge_maxage' => $maxage } } else { $bropts6 = {} } if $maxwait { validate_re($maxwait, '^\d+$') $bropts7 = { 'bridge_maxwait' => $maxwait } } else { $bropts7 = {} } } debnet::iface { $ifname: method => $method, auto => $auto, allows => $allows, family => $family, order => $order, + iface_d => $iface_d, metric => $metric, hostname => $hostname, leasetime => $leasetime, vendor => $vendor, client => $client, address => $address, netmask => $netmask, broadcast => $broadcast, gateway => $gateway, pointopoint => $pointopoint, mtu => $mtu, scope => $scope, pre_ups => $pre_ups, ups => $ups, downs => $downs, post_downs => $post_downs, aux_ops => merge( $aux_ops, $bropts0, $bropts1, $bropts2, $bropts3, $bropts4, $bropts5, $bropts6, $bropts7), routes => $routes, dns_nameservers => $dns_nameservers, dns_search => $dns_search, } } \ No newline at end of file diff --git a/manifests/iface/dhcp.pp b/manifests/iface/dhcp.pp index 06cc60a..270fd6f 100644 --- a/manifests/iface/dhcp.pp +++ b/manifests/iface/dhcp.pp @@ -1,155 +1,160 @@ # == Define: iface::dhcp # # Resource to define an interface configuration stanza within interfaces(5). # # == Parameters # # [*ifname*] => *(namevar)* - string # Name of the interface to be configured. # # [*method*] - string # Configuration method to be used. # # [*auto*] - bool # Sets the interface on automatic setup on startup. This is affected by # ifup -a and ifdown -a commands. # # [*allows*] - array # Adds an allow- entry to the interface stanza. # # [*family*] - string # Address family. Currently, only inet family is supported. Support for # inet6 is comming soon. # # [*order*] - int # Order of the entry to be created in /etc/network/interfaces. Innate # odering is preset with default value of 10 for loopback and 20 for dhcp # and static stanzas. The order attribute of the resource is added to the # default value. # # [*hwaddress*] - string # The MAC address of the interface. This value is validated as standard # IEEE MAC address of 6 bytes, written hexadecimal, delimited with # colons (:) or dashes (-). # # [*hostname*] - string # The hostname to be submitted with dhcp requests. # # [*leasetime*] - int # The requested leasetime of dhcp leases. # # [*vendor*] - string # The vendor id to be submitted with dhcp requests. # # [*client*] - string # The client id to be submitted with dhcp requests. # # [*metric*] - int # Routing metric for routes added resolved on this interface. # # [*pre_ups*] - array # Array of commands to be run prior to bringing this interface up. # # [*ups*] - array # Array of commands to be run after bringing this interface up. # # [*downs*] - array # Array of commands to be run prior to bringing this interface down. # # [*post_downs*] - array # Array of commands to be run after bringing this interface down. # # [*aux_ops*] - hash # Hash of key-value pairs with auxiliary options for this interface. # To be used by other debnet types only. # # [*tx_queue*] - int # Feature helper for setting tx queue on the interface. # # [*routes*] - hash # Feature helper for setting static routes via the interface. # # [*dns_nameserver*] - array # Feature helper to add a list of nameservers to be configures via resolvconf # while the interface is set up. # # [*dns_search*] - array # Feature helper to add a list of domain names as dns search via resolvconf # while the interface is set up. # # === Authors # # Tibor Repasi # # === Copyright # # Copyright 2016 Tibor Repasi # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # define debnet::iface::dhcp ( $ifname = $title, $auto = true, $allows = [], $family = 'inet', $order = 0, + $iface_d = undef, $metric = undef, $hwaddress = undef, $hostname = undef, $leasetime = undef, $vendor = undef, $client = undef, # up and down commands $pre_ups = [], $ups = [], $downs = [], $post_downs = [], # auxiliary options $aux_ops = {}, # feature-helpers $tx_queue = undef, $routes = {}, $dns_nameservers = undef, $dns_search = undef, ) { include debnet validate_string($ifname) validate_bool($auto) validate_array($allows) validate_re($family, '^inet$' ) debnet::iface { $ifname : method => 'dhcp', auto => $auto, + allows => $allows, + family => $family, + order => $order, + iface_d => $iface_d, hostname => $hostname, metric => $metric, leasetime => $leasetime, vendor => $vendor, client => $client, hwaddress => $hwaddress, pre_ups => $pre_ups, ups => $ups, downs => $downs, post_downs => $post_downs, aux_ops => $aux_ops, tx_queue => $tx_queue, routes => $routes, dns_nameservers => $dns_nameservers, dns_search => $dns_search, } } diff --git a/manifests/iface/loopback.pp b/manifests/iface/loopback.pp index 6d7e807..fc1668a 100644 --- a/manifests/iface/loopback.pp +++ b/manifests/iface/loopback.pp @@ -1,86 +1,89 @@ # == Define: iface::loopback # # Resource to define an loopback interface stanza within interfaces(5). # # == Parameters # # [*ifname*] => *(namevar)* - string # Must conventionally always be 'lo'. # # [*auto*] - bool # Sets the interface on automatic setup on startup. This is affected by # ifup -a and ifdown -a commands. # # [*allows*] - array # Adds an allow- entry to the interface stanza. # # [*pre_ups*] - array # Array of commands to be run prior to bringing this interface up. # # [*ups*] - array # Array of commands to be run after bringing this interface up. # # [*downs*] - array # Array of commands to be run prior to bringing this interface down. # # [*post_downs*] - array # Array of commands to be run after bringing this interface down. # # [*aux_ops*] - hash # Hash of key-value pairs with auxiliary options for this interface. # To be used by other debnet types only. # # === Authors # # Tibor Repasi # # === Copyright # # Copyright 2016 Tibor Repasi # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # define debnet::iface::loopback ( $ifname = $title, $auto = true, $allows = [], $family = 'inet', $order = 0, + $iface_d = undef, # up and down commands $pre_ups = [], $ups = [], $downs = [], $post_downs = [], # auxiliary options $aux_ops = {}, ) { include debnet validate_re($ifname, '^lo$') validate_bool($auto) validate_array($allows) validate_re($family, '^inet$' ) debnet::iface { $ifname: method => 'loopback', auto => $auto, allows => $allows, family => $family, + order => $order, + iface_d => $iface_d, pre_ups => $pre_ups, ups => $ups, downs => $downs, post_downs => $post_downs, aux_ops => $aux_ops, } } diff --git a/manifests/iface/static.pp b/manifests/iface/static.pp index 3a91f73..2626ca4 100644 --- a/manifests/iface/static.pp +++ b/manifests/iface/static.pp @@ -1,173 +1,174 @@ # == Define: iface::static # # Resource to define simple interface with static configuration stanza within # interfaces(5). # # == Parameters # # [*ifname*] => *(namevar)* - string # Name of the interface to be configured. # # [*auto*] - bool # Sets the interface on automatic setup on startup. This is affected by # ifup -a and ifdown -a commands. # # [*allows*] - array # Adds an allow- entry to the interface stanza. # # [*family*] - string # Address family. Currently, only inet family is supported. Support for # inet6 is comming soon. # # [*order*] - int # Order of the entry to be created in /etc/network/interfaces. Innate # odering is preset with default value of 10 for loopback and 20 for dhcp # and static stanzas. The order attribute of the resource is added to the # default value. # # [*address*] - string # IP address formatted as dotted-quad for IPv4. # # [*netmask*] - string # Netmask as dotted-quad or CIDR prefix length. # # [*broadcast*] - string # Broadcast address as dotted-quad or + or -. # # [*gateway*] - string # Default route to be brought up with this interface. # # [*metric*] - int # Routing metric for routes added resolved on this interface. # # [*pointopoint*] - stirng # Address of the ppp endpoint as dotted-quad. # # [*mtu*] - int # Size of the maximum transportable unit over this interface. # # [*scope*] - string # Scope of address validity. Values allowed are global, link or host. # # [*hwaddress*] - string # The MAC address of the interface. This value is validated as standard # IEEE MAC address of 6 bytes, written hexadecimal, delimited with # colons (:) or dashes (-). # # [*pre_ups*] - array # Array of commands to be run prior to bringing this interface up. # # [*ups*] - array # Array of commands to be run after bringing this interface up. # # [*downs*] - array # Array of commands to be run prior to bringing this interface down. # # [*post_downs*] - array # Array of commands to be run after bringing this interface down. # # [*aux_ops*] - hash # Hash of key-value pairs with auxiliary options for this interface. # To be used by other debnet types only. # # [*tx_queue*] - int # Feature helper for setting tx queue on the interface. # # [*routes*] - hash # Feature helper for setting static routes via the interface. # # [*dns_nameserver*] - array # Feature helper to add a list of nameservers to be configures via resolvconf # while the interface is set up. # # [*dns_search*] - array # Feature helper to add a list of domain names as dns search via resolvconf # while the interface is set up. # # === Authors # # Tibor Repasi # # === Copyright # # Copyright 2016 Tibor Repasi # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # define debnet::iface::static ( $address, $netmask, $ifname = $title, $auto = true, $allows = [], $family = 'inet', $order = 0, + $iface_d = undef, $broadcast = undef, $metric = undef, $gateway = undef, $pointopoint = undef, $hwaddress = undef, $mtu = undef, $scope = undef, # up and down commands $pre_ups = [], $ups = [], $downs = [], $post_downs = [], # auxiliary options $aux_ops = {}, # feature-helpers $tx_queue = undef, $routes = {}, $dns_nameservers = undef, $dns_search = undef, ) { include debnet validate_string($ifname) validate_bool($auto) validate_array($allows) validate_re($family, '^inet$' ) debnet::iface { $ifname: method => 'static', auto => $auto, allows => $allows, family => $family, order => $order, + iface_d => $iface_d, address => $address, netmask => $netmask, broadcast => $broadcast, metric => $metric, gateway => $gateway, pointopoint => $pointopoint, hwaddress => $hwaddress, mtu => $mtu, scope => $scope, pre_ups => $pre_ups, ups => $ups, downs => $downs, post_downs => $post_downs, aux_ops => $aux_ops, tx_queue => $tx_queue, routes => $routes, dns_nameservers => $dns_nameservers, dns_search => $dns_search, - } } diff --git a/spec/defines/iface_spec.rb b/spec/defines/iface_spec.rb index 38b9852..84e1942 100644 --- a/spec/defines/iface_spec.rb +++ b/spec/defines/iface_spec.rb @@ -1,49 +1,85 @@ require 'spec_helper' describe 'debnet::iface' do let(:title) { 'eth0' } let(:facts) {{ :concat_basedir => '/var/lib/puppet/concat', :osfamily => 'Debian', }} context "Non-Debian system" do let(:facts) {{ :osfamily => 'RedHat', }} it { expect { should raise_error(Puppet::Error) } } end context 'eth0 with address and mask' do let(:params) {{ :method => 'static', :address => '192.168.254.253', :netmask => '24', }} it { should contain_concat('/etc/network/interfaces').with({ 'owner' => 'root', 'group' => 'root', 'mode' => '0644', 'ensure_newline' => true, 'order' => 'numeric', }) - should contain_concat__fragment('/etc/network/interfaces').with({ + should contain_concat__fragment('/etc/network/interfaces_header').with({ 'target' => '/etc/network/interfaces', 'order' => '10', }) - should contain_concat__fragment('/etc/network/interfaces') \ + should contain_concat__fragment('/etc/network/interfaces_header') \ .with_content(/controlled by Puppet module trepasi-debnet/) should contain_concat__fragment('eth0_stanza').with({ 'target' => '/etc/network/interfaces', }) should contain_concat__fragment('eth0_stanza') \ .with_content(/^# interface eth0 configuration/) should contain_concat__fragment('eth0_stanza') \ .with_content(/^iface eth0 inet static/) } end + context 'eth0 with address and mask at different location' do + let(:facts) {{ + :concat_basedir => '/var/lib/puppet/concat', + :osfamily => 'Debian', + :lsbmajdistrelease => '8' + }} + let(:params) {{ + :method => 'static', + :iface_d => 'test', + :address => '192.168.254.253', + :netmask => '24', + }} + it { + should contain_concat('/etc/network/interfaces.d/test').with({ + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'ensure_newline' => true, + 'order' => 'numeric', + }) + should contain_concat__fragment('/etc/network/interfaces.d/test_header').with({ + 'target' => '/etc/network/interfaces.d/test', + 'order' => '10', + }) + should contain_concat__fragment('/etc/network/interfaces.d/test_header') \ + .with_content(/controlled by Puppet module trepasi-debnet/) + should contain_concat__fragment('eth0_stanza').with({ + 'target' => '/etc/network/interfaces.d/test', + }) + should contain_concat__fragment('eth0_stanza') \ + .with_content(/^# interface eth0 configuration/) + should contain_concat__fragment('eth0_stanza') \ + .with_content(/^iface eth0 inet static/) + } + end + end diff --git a/spec/defines/static_spec.rb b/spec/defines/static_spec.rb index 4ad5aa5..35b0daf 100644 --- a/spec/defines/static_spec.rb +++ b/spec/defines/static_spec.rb @@ -1,24 +1,41 @@ require 'spec_helper' describe 'debnet::iface::static' do let(:title) { 'eth0' } let(:facts) {{ :concat_basedir => '/var/lib/puppet/concat', :osfamily => 'Debian', }} context 'eth0 with address and mask' do let(:params) {{ :address => '192.168.254.253', :netmask => '24', }} it { should contain_debnet__iface('eth0').with({ 'method' => 'static', 'family' => 'inet', 'address' => '192.168.254.253', 'netmask' => '24', }) } end + + context 'eth0 with address and mask on different location' do + let(:params) {{ + :address => '192.168.254.253', + :netmask => '24', + :iface_d => 'test', + }} + it { + should contain_debnet__iface('eth0').with({ + 'method' => 'static', + 'family' => 'inet', + 'iface_d' => 'test', + 'address' => '192.168.254.253', + 'netmask' => '24', + }) + } + end end