+ node.default[:networking][:interfaces][name][:prefix] = role[interface[:family]][:prefix]
+ node.default[:networking][:interfaces][name][:gateway] = role[interface[:family]][:gateway]
+ node.default[:networking][:interfaces][name][:routes] = role[interface[:family]][:routes]
+ end
+
+ node.default[:networking][:interfaces][name][:metric] = role[:metric]
+ node.default[:networking][:interfaces][name][:zone] = role[:zone]
+ end
+
+ if interface[:address]
+ prefix = node[:networking][:interfaces][name][:prefix]
+
+ node.default[:networking][:interfaces][name][:netmask] = (~IPAddr.new(interface[:address]).mask(0)).mask(prefix)
+ node.default[:networking][:interfaces][name][:network] = IPAddr.new(interface[:address]).mask(prefix)
+ end
+
+ interface = node[:networking][:interfaces][name]
+
+ deviceplan = if interface[:interface] =~ /^(.*)\.(\d+)$/
+ netplan["network"]["vlans"][interface[:interface]] ||= {
+ "id" => Regexp.last_match(2).to_i,
+ "link" => Regexp.last_match(1),
+ "accept-ra" => false,
+ "addresses" => [],
+ "routes" => []
+ }
+ elsif interface[:interface] =~ /^bond\d+$/
+ netplan["network"]["bonds"][interface[:interface]] ||= {
+ "accept-ra" => false,
+ "addresses" => [],
+ "routes" => []
+ }
+ else
+ netplan["network"]["ethernets"][interface[:interface]] ||= {
+ "accept-ra" => false,
+ "addresses" => [],
+ "routes" => []
+ }
+ end
+
+ if interface[:address]
+ deviceplan["addresses"].push("#{interface[:address]}/#{prefix}")
+ end
+
+ if interface[:mtu]
+ deviceplan["mtu"] = interface[:mtu]
+ end
+
+ if interface[:bond]
+ deviceplan["interfaces"] = interface[:bond][:slaves].to_a
+
+ deviceplan["parameters"] = {
+ "mode" => interface[:bond][:mode] || "active-backup",
+ "mii-monitor-interval" => interface[:bond][:miimon] || 100,
+ "down-delay" => interface[:bond][:downdelay] || 200,
+ "up-delay" => interface[:bond][:updelay] || 200
+ }
+
+ deviceplan["parameters"]["primary"] = interface[:bond][:slaves].first if deviceplan["parameters"]["mode"] == "active-backup"
+ deviceplan["parameters"]["transmit-hash-policy"] = interface[:bond][:xmithashpolicy] if interface[:bond][:xmithashpolicy]
+ deviceplan["parameters"]["lacp-rate"] = interface[:bond][:lacprate] if interface[:bond][:lacprate]
+ end
+
+ if interface[:gateway] && interface[:gateway] != interface[:address]
+ if interface[:family] == "inet"
+ default_route = "0.0.0.0/0"
+ elsif interface[:family] == "inet6"
+ default_route = "::/0"