Skip to content

Commit

Permalink
Attempt to stabilize module against centos7+8
Browse files Browse the repository at this point in the history
- Fix Style issues
- Keep full mask in route structure to pass tests but use prefix when writing file

Signed-off-by: Gino <onigino@protonmail.com>
  • Loading branch information
Gino McCarty committed May 6, 2022
1 parent 38124e8 commit a3e7c2c
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions lib/puppet/provider/network_route/redhat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,15 @@ def self.parse_file(_filename, contents)
new_route[:options] = route[5] if route[5]

if route[0] == 'default'
cidr_target = 'default'

new_route[:name] = cidr_target
new_route[:name] = 'default'
new_route[:network] = 'default'
new_route[:netmask] = '0.0.0.0'
else
# use the CIDR version of the target as :name
network, netmask = route[0].split('/')
cidr_target = "#{network}/#{IPAddr.new(netmask).to_i.to_s(2).count('1')}"

new_route[:name] = cidr_target
new_route[:network] = network
new_route[:netmask] = netmask
ip = IPAddr.new(route[0])
netmask = IPAddr.new("255.255.255.255/#{ip.prefix}")
new_route[:name] = "#{ip}/#{ip.prefix}"
new_route[:network] = ip.to_s
new_route[:netmask] = netmask.to_s
end

routes << new_route
Expand All @@ -84,7 +80,8 @@ def self.format_file(_filename, providers)
contents << if provider.network == 'default'
"#{provider.network} via #{provider.gateway} dev #{provider.interface}"
else
"#{provider.network}/#{provider.netmask} via #{provider.gateway} dev #{provider.interface}"
ip = IPAddr.new("#{provider.network}/#{provider.netmask}")
"#{ip}/#{ip.prefix} via #{provider.gateway} dev #{provider.interface}"
end
contents << (provider.options == :absent ? "\n" : " #{provider.options}\n")
end
Expand Down

0 comments on commit a3e7c2c

Please sign in to comment.