Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/puppet/provider/network_config/interfaces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def self.raise_malformed
raise MalformedInterfacesError
end

def order_rules
@resource[:order_rules]
end

class Instance
attr_reader :name

Expand Down Expand Up @@ -240,6 +244,10 @@ def self.parse_file(_filename, contents)
Instance.all_instances.map { |_name, instance| instance.to_hash }
end

def self.interface_order(name, rules)
(rules['rules'].map { |entry| entry.last if name.match(entry.first) } + [rules['default']]).compact.first
end

# Generate an array of sections
def self.format_file(_filename, providers)
contents = []
Expand All @@ -249,20 +257,20 @@ def self.format_file(_filename, providers)
auto_interfaces = providers.select { |provider| provider.onboot == true }
unless auto_interfaces.empty?
stanza = []
stanza << ('auto ' + auto_interfaces.map(&:name).sort.join(' '))
stanza << ('auto ' + auto_interfaces.sort_by { |provider| interface_order(provider.name, provider.order_rules) }.map(&:name).join(' '))
contents << stanza.join("\n")
end

# Add hotpluggable interfaces
hotplug_interfaces = providers.select { |provider| provider.hotplug == true }
unless hotplug_interfaces.empty?
stanza = []
stanza << ('allow-hotplug ' + hotplug_interfaces.map(&:name).sort.join(' '))
stanza << ('allow-hotplug ' + hotplug_interfaces.sort_by { |provider| interface_order(provider.name, provider.order_rules) }.map(&:name).join(' '))
contents << stanza.join("\n")
end

# Build iface stanzas
providers.sort_by(&:name).each do |provider|
providers.sort_by { |provider| interface_order(provider.name, provider.order_rules) }.each do |provider|
# TODO: add validation method
raise Puppet::Error, "#{provider.name} does not have a method." if provider.method.nil?
raise Puppet::Error, "#{provider.name} does not have a family." if provider.family.nil?
Expand Down
4 changes: 4 additions & 0 deletions lib/puppet/type/network_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@
desc 'Reconfigure the interface after the configuration has been updated'
end

newparam(:order_rules) do
desc 'Specify order rules of interfaces'
end

newproperty(:mtu) do
desc 'The Maximum Transmission Unit size to use for the interface'
validate do |value|
Expand Down
5 changes: 5 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
$ipaddress_provider = 'puppet_gem',
$manage_ipaddress = true,
$ensure_ipaddress = absent,
$order_rules = { 'default' => 10, 'rules' => [[/^lo$/, 2], [/^lo:\d+$/, 6], [/^bond\d+$/, 11], [/^bond\d+:\d+$/, 12], [/\.\d+$/, 13], [/^(lxc)?br\d+$/, 14], [/^gre\d+$/, 15]] },
) {
if $facts['os']['family'] == 'Debian' and $manage_ifupdown_extra {
package { $ifupdown_extra:
Expand All @@ -78,4 +79,8 @@
}
Package[$ipaddress] -> Network_config <| |>
}

Network_config <| |> {
order_rules => $order_rules,
}
}