From 029f7d64551dad5564258554f79a7c75be40334b Mon Sep 17 00:00:00 2001 From: Evgeniy Nikulin Date: Thu, 11 Nov 2021 18:00:44 +0300 Subject: [PATCH 1/2] adding diff output when interface config is changing --- lib/cumulus/ifupdown2.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/cumulus/ifupdown2.rb b/lib/cumulus/ifupdown2.rb index 5712ada..a44751c 100644 --- a/lib/cumulus/ifupdown2.rb +++ b/lib/cumulus/ifupdown2.rb @@ -1,6 +1,8 @@ require 'json' +require 'puppet/util/diff' # defines functions that read and write ifquery output class Ifupdown2Config + include Puppet::Util::Diff attr_accessor :confighash, :currenthash def initialize(resource) @resource = resource @@ -38,10 +40,36 @@ def remove_nil_entries(myhash) end def compare_with_current + diff_config remove_nil_entries(@confighash) == remove_nil_entries(@currenthash) end + # diff between old and new config + def diff_config + filepath = @resource[:location] + '/' + @resource[:name] + if Puppet::FileSystem.exist?(filepath) + tmp_intf = hash_to_if + if !tmp_intf.empty? + tmp_filepath = '/tmp/puppet-temp-iface-' + @resource[:name] + rand(36**8).to_s(36) + begin + ifacefile = File.open(tmp_filepath, 'w') + ifacefile.write(tmp_intf) + ensure + ifacefile.close + end + diff = Puppet::Util::Diff.diff(filepath, tmp_filepath) + if !diff.empty? + Puppet.info "config diff for #{@resource[:name]}" + Puppet.notice "#{diff}" + end + if File.exist?(tmp_filepath) + File.delete(tmp_filepath) + end + end + end + end + ## # Use ifquery to generate a configuration from a hash and return the # configuration. From 0b0f742b9fc1d2865183e625fbe0beadc040fcb6 Mon Sep 17 00:00:00 2001 From: Evgeniy Nikulin Date: Thu, 11 Nov 2021 18:00:57 +0300 Subject: [PATCH 2/2] bump release --- metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.json b/metadata.json index e3dcb58..ff2f5da 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "c2devel-cumulus_interfaces", - "version": "1.2.8", + "version": "1.2.10", "author": "Cumulus Networks", "summary": "Configures Cumulus Linux interfaces", "license": "GPLv2",