Skip to content
Open
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
28 changes: 16 additions & 12 deletions chef/cookbooks/network/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,28 @@ def kill_nic(nic)
# Ignore loopback interfaces for now.
return if nic.loopback?

Chef::Log.info("Interface #{nic.name} is no longer being used, deconfiguring it.")
nic.destroy

nicfiles = []
case node[:platform_family]
when "rhel"
# Redhat and Centos have lots of small files definining interfaces.
# Delete the ones we no longer care about here.
if ::File.exists?("/etc/sysconfig/network-scripts/ifcfg-#{nic.name}")
::File.delete("/etc/sysconfig/network-scripts/ifcfg-#{nic.name}")
end
nicfiles.push("/etc/sysconfig/network-scripts/ifcfg-#{nic.name}")
when "suse"
# SuSE also has lots of small files, but in slightly different locations.
if ::File.exists?("/etc/sysconfig/network/ifcfg-#{nic.name}")
::File.delete("/etc/sysconfig/network/ifcfg-#{nic.name}")
end
if ::File.exists?("/etc/sysconfig/network/ifroute-#{nic.name}")
::File.delete("/etc/sysconfig/network/ifroute-#{nic.name}")
end
nicfiles.push("/etc/sysconfig/network/ifcfg-#{nic.name}",
"/etc/sysconfig/network/ifroute-#{nic.name}")
end

# Ignore unmanaged interfaces
nicfiles.each do |file|
next unless ::File.exist?(file)
return nil if system("fgrep", "-q", "#unmanaged", file)
end
Chef::Log.info("Interface #{nic.name} is no longer being used, deconfiguring it.")
nic.destroy

nicfiles.each do |file|
::File.delete(file) if ::File.exist?(file)
end
end

Expand Down