Add support for bonding and VLANs
authorTom Hughes <tom@compton.nu>
Thu, 5 May 2016 11:33:46 +0000 (12:33 +0100)
committerTom Hughes <tom@compton.nu>
Thu, 5 May 2016 11:33:46 +0000 (12:33 +0100)
cookbooks/networking/recipes/default.rb
cookbooks/networking/templates/default/interfaces.erb

index 8355b54c036e68d0b12d4d68e610e10c962c84d1..e23b1dae313b13beaed885d8edde69ed67d2fdca 100644 (file)
 
 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"
index 50238cb5f885ff16cb55970d1c7173c4ceb9c9b7..1b3e1a9890a88e8db62cf78c8fa0523af64e70ca 100644 (file)
@@ -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 -%>