Configure interface bonding by puppet

Example:
  l23network::l3::ifconfig {'eth0': ipaddr=>'none', bond_master=>'bond0', } ->
  l23network::l3::ifconfig {'eth2': ipaddr=>'none', bond_master=>'bond0', } ->
  l23network::l3::ifconfig {'bond0':
    ipaddr=>'192.168.232.1',
    bond_mode=>0,
  }
This commit is contained in:
Sergey Vasilenko 2013-03-20 18:38:47 +04:00
parent 98ca56a738
commit 9882e440b2
11 changed files with 90 additions and 6 deletions

View File

@ -112,6 +112,7 @@ Puppet::Type.type(:l3_if_downup).provide(:ruby) do
notice("Can't flush interface '#{@resource[:interface]}'.") notice("Can't flush interface '#{@resource[:interface]}'.")
end end
end end
return true if @resource[:onlydown]
begin # Put interface to UP state begin # Put interface to UP state
ifup(@resource[:interface]) ifup(@resource[:interface])
notice("Interface '#{@resource[:interface]}' up.") notice("Interface '#{@resource[:interface]}' up.")

View File

@ -24,6 +24,11 @@ Puppet::Type.newtype(:l3_if_downup) do
defaultto(true) defaultto(true)
end end
newparam(:onlydown) do
newvalues(true, false)
defaultto(false)
end
newparam(:kill_dhclient) do newparam(:kill_dhclient) do
# workaround for https://bugs.launchpad.net/ubuntu/+source/dhcp3/+bug/38140 # workaround for https://bugs.launchpad.net/ubuntu/+source/dhcp3/+bug/38140
newvalues(true, false) newvalues(true, false)

View File

@ -18,6 +18,19 @@
# If you configure 802.1q vlan interface wint name vlanXXX # If you configure 802.1q vlan interface wint name vlanXXX
# you must specify parent interface in this option # you must specify parent interface in this option
# #
# [*bond_master*]
# This option say, that this interface is a slave of bondX interface.
#
# [*bond_mode*]
# For interfaces bondNN this option specified bond mode.
# All bond_* options ignored for non-master-bond interfaces.
#
# [*bond_miimon*]
# lacp MII monitor period.
#
# [*bond_lacp_rate*]
# lacp MII rate
#
# [*ifname_order_prefix*] # [*ifname_order_prefix*]
# Centos and Ubuntu at boot time Up and configure network interfaces in # Centos and Ubuntu at boot time Up and configure network interfaces in
# alphabetical order of interface configuration file names. # alphabetical order of interface configuration file names.
@ -58,6 +71,11 @@ define l23network::l3::ifconfig (
$netmask = '255.255.255.0', $netmask = '255.255.255.0',
$gateway = undef, $gateway = undef,
$vlandev = undef, $vlandev = undef,
$bond_master = undef,
$bond_mode = undef,
$bond_miimon = 100,
$bond_lacp_rate = 1,
$mtu = undef,
$dns_nameservers = undef, $dns_nameservers = undef,
$dns_search = undef, $dns_search = undef,
$dns_domain = undef, $dns_domain = undef,
@ -67,11 +85,27 @@ define l23network::l3::ifconfig (
$check_by_ping = 'gateway', $check_by_ping = 'gateway',
$check_by_ping_timeout = 120, $check_by_ping_timeout = 120,
){ ){
case $ipaddr { $bond_modes = [
'dhcp': { $method = 'dhcp' } 'balance-rr',
'none': { $method = 'manual' } 'active-backup',
default: { $method = 'static' } 'balance-xor',
'broadcast',
'802.3ad',
'balance-tlb',
'balance-alb'
]
if $bond_master {
$method = 'bondslave'
} else {
case $ipaddr {
'dhcp': { $method = 'dhcp' }
'none': { $method = 'manual' }
default: { $method = 'static' }
}
} }
# OS depends constats and packages
case $::osfamily { case $::osfamily {
/(?i)debian/: { /(?i)debian/: {
$if_files_dir = '/etc/network/interfaces.d' $if_files_dir = '/etc/network/interfaces.d'
@ -79,6 +113,8 @@ define l23network::l3::ifconfig (
if $dns_nameservers { if $dns_nameservers {
$dns_nameservers_join = join($dns_nameservers, ' ') $dns_nameservers_join = join($dns_nameservers, ' ')
} }
if !defined(Package['vlan']){ package {'vlan': ensure => installed } }
if !defined(Package['ifenslave']){ package {'ifenslave': ensure => installed } }
} }
/(?i)redhat/: { /(?i)redhat/: {
$if_files_dir = '/etc/sysconfig/network-scripts' $if_files_dir = '/etc/sysconfig/network-scripts'
@ -87,13 +123,15 @@ define l23network::l3::ifconfig (
$dns_nameservers_1 = $dns_nameservers[0] $dns_nameservers_1 = $dns_nameservers[0]
$dns_nameservers_2 = $dns_nameservers[1] $dns_nameservers_2 = $dns_nameservers[1]
} }
if !defined(Package['vconfig']){ package {'vconfig': ensure => installed } }
} }
default: { default: {
fail("Unsupported OS: ${::osfamily}/${::operatingsystem}") fail("Unsupported OS: ${::osfamily}/${::operatingsystem}")
} }
} }
if !defined(Package['ethtool']){ package {'ethtool': ensure => installed } }
# Detect VLAN mode configuration # Detect VLAN and bond mode configuration
case $interface { case $interface {
/^vlan(\d+)/: { /^vlan(\d+)/: {
$vlan_mode = 'vlan' $vlan_mode = 'vlan'
@ -109,6 +147,12 @@ define l23network::l3::ifconfig (
$vlan_id = $2 $vlan_id = $2
$vlan_dev = $1 $vlan_dev = $1
} }
/^(bond\d+)/: {
if ! $bond_mode or $bond_mode <0 or $bond_mode>6 {
fail("Option bond_mode must be between 0..6, not '${bond_mode}'.")
}
$vlan_mode = undef
}
default: { default: {
$vlan_mode = undef $vlan_mode = undef
} }
@ -142,7 +186,8 @@ define l23network::l3::ifconfig (
content => template('l23network/interfaces.erb'), content => template('l23network/interfaces.erb'),
} }
} }
File[$interfaces] -> File[$if_files_dir] #File[$interfaces] -> File[$if_files_dir]
#File<| title == $interfaces |> -> File<| title == $if_files_dir |>
} }
if ! defined(File[$if_files_dir]) { if ! defined(File[$if_files_dir]) {

View File

@ -0,0 +1,3 @@
auto <%= interface %>
iface <%= interface %> inet manual
bond-master <%= @bond_master %>

View File

@ -2,3 +2,9 @@ auto <%= interface %>
iface <%= interface %> inet dhcp iface <%= interface %> inet dhcp
<% if @dhcp_hostname %>hostname <%= @dhcp_hostname %><% end %> <% if @dhcp_hostname %>hostname <%= @dhcp_hostname %><% end %>
<% if @vlan_mode %>vlan_raw_device <%= @vlan_dev %><% end %> <% if @vlan_mode %>vlan_raw_device <%= @vlan_dev %><% end %>
<% if @mtu %>mtu <%= @mtu %><% end %>
<% if @bond_mode %>bond-mode <%= @bond_mode %>
slaves none<% if @bond_mode == 4 %>
bond-miimon <%= @bond_miimon %>
bond-lacp-rate <%= @bond_lacp_rate %><% end %>
<% end %>

View File

@ -3,3 +3,9 @@ iface <%= interface %> inet manual
<% if @vlan_mode %>vlan_raw_device <%= @vlan_dev %><% end %> <% if @vlan_mode %>vlan_raw_device <%= @vlan_dev %><% end %>
up ip l set <%= interface %> up up ip l set <%= interface %> up
down ip l set <%= interface %> down down ip l set <%= interface %> down
<% if @mtu %>mtu <%= @mtu %><% end %>
<% if @bond_mode %>bond-mode <%= @bond_mode %>
slaves none<% if @bond_mode == 4 %>
bond-miimon <%= @bond_miimon %>
bond-lacp-rate <%= @bond_lacp_rate %><% end %>
<% end %>

View File

@ -7,3 +7,9 @@ netmask <%= netmask %>
<% if @dns_nameservers_join %>dns-nameservers <%= @dns_nameservers_join %><% end %> <% if @dns_nameservers_join %>dns-nameservers <%= @dns_nameservers_join %><% end %>
<% if @dns_search %>dns-search <%= @dns_search %><% end %> <% if @dns_search %>dns-search <%= @dns_search %><% end %>
<% if @dns_domain %>dns-domain <%= @dns_domain %><% end %> <% if @dns_domain %>dns-domain <%= @dns_domain %><% end %>
<% if @mtu %>mtu <%= @mtu %><% end %>
<% if @bond_mode %>bond-mode <%= @bond_mode %>
slaves none<% if @bond_mode == 4 %>
bond-miimon <%= @bond_miimon %>
bond-lacp-rate <%= @bond_lacp_rate %><% end %>
<% end %>

View File

@ -0,0 +1,6 @@
DEVICE=<%= interface %>
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
MASTER=<%= @bond_master %>
SLAVE=yes

View File

@ -6,3 +6,5 @@ USERCTL=no
<% if @vlan_mode %>VLAN=yes<% end %> <% if @vlan_mode %>VLAN=yes<% end %>
<% if @vlan_mode == 'vlan' %>VLAN_NAME_TYPE=VLAN_PLUS_VID_NO_PAD <% if @vlan_mode == 'vlan' %>VLAN_NAME_TYPE=VLAN_PLUS_VID_NO_PAD
PHYSDEV=<%= @vlan_dev %><% end %> PHYSDEV=<%= @vlan_dev %><% end %>
<% if @mtu %>MTU=<%= @mtu %><% end %>
<% if @bond_mode %>BONDING_OPTS="mode=<%= @bond_mode %><% if @bond_mode == 4 %> miimon=<%= @bond_miimon %> bond-lacp-rate=<%= @bond_lacp_rate %><% end %>"<% end %>

View File

@ -5,3 +5,5 @@ USERCTL=no
<% if @vlan_mode %>VLAN=yes<% end %> <% if @vlan_mode %>VLAN=yes<% end %>
<% if @vlan_mode == 'vlan' %>VLAN_NAME_TYPE=VLAN_PLUS_VID_NO_PAD <% if @vlan_mode == 'vlan' %>VLAN_NAME_TYPE=VLAN_PLUS_VID_NO_PAD
PHYSDEV=<%= @vlan_dev %><% end %> PHYSDEV=<%= @vlan_dev %><% end %>
<% if @mtu %>MTU=<%= @mtu %><% end %>
<% if @bond_mode %>BONDING_OPTS="mode=<%= @bond_mode %><% if @bond_mode == 4 %> miimon=<%= @bond_miimon %> bond-lacp-rate=<%= @bond_lacp_rate %><% end %>"<% end %>

View File

@ -10,3 +10,5 @@ PHYSDEV=<%= @vlan_dev %><% end %>
<% if @def_gateway %>GATEWAY=<%= @def_gateway %><% end %> <% if @def_gateway %>GATEWAY=<%= @def_gateway %><% end %>
<% if @dns_nameservers_1 %>DNS1=<%= @dns_nameservers_1 %><% end %> <% if @dns_nameservers_1 %>DNS1=<%= @dns_nameservers_1 %><% end %>
<% if @dns_nameservers_2 %>DNS2=<%= @dns_nameservers_2 %><% end %> <% if @dns_nameservers_2 %>DNS2=<%= @dns_nameservers_2 %><% end %>
<% if @mtu %>MTU=<%= @mtu %><% end %>
<% if @bond_mode %>BONDING_OPTS="mode=<%= @bond_mode %><% if @bond_mode == 4 %> miimon=<%= @bond_miimon %> bond-lacp-rate=<%= @bond_lacp_rate %><% end %>"<% end %>