From d8a9a4f2b6fdab7e0de8b4bff2ea20ce8204a768 Mon Sep 17 00:00:00 2001 From: "Bernhard M. Wiedemann" Date: Thu, 23 Feb 2017 15:12:42 +0100 Subject: [PATCH 1/2] network: refactor nic cleanup --- chef/cookbooks/network/recipes/default.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/chef/cookbooks/network/recipes/default.rb b/chef/cookbooks/network/recipes/default.rb index 43583ce57a..82643bf369 100644 --- a/chef/cookbooks/network/recipes/default.rb +++ b/chef/cookbooks/network/recipes/default.rb @@ -122,21 +122,19 @@ def kill_nic(nic) 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 + nicfiles.each do |file| + ::File.delete(file) if ::File.exists?(file) end end From 46b856b9b4cfdd4d17690fc9efdb7519af34002c Mon Sep 17 00:00:00 2001 From: "Bernhard M. Wiedemann" Date: Thu, 23 Feb 2017 15:15:37 +0100 Subject: [PATCH 2/2] network: allow unmanaged network interfaces --- chef/cookbooks/network/recipes/default.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/chef/cookbooks/network/recipes/default.rb b/chef/cookbooks/network/recipes/default.rb index 82643bf369..ccfa0531bd 100644 --- a/chef/cookbooks/network/recipes/default.rb +++ b/chef/cookbooks/network/recipes/default.rb @@ -119,9 +119,6 @@ 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" @@ -133,8 +130,17 @@ def kill_nic(nic) 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.exists?(file) + ::File.delete(file) if ::File.exist?(file) end end