From 9882e440b295308ff9551d6aa04b526533980851 Mon Sep 17 00:00:00 2001 From: Sergey Vasilenko Date: Wed, 20 Mar 2013 18:38:47 +0400 Subject: [PATCH] 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, } --- .../lib/puppet/provider/l3_if_downup/ruby.rb | 1 + .../lib/puppet/type/l3_if_downup.rb | 5 ++ .../l23network/manifests/l3/ifconfig.pp | 57 +++++++++++++++++-- .../templates/ipconfig_Debian_bondslave.erb | 3 + .../templates/ipconfig_Debian_dhcp.erb | 6 ++ .../templates/ipconfig_Debian_manual.erb | 6 ++ .../templates/ipconfig_Debian_static.erb | 6 ++ .../templates/ipconfig_RedHat_bondslave.erb | 6 ++ .../templates/ipconfig_RedHat_dhcp.erb | 2 + .../templates/ipconfig_RedHat_manual.erb | 2 + .../templates/ipconfig_RedHat_static.erb | 2 + 11 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 deployment/puppet/l23network/templates/ipconfig_Debian_bondslave.erb create mode 100644 deployment/puppet/l23network/templates/ipconfig_RedHat_bondslave.erb diff --git a/deployment/puppet/l23network/lib/puppet/provider/l3_if_downup/ruby.rb b/deployment/puppet/l23network/lib/puppet/provider/l3_if_downup/ruby.rb index 305b827c33..9d4b44d2bd 100644 --- a/deployment/puppet/l23network/lib/puppet/provider/l3_if_downup/ruby.rb +++ b/deployment/puppet/l23network/lib/puppet/provider/l3_if_downup/ruby.rb @@ -112,6 +112,7 @@ Puppet::Type.type(:l3_if_downup).provide(:ruby) do notice("Can't flush interface '#{@resource[:interface]}'.") end end + return true if @resource[:onlydown] begin # Put interface to UP state ifup(@resource[:interface]) notice("Interface '#{@resource[:interface]}' up.") diff --git a/deployment/puppet/l23network/lib/puppet/type/l3_if_downup.rb b/deployment/puppet/l23network/lib/puppet/type/l3_if_downup.rb index e04719119f..44a4ec750b 100644 --- a/deployment/puppet/l23network/lib/puppet/type/l3_if_downup.rb +++ b/deployment/puppet/l23network/lib/puppet/type/l3_if_downup.rb @@ -24,6 +24,11 @@ Puppet::Type.newtype(:l3_if_downup) do defaultto(true) end + newparam(:onlydown) do + newvalues(true, false) + defaultto(false) + end + newparam(:kill_dhclient) do # workaround for https://bugs.launchpad.net/ubuntu/+source/dhcp3/+bug/38140 newvalues(true, false) diff --git a/deployment/puppet/l23network/manifests/l3/ifconfig.pp b/deployment/puppet/l23network/manifests/l3/ifconfig.pp index 4f647cfbf4..0e4ade5b88 100644 --- a/deployment/puppet/l23network/manifests/l3/ifconfig.pp +++ b/deployment/puppet/l23network/manifests/l3/ifconfig.pp @@ -18,6 +18,19 @@ # If you configure 802.1q vlan interface wint name vlanXXX # 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*] # Centos and Ubuntu at boot time Up and configure network interfaces in # alphabetical order of interface configuration file names. @@ -58,6 +71,11 @@ define l23network::l3::ifconfig ( $netmask = '255.255.255.0', $gateway = undef, $vlandev = undef, + $bond_master = undef, + $bond_mode = undef, + $bond_miimon = 100, + $bond_lacp_rate = 1, + $mtu = undef, $dns_nameservers = undef, $dns_search = undef, $dns_domain = undef, @@ -67,11 +85,27 @@ define l23network::l3::ifconfig ( $check_by_ping = 'gateway', $check_by_ping_timeout = 120, ){ - case $ipaddr { - 'dhcp': { $method = 'dhcp' } - 'none': { $method = 'manual' } - default: { $method = 'static' } + $bond_modes = [ + 'balance-rr', + 'active-backup', + '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 { /(?i)debian/: { $if_files_dir = '/etc/network/interfaces.d' @@ -79,6 +113,8 @@ define l23network::l3::ifconfig ( if $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/: { $if_files_dir = '/etc/sysconfig/network-scripts' @@ -87,13 +123,15 @@ define l23network::l3::ifconfig ( $dns_nameservers_1 = $dns_nameservers[0] $dns_nameservers_2 = $dns_nameservers[1] } + if !defined(Package['vconfig']){ package {'vconfig': ensure => installed } } } default: { 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 { /^vlan(\d+)/: { $vlan_mode = 'vlan' @@ -109,6 +147,12 @@ define l23network::l3::ifconfig ( $vlan_id = $2 $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: { $vlan_mode = undef } @@ -142,7 +186,8 @@ define l23network::l3::ifconfig ( 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]) { diff --git a/deployment/puppet/l23network/templates/ipconfig_Debian_bondslave.erb b/deployment/puppet/l23network/templates/ipconfig_Debian_bondslave.erb new file mode 100644 index 0000000000..ed02a4ea69 --- /dev/null +++ b/deployment/puppet/l23network/templates/ipconfig_Debian_bondslave.erb @@ -0,0 +1,3 @@ +auto <%= interface %> +iface <%= interface %> inet manual +bond-master <%= @bond_master %> \ No newline at end of file diff --git a/deployment/puppet/l23network/templates/ipconfig_Debian_dhcp.erb b/deployment/puppet/l23network/templates/ipconfig_Debian_dhcp.erb index 521cb8ed63..0638c45062 100644 --- a/deployment/puppet/l23network/templates/ipconfig_Debian_dhcp.erb +++ b/deployment/puppet/l23network/templates/ipconfig_Debian_dhcp.erb @@ -2,3 +2,9 @@ auto <%= interface %> iface <%= interface %> inet dhcp <% if @dhcp_hostname %>hostname <%= @dhcp_hostname %><% 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 %> \ No newline at end of file diff --git a/deployment/puppet/l23network/templates/ipconfig_Debian_manual.erb b/deployment/puppet/l23network/templates/ipconfig_Debian_manual.erb index 651c01f164..136e2f8351 100644 --- a/deployment/puppet/l23network/templates/ipconfig_Debian_manual.erb +++ b/deployment/puppet/l23network/templates/ipconfig_Debian_manual.erb @@ -3,3 +3,9 @@ iface <%= interface %> inet manual <% if @vlan_mode %>vlan_raw_device <%= @vlan_dev %><% end %> up ip l set <%= interface %> up 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 %> diff --git a/deployment/puppet/l23network/templates/ipconfig_Debian_static.erb b/deployment/puppet/l23network/templates/ipconfig_Debian_static.erb index 6bf13fe53f..9ce67a71a2 100644 --- a/deployment/puppet/l23network/templates/ipconfig_Debian_static.erb +++ b/deployment/puppet/l23network/templates/ipconfig_Debian_static.erb @@ -7,3 +7,9 @@ netmask <%= netmask %> <% if @dns_nameservers_join %>dns-nameservers <%= @dns_nameservers_join %><% end %> <% if @dns_search %>dns-search <%= @dns_search %><% 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 %> \ No newline at end of file diff --git a/deployment/puppet/l23network/templates/ipconfig_RedHat_bondslave.erb b/deployment/puppet/l23network/templates/ipconfig_RedHat_bondslave.erb new file mode 100644 index 0000000000..e511ba7964 --- /dev/null +++ b/deployment/puppet/l23network/templates/ipconfig_RedHat_bondslave.erb @@ -0,0 +1,6 @@ +DEVICE=<%= interface %> +BOOTPROTO=none +ONBOOT=yes +USERCTL=no +MASTER=<%= @bond_master %> +SLAVE=yes diff --git a/deployment/puppet/l23network/templates/ipconfig_RedHat_dhcp.erb b/deployment/puppet/l23network/templates/ipconfig_RedHat_dhcp.erb index 52c2923395..7b734ffc0e 100644 --- a/deployment/puppet/l23network/templates/ipconfig_RedHat_dhcp.erb +++ b/deployment/puppet/l23network/templates/ipconfig_RedHat_dhcp.erb @@ -6,3 +6,5 @@ USERCTL=no <% if @vlan_mode %>VLAN=yes<% end %> <% if @vlan_mode == 'vlan' %>VLAN_NAME_TYPE=VLAN_PLUS_VID_NO_PAD 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 %> diff --git a/deployment/puppet/l23network/templates/ipconfig_RedHat_manual.erb b/deployment/puppet/l23network/templates/ipconfig_RedHat_manual.erb index 5874d815fe..4ebc3d1555 100644 --- a/deployment/puppet/l23network/templates/ipconfig_RedHat_manual.erb +++ b/deployment/puppet/l23network/templates/ipconfig_RedHat_manual.erb @@ -5,3 +5,5 @@ USERCTL=no <% if @vlan_mode %>VLAN=yes<% end %> <% if @vlan_mode == 'vlan' %>VLAN_NAME_TYPE=VLAN_PLUS_VID_NO_PAD 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 %> diff --git a/deployment/puppet/l23network/templates/ipconfig_RedHat_static.erb b/deployment/puppet/l23network/templates/ipconfig_RedHat_static.erb index 7f0ea5cc25..65b9be31f0 100644 --- a/deployment/puppet/l23network/templates/ipconfig_RedHat_static.erb +++ b/deployment/puppet/l23network/templates/ipconfig_RedHat_static.erb @@ -10,3 +10,5 @@ PHYSDEV=<%= @vlan_dev %><% end %> <% if @def_gateway %>GATEWAY=<%= @def_gateway %><% end %> <% if @dns_nameservers_1 %>DNS1=<%= @dns_nameservers_1 %><% 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 %>