Class: Puppet::CatalogDiff::FindCatalogs

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/catalog-diff/findcatalogs.rb

Overview

FindCatalogs allows to find pairs of catalogs in two directories

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(old_catalog_path, new_catalog_path) ⇒ FindCatalogs

Returns a new instance of FindCatalogs.



8
9
10
11
# File 'lib/puppet/catalog-diff/findcatalogs.rb', line 8

def initialize(old_catalog_path, new_catalog_path)
  @old_catalog_path = old_catalog_path
  @new_catalog_path = new_catalog_path
end

Instance Attribute Details

#new_catalog_pathObject

Returns the value of attribute new_catalog_path.



6
7
8
# File 'lib/puppet/catalog-diff/findcatalogs.rb', line 6

def new_catalog_path
  @new_catalog_path
end

#old_catalog_pathObject

Returns the value of attribute old_catalog_path.



6
7
8
# File 'lib/puppet/catalog-diff/findcatalogs.rb', line 6

def old_catalog_path
  @old_catalog_path
end

Instance Method Details

#find_catalogs(catalog_path) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/puppet/catalog-diff/findcatalogs.rb', line 13

def find_catalogs(catalog_path)
  found_catalogs = []
  Dir.glob("#{catalog_path}/*.{yaml,marshal,pson,json}") do |catalog_file|
    found_catalogs << catalog_file
  end
  Puppet.debug("Found catalogs #{found_catalogs.size} in #{catalog_path}")
  found_catalogs
end

#return_catalogs(_options = {}) ⇒ Object



48
49
50
51
52
# File 'lib/puppet/catalog-diff/findcatalogs.rb', line 48

def return_catalogs(_options = {})
  old = find_catalogs(old_catalog_path)
  new = find_catalogs(new_catalog_path)
  return_matching_catalogs(old, new)
end

#return_filename_hash(paths) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/puppet/catalog-diff/findcatalogs.rb', line 22

def return_filename_hash(paths)
  # create a hash of the results with the filename as the key
  results_hash = {}
  paths.each do |path|
    filename = File.basename(path)
    results_hash[filename] = path
  end
  results_hash
end

#return_matching_catalogs(old_results, new_results) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/puppet/catalog-diff/findcatalogs.rb', line 32

def return_matching_catalogs(old_results, new_results)
  # return a hash with new_path => old_path for all matching results
  new_results = return_filename_hash(new_results)
  old_results = return_filename_hash(old_results)
  matching_catalogs = {}
  new_results.each do |filename, new_path|
    if old_results.key?(filename)
      Puppet.debug("Found matching catalog for #{new_path}")
      matching_catalogs[new_results[filename]] = old_results[filename]
    else
      Puppet.err("Missing partner catalog for #{filename}")
    end
  end
  matching_catalogs
end