Module: Puppet::CatalogDiff::Preprocessor

Included in:
CompileCatalog, Differ
Defined in:
lib/puppet/catalog-diff/preprocessor.rb

Overview

Puppet::CatalogDiff::Preprocessor provides methods to convert catalogs to the catalog-diff intermediate format

Instance Method Summary collapse

Instance Method Details

#capitalizeresource(resource) ⇒ Object

capitalize a resource from [“class”, “foo::bar”] to Class

Dear Puppet 0.24. Die.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/puppet/catalog-diff/preprocessor.rb', line 10

def capitalizeresource(resource)
  res = ''

  if resource[0] =~ %r{class}i
    res << 'Class['
    res << resource[1].split(%r{::}).map(&:capitalize).join('::')
    res << ']'
  else
    res << resource[0].capitalize
    res << '[' << resource[1] << ']'
  end

  res
end

#convert25(resource, collector) ⇒ Object

Converts Puppet 0.25 and 2.6.x catalogs to our intermediate format



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/puppet/catalog-diff/preprocessor.rb', line 26

def convert25(resource, collector)
  if resource.is_a?(Puppet::Resource::Catalog)
    resource.edges.each do |b|
      convert25(b, collector)
    end
  elsif resource.is_a?(Puppet::Relationship) && resource.target.is_a?(Puppet::Resource) && resource.target.title
    target = resource.target

    resource = { type: target.type,
                 title: target.title,
                 parameters: {} }

    target.each do |param, value|
      resource[:parameters][param] = value
    end

    resource[:parameters][:content] = { checksum: Digest::MD5.hexdigest(resource[:parameters][:content]), content: resource[:parameters][:content] } if resource[:parameters].include?(:content) && resource[:parameters][:content].is_a?(String)

    resource[:resource_id] = "#{target.type.downcase}[#{target.title}]"
    collector << resource
  end
end

#convert_pdb(catalog) ⇒ Object

Converts PuppetDB catalogs to our intermediate format



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/puppet/catalog-diff/preprocessor.rb', line 50

def convert_pdb(catalog)
  catalog = catalog[0]
  # Fix "data" level in PuppetDB catalog
  catalog['resources'] = catalog['resources']['data']
  # Fix edges
  new_edges = []
  catalog['edges']['data'].each do |edge|
    new_edges << {
      'source' => "#{edge['source_type']}[#{edge['source_title']}]",
      'target' => "#{edge['target_type']}[#{edge['target_title']}]",
    }
  end
  catalog['edges'] = new_edges
  catalog
end