Skip to content

Commit

Permalink
Merge pull request #8 from Karmkor/add_config_diff
Browse files Browse the repository at this point in the history
Adding diff output when interface config is changing
  • Loading branch information
odivlad authored Nov 11, 2021
2 parents f3cfdee + 0b0f742 commit b215e32
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions lib/cumulus/ifupdown2.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit b215e32

Please sign in to comment.