diff --git a/README.markdown b/README.markdown index ea3594e..04d2935 100644 --- a/README.markdown +++ b/README.markdown @@ -1,311 +1,312 @@ # debnet # [![Build Status](https://travis-ci.org/rtib/tib-debnet.svg?branch=master)](https://travis-ci.org/rtib/tib-debnet) ####Table of Contents 1. [Overview](#overview) 2. [Module Description - What the module does](#module-description) 3. [Setup - Basic usage of module debnet](#setup) * [Beginning with the module](#beginning-with-the-module) * [Available configuration methods](#available-configuration-methods) * [Configuring the loopback interface](#configuring-the-loopback-interface) * [Static IPv4 configuration](#static-ipv4-interface-configuration) * [DHCP configuration](#dhcp-configuration) * [Common attributes](#common-attributes) 4. [Advanced configuration methods](#advanced-configuration-methods) * [Raw interface configuration](#Raw-interface-configuration) * [Bridge configuration](#bridge-configuration) * [Bonding configuration](#bonding-configuration) * [Using Up and down command hooks](#using-up-and-down-command-hooks) 5. [Feature helpers](#feature-helpers) * [Queue length](#queue-length) * [Static routes](#static-routes) * [DNS resolver settings](#dns-resolver-settings) ##Overview This module constructs the ```/etc/network/interfaces``` file on Debian based Linux distributions and enables an easy configuration of sophisticated network setups, such as bridges and bonding configurations. ##Module Description This module lets you use many ```debnet::iface``` resourses for setting up network interfaces. ##Setup Declaring a single resource of this module will cause debnet to take control over the file ```/etc/network/interfaces``` which than will contain stanzas generated by the module only. Every declaration of ```debnet::iface``` resources will create a corresponding stanza in ```/etc/network/interfaces```. ###Beginning with the module To start with the debnet module the node can simply declare resources. Many nodes need at least a loopback interface which might look like: ```puppet debnet::iface::loopback { 'lo': } ``` Many other declaration may follow. Each of which will create an interface configuration. There are specialized resources available for many kind of configuration tasks, however, you may also use the simple ```debnet::iface``` resource to create generic interface stanzas. Be aware, that the specialized resources do some more validation, which makes the configuration less error prone. ###Available configuration methods The resource ```debnet::iface``` implements different configuration methods also available for the interfaces(5) stanzas. Currently supported methods are: * loopback * static * dhcp * manual +* wvdial ###Configuring the loopback interface Currently there is only a single way to create a configuration on the loopback interface. ```puppet debnet::iface::loopback { 'lo': } ``` ###Static IPv4 interface configuration For a static IP configuration the attributes address and netmask are mandatory. Attributes broadcast, gateway, pointopoint, hwaddress, mtu and scope are optional. ```puppet debnet::iface::static { 'eth0': address => '192.168.0.10', netmask => 24, gateway => '192.168.0.1', } ``` Available attributes: * ```ifname``` - (string) iface name (default: ```title```) * ```address``` - (dotted-quad) static address (mandatory) * ```netmask``` - (int or dotted-quad) netmask (mandatory) * ```broadcast``` - (dotted-quad) broadcast address (optional) * ```metric``` - (int) metric for routing protocols * ```gateway``` - (dotted-quad) gateway to set default route * ```pointopoint``` - (dotted-quad) point-to-point address * ```hwaddress``` - (macaddress) hardware address to override with * ```mtu``` - (int) interface MTU * ```scope``` - (string) address scope ###DHCP configuration Configuring an interface by dhcp is enabled through method set to according. Optional attributes hostname, metric, leasetime, vendor, client and hwaddress may be set. ```puppet debnet::iface::dhcp { 'eth0': } ``` Available attributes: * ```ifname``` - (string) iface name (default: ```$title```) * ```metric``` - (int) metric for routing protocols * ```hwaddress``` - (macaddress) hardware address to override with (optional) * ```hostname``` - (string) hostname to send with DHCP REQUEST (optional) * ```leasetime``` - (int) leasetime to request (optional) * ```vendor``` - (string) vendor id to send with request (optional) * ```client``` - (string) client id to send with request (optional) ###Common attributes Many resource types have some common attributes. These are: * ```auto``` - (bool) allow auto-bring-up interface (default: true) * ```allows``` - (array) allows-* features (default: []) * ```family``` - (string) only inet supported (default: inet) * ```order``` - (int) ordering of the resource (default: 0) ##Advanced configuration methods The module also gives a convenient way to declare more sofisticated network configurations like bonding of multiple interfaces or creating bridge devices. To leaverage from these it is necessary to learn how raw configuration of interfaces work by usage of ```debnet::iface``` type resource. This will allow the declaration of bonded interfaces through ```debnet::iface::bond``` and bridges through ```debnet::iface::bridge```. ###Raw interface configuration Using the specialised resources is convenient but not feasable in some circumstances. Therefore it might be necessery, however, to create configurations using the ```debnet::iface``` generic resource type. The above examples can be alternatively configured by using ```debnet::iface``` type as follows: Loopback interface: ```puppet debnet::iface { 'lo': method => 'loopback', } ``` Static interface: ```puppet debnet::iface { 'eth0': method => 'static', address => '192.168.0.10', netmask => 24, gateway => '192.168.0.1', } ``` DHCP configuration: ```puppet debnet::iface { 'eth0': method => 'dhcp', } ``` ###Bridge configuration Configuring a software bridge is enabled by declaring a resource of type ```debnet::iface::bridge```. Mandatory attribute is the method of configuration of the bridge interface. Depending on the method, the mandatory attributes of the choosen method are also mandatory for the bridge resource. Optional attributes are ports, stp, prio, fwdelay and hello. To simply bridge two devices without bringing them up on layer-3, e.g.: ```puppet debnet::iface::bridge { 'br0': ports => ['eth1','eth2'], stp => true, method => 'manual', } ``` The ```debnet::iface::bridge``` resource is defining interfaces for each port of the bridge with manual configuration to inhibit multiple use of the same interface. Available attributes: * ```method``` - (string) interface configuration method (mandatory) * ```ifname``` - (string) iface name (default: ```$title```) * ```ports``` - (array) ports to be added (default: ```[]```) * ```stp``` - (bool) enable IEEE 802.1d spanning tree protocol (default: false) * ```prio``` - (int) STP bridge priority (optional) * ```fwdelay``` - (int) forward delay (optional) * ```hello``` - (int) hello timing (optional) * ```maxage``` - (int) max BPDU age (optional) * ```maxwait``` - (int) max seconds to wait for ports to come up (optional) ###Bonding configuration The module allows to bond multiple interfaces together by configuring a linux bonding device. The following example will bond devices ```eth1``` and ```eth2``` as active-passive slaves of ```bond0```, and will bring up the layer-3 config with static address and gateway settings. ```puppet debnet::iface::bond { 'bond0': ports => ['eth1', 'eth2'], method => 'static', address => '192.168.0.10', netmask => 24, gateway => '192.168.0.1', } ``` Supported bonding modes are: balance-rr, active-backup, balance-xor, broadcast, 802.3ad, balance-tlb, balance-alb. Available attributes: * ```ports``` - (array) slave interfaces (mandatory) * ```mode``` - (string) bonding mode (default: active-backup) * ```miimon``` - (int) mii monitor timing (default: 100) * ```use_carrier``` - (bool) enable carrier sense (default: true) * ```updelay``` - (int) setting the updelay timer (optional) * ```downdelay``` - (int) setting the downdelay timer (optional) Such a configuration will create the interfaces(5) stanzas for many ports and the bonding device. The array in argument ports must have at least one item, and the first item will be configured as bond-primary. ###Using Up and down command hooks In many resources of the module you may use attributes ```ups```, ```downs```, ```pre-ups``` and ```post-downs``` declaring arrays of commands which will be called on the specific events. By declaring the attribute ```aux_ops``` with a hash, it is possilble to add auxiliary options to the interface stanza, which will be generated by using the key as option name and the value to the key as value. This obviously has the limitation of having every option name ones, however, the most important case this is useful, the up and down hooks can be handled through ```ups```, ```downs```, ```pre-ups``` and ```post-downs``` attributes. Many debnet resources allow to add commands to the usual up/down hooks. The attributes pre_ups, ups, downs and post_downs are available for many resources. Each of which are typed as array and many elements will be added in order as pre-up, up, down or post-down options, respectively. High care must be taken while using these attributes, since the module does not do any kind of checks. ```puppet debnet::iface::dhcp { 'eth0': ups => ['echo "eth0 is up"'], downs => ['echo "eth0 is going down"'] } ``` ##Feature helpers The module provides feature helpers to enable sofisticated configuration features to be added easily. ###Queue length If the setting of the txqueuelen feature of ethernet interfaces needs to done, the attribute ```tx_queue``` can be added to any resource type other than loopback. The helper adds an up command to set the transmit queue of the interface. In case of types bond and bridge, the up command is applied to the corresponding slave interfaces. ```puppet debnet::iface::dhcp { 'eth0': tx_queue => 50, } ``` Available attributes: * ```tx_queue``` - (int) length of the transmit queue (optional) ###Static routes Static routes can be added to any resource type which is configuring layer-3 of an interface. Declaring the ```routes``` attribute as a hash which is mapping gateway addresses (values) to specific destinations (keys). Destinations are declared by a dotted-quad and prefix length, the gateway addresses must be dotted-quads. Multiple routes may be declared. Many routes will be added as up and down commands to the containing interface. ```puppet debnet::iface::static { 'eth0': address => '192.168.0.10', netmask => 24, gateway => '192.168.0.1', routes => { '172.16.0.0/12' => '192.168.0.2', '10.0.0.0/8' => '192.168.0.3', }, } ``` Available attributes: * ```routes``` - (hash) maps routes to their gateways (optional) ###DNS resolver settings Many Debian installations make use of the resolvconf tools to setup the local DNS resolver dynamically. Feature helpers ```dns_nameservers``` and ```dns_search``` enables to add presets to be passed to resolvconf scripts when an interface is brought up. ```puppet debnet::iface::static { 'eth0': address => '192.168.0.10', netmask => 24, gateway => '192.168.0.1', dns_search => ['example.org', 'example.com'], dns_nameservers => ['192.168.0.2', '192.168.0.3'], } ``` Available attributes: * ```dns_search``` - (array) DNS search list (optional) * ```dns_nameservers``` - (array) DNS nameserver list (optional) diff --git a/examples/init.pp b/examples/init.pp new file mode 100644 index 0000000..0d6ae1b --- /dev/null +++ b/examples/init.pp @@ -0,0 +1 @@ +include debnet \ No newline at end of file diff --git a/examples/support/wvdial.pp b/examples/support/wvdial.pp new file mode 100644 index 0000000..655dfc9 --- /dev/null +++ b/examples/support/wvdial.pp @@ -0,0 +1,14 @@ +include debnet + +debnet::support::wvdial { 'myconf': + device => '/dev/ttyACM1', + baud => '460800', + username => 'blank', + password => 'blank', + init => [ + 'ATZ', + 'ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0', + 'AT+CFUN=1', + 'AT+CGDCONT=1,"IP","INTERNETSTATIC", "192.168.1.24"' + ] +} \ No newline at end of file diff --git a/manifests/iface.pp b/manifests/iface.pp index 3c2068e..ee2c883 100644 --- a/manifests/iface.pp +++ b/manifests/iface.pp @@ -1,268 +1,285 @@ # == 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 2015 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, # 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$') + 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 { validate_re($tx_queue, '^\d+$') } if $routes { validate_hash($routes) } if $dns_nameservers { validate_array($dns_nameservers) } if $dns_search { validate_array($dns_search) } case $method { 'loopback' : { concat::fragment { 'lo_stanza': target => $debnet::params::interfaces_file, content => template('debnet/loopback.erb'), order => 10 + $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}(? $debnet::params::interfaces_file, content => template( 'debnet/iface_header.erb', 'debnet/inet_dhcp.erb', 'debnet/iface_aux.erb', 'debnet/iface_routes.erb'), order => 20 + $order, } } 'static' : { validate_re($address, '^(:?[0-9]{1,3}\.){3}[0-9]{1,3}$') validate_re($netmask, '^([0-9]{1,3}\.){3}[0-9]{1,3}$|^[0-9]{1,2}$') 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 => $debnet::params::interfaces_file, content => template( 'debnet/iface_header.erb', 'debnet/inet_static.erb', 'debnet/iface_aux.erb', 'debnet/iface_routes.erb'), order => 20 + $order, } } 'manual' : { concat::fragment { "${ifname}_stanza": target => $debnet::params::interfaces_file, content => template( 'debnet/iface_header.erb', - 'debnet/inet_manual.erb', + 'debnet/inet_misc.erb', 'debnet/iface_aux.erb'), order => 20 + $order, } } + 'wvdial' : { + if !defined(Package[$debnet::params::wvdial_pkg]) { + package { $debnet::params::wvdial_pkg: ensure => 'installed', } + } + + concat::fragment { "${ifname}_stanza": + target => $debnet::params::interfaces_file, + content => template( + 'debnet/iface_header.erb', + 'debnet/inet_misc.erb', + 'debnet/iface_aux.erb', + 'debnet/iface_routes.erb'), + order => 20 + $order, + } + } + default: { err('unrecognized method') } } } diff --git a/manifests/iface/bond.pp b/manifests/iface/bond.pp index 9507ac8..c7747be 100644 --- a/manifests/iface/bond.pp +++ b/manifests/iface/bond.pp @@ -1,270 +1,270 @@ # == 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 2015 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, # 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!') } validate_re($mode, '^balance\-rr$|^active\-backup$|^balance\-xor$|^broadcast$|^802\.3ad$|^balance\-tlb$|^balance\-alb$') validate_re($miimon, '^\d+$') $bondopts0 = { 'bond-slaves' => 'none', 'bond-primary' => $ports[1], 'bond-mode' => $mode, 'bond-miimon' => $miimon, } validate_bool($use_carrier) if $updelay { validate_re($updelay, '^\d+$') $bondopts1 = {'bond-updelay' => $updelay} } else { $bondopts1 = {} } if $downdelay { validate_re($downdelay, '^\d+$') $bondopts2 = {'bond-downdelay' => $downdelay} } else { $bondopts2 = {} } debnet::iface { $ports: method => 'manual', auto => $auto, allows => $allows, family => $family, order => 50 + $order, 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, 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 dd10d59..bb019a1 100644 --- a/manifests/iface/bridge.pp +++ b/manifests/iface/bridge.pp @@ -1,286 +1,286 @@ # == 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 2015 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, # 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, 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 611b4a3..8e7844b 100644 --- a/manifests/iface/dhcp.pp +++ b/manifests/iface/dhcp.pp @@ -1,155 +1,155 @@ # == 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 2014 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, $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, hostname => $hwaddress, 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 0714b4f..96d2aed 100644 --- a/manifests/iface/loopback.pp +++ b/manifests/iface/loopback.pp @@ -1,86 +1,86 @@ # == 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 2015 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, # 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, 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 9fcc0e5..c275e1c 100644 --- a/manifests/iface/static.pp +++ b/manifests/iface/static.pp @@ -1,173 +1,173 @@ # == 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 2015 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, $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, 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/manifests/init.pp b/manifests/init.pp index e6aa21d..0cd7b37 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,56 +1,56 @@ # == Class: debnet # # Initial class of module. # # === Parameters # # none # # === Variables # # none # # === Examples # # include debnet # # === Authors # # Tibor Repasi # # === Copyright # # Copyright 2015 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. # class debnet { include debnet::params package { $debnet::params::iproute_pkg: ensure => 'installed', } concat { $params::interfaces_file : owner => 'root', group => 'root', mode => '0644', ensure_newline => true, } - + concat::fragment { 'interfaces_header': target => $params::interfaces_file, content => template('debnet/header.erb'), order => 01, } } diff --git a/manifests/params.pp b/manifests/params.pp index 738ed44..a8247a4 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,39 +1,40 @@ # == Class: params # # Parameter settings. # # === Parameters # # none # # === Variables # # none # # === Authors # # Tibor Repasi # # === Copyright # # Copyright 2015 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. # class debnet::params { $interfaces_file = '/etc/network/interfaces' $iproute_pkg = 'iproute' + $wvdial_pkg = 'wvdial' $dhclient_pkg = 'isc-dhcp-client' $bridge_utils_pkg = 'bridge-utils' $ifenslave_pkg = 'ifenslave-2.6' } \ No newline at end of file diff --git a/manifests/support/wvdial.pp b/manifests/support/wvdial.pp new file mode 100644 index 0000000..f13fd70 --- /dev/null +++ b/manifests/support/wvdial.pp @@ -0,0 +1,76 @@ +# == Define: support/wvdial +# +# Resource to define wvdial() configuration +# +# == Examples +# +# See the examples folder for usage examples of the wvdial function +# +# == Parameters +# +# [*device*] - string +# Specify which device to use for this config. +# Each channel will require a different device, e.g. voice on ACM0, data on ACM1, etc +# +# [*baud*] - string +# +# [*username*] - string +# [*password*] - string +# +# [*init*] - array +# will produce: +# Init1 = ATZ +# Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 +# Init3 = AT+CFUN=1 +# Init4 = AT+CGDCONT=1,"IP","INTERNETSTATIC", "1.2.3.4" +# +# [*autodns*] - (on|off) +# Whether to add nameserver information to /etc/resolv.conf +# +# === Authors +# +# David Raison +# +# === Copyright +# +# Copyright 2015 David Raison +# +# 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::support::wvdial( + $device, + $baud, + $init = [], + $username = undef, + $password = undef, + $autodns = 'off', +) { + + validate_string($device) + validate_string($baud) + validate_array($init) + validate_re($autodns, '^on$|^off$') + + if $username { + validate_string($username) + } + + if $password { + validate_string($password) + } + + file { '/etc/wvdial.conf': + ensure => file, + content => template('debnet/wvdial.conf.erb'), + } +} diff --git a/templates/inet_manual.erb b/templates/inet_manual.erb deleted file mode 100644 index b13016e..0000000 --- a/templates/inet_manual.erb +++ /dev/null @@ -1 +0,0 @@ -iface <%= @ifname -%> <%= @family -%> manual diff --git a/templates/inet_misc.erb b/templates/inet_misc.erb new file mode 100644 index 0000000..18d0243 --- /dev/null +++ b/templates/inet_misc.erb @@ -0,0 +1 @@ +iface <%= @ifname -%> <%= @family -%> <%= @method %> diff --git a/templates/wvdial.conf.erb b/templates/wvdial.conf.erb new file mode 100644 index 0000000..de665d6 --- /dev/null +++ b/templates/wvdial.conf.erb @@ -0,0 +1,13 @@ +[Dialer Defaults] +Modem = <%= @device -%> +<% @init.each.with_index(1) do |cmd, index| %> +Init<%= index -%> = <%= cmd -%> +<% end %> +Stupid Mode = 1 +New PPPD = yes +ISDN = 0 +Username = "<%= @username -%>" +Password = "<%= @password -%>" +Phone = *99# +Baud = <%= @baud %> +Auto DNS = <%= @autodns -%> diff --git a/tests/init.pp b/tests/init.pp deleted file mode 100644 index 9f8ee6a..0000000 --- a/tests/init.pp +++ /dev/null @@ -1 +0,0 @@ -include debnet