From a31229e5ab1291d79d14ac9bf4ad210db4895cea Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 5 May 2016 12:33:46 +0100 Subject: [PATCH] Add support for bonding and VLANs --- cookbooks/networking/recipes/default.rb | 7 +++++++ cookbooks/networking/templates/default/interfaces.erb | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/cookbooks/networking/recipes/default.rb b/cookbooks/networking/recipes/default.rb index 8355b54c0..e23b1dae3 100644 --- a/cookbooks/networking/recipes/default.rb +++ b/cookbooks/networking/recipes/default.rb @@ -22,7 +22,12 @@ require "ipaddr" +network_packages = [] + node[:networking][:interfaces].each do |name, interface| + network_packages |= ["vlan"] if interface[:interface] =~ /\.\d+$/ + network_packages |= ["ifenslave"] if interface[:bond] + if interface[:role] && (role = node[:networking][:roles][interface[:role]]) if role[interface[:family]] node.set[:networking][:interfaces][name][:prefix] = role[interface[:family]][:prefix] @@ -39,6 +44,8 @@ node[:networking][:interfaces].each do |name, interface| node.set[:networking][:interfaces][name][:network] = IPAddr.new(interface[:address]).mask(prefix) end +package network_packages + template "/etc/network/interfaces" do source "interfaces.erb" owner "root" diff --git a/cookbooks/networking/templates/default/interfaces.erb b/cookbooks/networking/templates/default/interfaces.erb index 50238cb5f..1b3e1a989 100644 --- a/cookbooks/networking/templates/default/interfaces.erb +++ b/cookbooks/networking/templates/default/interfaces.erb @@ -31,6 +31,14 @@ iface <%= interface[:interface] %> <%= interface[:family] %> static <% if interface[:family] == "inet6" -%> autoconf 0 <% end -%> +<% if interface[:bond] -%> + bond-mode <%= interface[:bond][:mode] || "active-backup" %> + bond-slaves <%= interface[:bond][:slaves].join(" ") %> + bond-primary <%= interface[:bond][:slaves].first %> + bond-miimon <%= interface[:bond][:miimon] || 100 %> + bond-downdelay <%= interface[:bond][:downdelay] || 200 %> + bond-updelay <%= interface[:bond][:updelay] || 200 %> +<% end -%> <% end -%> <% end -%> -- 2.39.5