diff options
author | Tom Doherty <tom.doherty@fixnetix.com> | 2017-09-08 14:05:10 +0100 |
---|---|---|
committer | Tom Doherty <tom.doherty@fixnetix.com> | 2017-09-08 14:05:10 +0100 |
commit | b8ebe375fae24a35deac44b62a020fba6890b506 (patch) | |
tree | d0275252764317b01c086ee08a37c94bc0023646 /lib/chef/provider | |
parent | 48defc6e5a8a89a37b4327dcafee9a3a4d9a2457 (diff) | |
download | chef-b8ebe375fae24a35deac44b62a020fba6890b506.tar.gz |
Allow specifying default gateway on RHEL/Centos
Signed-off-by: Tom Doherty <tom.doherty@fixnetix.com>
Diffstat (limited to 'lib/chef/provider')
-rw-r--r-- | lib/chef/provider/route.rb | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/chef/provider/route.rb b/lib/chef/provider/route.rb index 59d516be6a..56689c8364 100644 --- a/lib/chef/provider/route.rb +++ b/lib/chef/provider/route.rb @@ -86,12 +86,15 @@ class Chef self.is_running = false # cidr or quad dot mask - new_ip = if new_resource.netmask + new_ip = if new_resource.target == "default" + nil + elsif new_resource.netmask IPAddr.new("#{new_resource.target}/#{new_resource.netmask}") else IPAddr.new(new_resource.target) end + return unless new_ip # For linux, we use /proc/net/route file to read proc table info return if node[:os] != "linux" @@ -172,7 +175,15 @@ class Chef conf[dev] = "" if conf[dev].nil? case @action when :add - conf[dev] << config_file_contents(:add, target: resource.target, netmask: resource.netmask, gateway: resource.gateway) if resource.action == [:add] + if resource.target == "default" + network_file_name = "/etc/sysconfig/network" + network_file = Chef::Util::FileEdit.new network_file_name + network_file.search_file_replace_line /^GATEWAY=/, "GATEWAY=#{resource.gateway}" + network_file.insert_line_if_no_match /^GATEWAY=/, "GATEWAY=#{resource.gateway}" + network_file.write_file + else + conf[dev] << config_file_contents(:add, target: resource.target, netmask: resource.netmask, gateway: resource.gateway) if resource.action == [:add] + end when :delete # need to do this for the case when the last route on an int # is removed @@ -197,9 +208,14 @@ class Chef case action when :add - command = [ "ip", "route", "replace", target ] - command += [ "via", new_resource.gateway ] if new_resource.gateway - command += [ "dev", new_resource.device ] if new_resource.device + if target == "default" + command = [ "ip", "route", "replace", target ] + command += [ "via", new_resource.gateway ] if new_resource.gateway + else + command = [ "ip", "route", "replace", target ] + command += [ "via", new_resource.gateway ] if new_resource.gateway + command += [ "dev", new_resource.device ] if new_resource.device + end when :delete command = [ "ip", "route", "delete", target ] command += [ "via", new_resource.gateway ] if new_resource.gateway |