diff --git a/README.markdown b/README.markdown index d064306..cb8583b 100644 --- a/README.markdown +++ b/README.markdown @@ -19,27 +19,27 @@ ``` include interfaces -interfaces::iface { 'eth0': family => 'inet', method => 'dhcp', auto => 1 } +interfaces::iface { 'eth0': family => 'inet', method => 'dhcp', auto => 1, allow_hotplug => 1 } ``` Network interface with static addressing and VLAN with DHCP configuration: ``` include interfaces -interfaces::iface { 'eth0': family => 'inet', method => 'static', options => ['address 192.0.2.1','netmask 255.255.255.0','gateway 192.0.2.2'], auto => 1 } +interfaces::iface { 'eth0': family => 'inet', method => 'static', options => ['address 192.0.2.1','netmask 255.255.255.0','gateway 192.0.2.2'], auto => 1, allow_hotplug => 1 } interfaces::iface { 'eth0.123': family => 'inet', method => 'dhcp', options => ['vlan_raw_device eth0'], auto => 1 } ``` Static IPv6 address configuration: ``` include interfaces -interfaces::iface { 'eth0': family => 'inet6', method => 'static', options => ['address 2001:db8::1','netmask 64'], auto => 1 } +interfaces::iface { 'eth0': family => 'inet6', method => 'static', options => ['address 2001:db8::1','netmask 64'], auto => 1, allow_hotplug => 1 } ``` Dualstack configuration: ``` include interfaces -interfaces::iface { 'eth0': family => 'inet', method => 'dhcp', auto => 1 } -interfaces::iface { 'eth0v6': ifname => 'eth0', family => 'inet6', method => 'static', options => ['address 2001:db8::1','netmask 64'], auto => 1 } +interfaces::iface { 'eth0': family => 'inet', method => 'dhcp', auto => 1, allow_hotplug => 1 } +interfaces::iface { 'eth0v6': ifname => 'eth0', family => 'inet6', method => 'static', options => ['address 2001:db8::1','netmask 64'] } ``` Reference: @@ -51,7 +51,7 @@ interfaces::auto() interfaces::allow($subsystem) interfaces::mapping($script, $maps=[]) -interfaces::iface($family, $method, $options=[], $ifname=$name, $auto=0) +interfaces::iface($family, $method, $options=[], $ifname=$name, $auto=0, $allow_hotplug=0) ``` -Currently the only shortcut is the $auto parameter of interfaces::iface which when set to 1 directly produces an interfaces::auto entry for the interface. +Currently the only shortcuts are the $auto parameter of interfaces::iface which when set to 1 directly produces an interfaces::auto entry for the interface and the $allow_hotplug parameter of interfaces::iface which when set to 1 directly produces an interfaces::allow hotplug subsystem entry for the interface. diff --git a/manifests/iface.pp b/manifests/iface.pp index 7575921..6fc40ab 100644 --- a/manifests/iface.pp +++ b/manifests/iface.pp @@ -1,4 +1,4 @@ -define interfaces::iface ( $family, $method, $options=[], $auto=0, $ifname='UNSET' ) { +define interfaces::iface ( $family, $method, $options=[], $auto=0, $allow_hotplug=0, $ifname='UNSET' ) { case $family { inet: { if ! ($method in [loopback, static, manual, dhcp, bootp, ppp, wvdial]) { @@ -29,6 +29,10 @@ interfaces::auto { $ifname_real: } } + if $allow_hotplug == 1 { + interfaces::allow { $ifname_real: subsystem => 'hotplug' } + } + concat::fragment{"interfaces::iface_${name}": target => '/etc/network/interfaces', content => inline_template("iface <%= @ifname_real %> <%= @family %> <%= @method %>\n\t<%= @options.join('\n\t') %>\n\n"), diff --git a/spec/defines/iface_spec.rb b/spec/defines/iface_spec.rb index ddc03c2..644e378 100644 --- a/spec/defines/iface_spec.rb +++ b/spec/defines/iface_spec.rb @@ -5,6 +5,7 @@ let(:params) { { :family => 'inet', :method => 'loopback', :auto => 1 } } it { + should_not contain_interfaces__allow('lo').with_subsystem('hotplug') should contain_interfaces__auto('lo') should contain_concat__fragment('interfaces::iface_lo').with_target('/etc/network/interfaces') should contain_concat__fragment('interfaces::iface_lo').with_content("iface lo inet loopback\n\t\n\n") @@ -17,6 +18,19 @@ it { should_not contain_interfaces__auto('eth0') + should_not contain_interfaces__allow('eth0').with_subsystem('hotplug') + should contain_concat__fragment('interfaces::iface_eth0').with_target('/etc/network/interfaces') + should contain_concat__fragment('interfaces::iface_eth0').with_content("iface eth0 inet dhcp\n\t\n\n") + } +end + +describe 'interfaces::iface' do + let(:title) { 'eth0' } + let(:params) { { :family => 'inet', :method => 'dhcp', :auto => 1, :allow_hotplug => 1 } } + + it { + should contain_interfaces__auto('eth0') + should contain_interfaces__allow('eth0').with_subsystem('hotplug') should contain_concat__fragment('interfaces::iface_eth0').with_target('/etc/network/interfaces') should contain_concat__fragment('interfaces::iface_eth0').with_content("iface eth0 inet dhcp\n\t\n\n") } @@ -28,6 +42,7 @@ it { should contain_interfaces__auto('eth0') + should_not contain_interfaces__allow('eth0').with_subsystem('hotplug') should contain_concat__fragment('interfaces::iface_eth0').with_target('/etc/network/interfaces') should contain_concat__fragment('interfaces::iface_eth0').with_content("iface eth0 inet dhcp\n\t\n\n") } @@ -35,10 +50,11 @@ describe 'interfaces::iface' do let(:title) { 'eth0' } - let(:params) { { :family => 'inet', :method => 'static', :options => ['address 192.0.2.1','netmask 255.255.255.0','gateway 192.0.2.2'], :auto => 1 } } + let(:params) { { :family => 'inet', :method => 'static', :options => ['address 192.0.2.1','netmask 255.255.255.0','gateway 192.0.2.2'], :auto => 1, :allow_hotplug => 1 } } it { should contain_interfaces__auto('eth0') + should contain_interfaces__allow('eth0').with_subsystem('hotplug') should contain_concat__fragment('interfaces::iface_eth0').with_target('/etc/network/interfaces') should contain_concat__fragment('interfaces::iface_eth0').with_content("iface eth0 inet static\n\taddress 192.0.2.1\n\tnetmask 255.255.255.0\n\tgateway 192.0.2.2\n\n") } @@ -50,6 +66,7 @@ it { should contain_interfaces__auto('eth0.123') + should_not contain_interfaces__allow('eth0.123').with_subsystem('hotplug') should contain_concat__fragment('interfaces::iface_eth0.123').with_target('/etc/network/interfaces') should contain_concat__fragment('interfaces::iface_eth0.123').with_content("iface eth0.123 inet dhcp\n\tvlan_raw_device eth0\n\n") } @@ -57,10 +74,11 @@ describe 'interfaces::iface' do let(:title) { 'eth0' } - let(:params) { { :family => 'inet6', :method => 'static', :options => ['address 2001:db8::1','netmask 64'], :auto => 1 } } + let(:params) { { :family => 'inet6', :method => 'static', :options => ['address 2001:db8::1','netmask 64'] } } it { - should contain_interfaces__auto('eth0') + should_not contain_interfaces__auto('eth0') + should_not contain_interfaces__allow('eth0').with_subsystem('hotplug') should contain_concat__fragment('interfaces::iface_eth0').with_target('/etc/network/interfaces') should contain_concat__fragment('interfaces::iface_eth0').with_content("iface eth0 inet6 static\n\taddress 2001:db8::1\n\tnetmask 64\n\n") } @@ -68,10 +86,11 @@ describe 'interfaces::iface' do let(:title) { 'eth0v6' } - let(:params) { { :ifname => 'eth0', :family => 'inet6', :method => 'static', :options => ['address 2001:db8::1','netmask 64'], :auto => 1 } } + let(:params) { { :ifname => 'eth0', :family => 'inet6', :method => 'static', :options => ['address 2001:db8::1','netmask 64'], :auto => 1, :allow_hotplug => 1 } } it { should contain_interfaces__auto('eth0') + should contain_interfaces__allow('eth0').with_subsystem('hotplug') should contain_concat__fragment('interfaces::iface_eth0v6').with_target('/etc/network/interfaces') should contain_concat__fragment('interfaces::iface_eth0v6').with_content("iface eth0 inet6 static\n\taddress 2001:db8::1\n\tnetmask 64\n\n") }