Class: OctocatalogDiff::Catalog::Computed

Inherits:
Object
  • Object
show all
Defined in:
lib/octocatalog-diff/catalog/computed.rb

Overview

Represents a Puppet catalog that is computed (via ‘puppet master –compile …`) By instantiating this class, the catalog is computed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Computed

Constructor

Parameters:

  • :node (String)

    REQUIRED: Node name

  • :basedir (String)

    Directory in which to compile the catalog

  • :pass_env_vars (Array<String>)

    Environment variables to pass when compiling catalog

  • :retry_failed_catalog (Integer)

    Number of retries if a catalog compilation fails

  • :tag (String)

    For display purposes, the catalog being compiled

  • :puppet_binary (String)

    Full path to Puppet

  • :puppet_version (String)

    Puppet version (optional; if not supplied, it is calculated)

  • :puppet_command (String)

    Full command to run Puppet (optional; if not supplied, it is calculated)

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/octocatalog-diff/catalog/computed.rb', line 30

def initialize(options)
  raise ArgumentError, 'Usage: OctocatalogDiff::Catalog::Computed.initialize(options_hash)' unless options.is_a?(Hash)
  raise ArgumentError, 'Node name must be passed to OctocatalogDiff::Catalog::Computed' unless options[:node].is_a?(String)

  # Standard readable variables
  @node = options[:node]
  @error_message = nil
  @catalog = nil
  @catalog_json = nil

  # Additional class variables
  @pass_env_vars = options.fetch(:pass_env_vars, [])
  @retry_failed_catalog = options.fetch(:retry_failed_catalog, 0)
  @tag = options.fetch(:tag, 'catalog')
  @puppet_binary = options[:puppet_binary]
  @puppet_version = options[:puppet_version]
  @puppet_command = options[:puppet_command]
  @retries = nil
  @builddir = nil
  @facts_terminus = options.fetch(:facts_terminus, 'yaml')

  # Pass through the input for other access
  @opts = options
  raise ArgumentError, 'Branch is undefined' unless @opts[:branch]
end

Instance Attribute Details

#catalogObject (readonly)

Returns the value of attribute catalog.



19
20
21
# File 'lib/octocatalog-diff/catalog/computed.rb', line 19

def catalog
  @catalog
end

#catalog_jsonObject (readonly)

Returns the value of attribute catalog_json.



19
20
21
# File 'lib/octocatalog-diff/catalog/computed.rb', line 19

def catalog_json
  @catalog_json
end

#error_messageObject (readonly)

Returns the value of attribute error_message.



19
20
21
# File 'lib/octocatalog-diff/catalog/computed.rb', line 19

def error_message
  @error_message
end

#nodeObject (readonly)

Returns the value of attribute node.



19
20
21
# File 'lib/octocatalog-diff/catalog/computed.rb', line 19

def node
  @node
end

#retriesObject (readonly)

Returns the value of attribute retries.



19
20
21
# File 'lib/octocatalog-diff/catalog/computed.rb', line 19

def retries
  @retries
end

Instance Method Details

#build(logger = Logger.new(StringIO.new)) ⇒ Object

Actually build the catalog (populate @error_message, @catalog, @catalog_json)



57
58
59
60
61
62
63
64
65
# File 'lib/octocatalog-diff/catalog/computed.rb', line 57

def build(logger = Logger.new(StringIO.new))
  if @facts_terminus != 'facter'
    facts_obj = OctocatalogDiff::CatalogUtil::Facts.new(@opts, logger)
    logger.debug "Start retrieving facts for #{@node} from #{self.class}"
    @opts[:facts] = facts_obj.facts
    logger.debug "Success retrieving facts for #{@node} from #{self.class}"
  end
  build_catalog(logger)
end

#compilation_dirString

Compilation directory

Returns:

  • (String)

    Compilation directory



76
77
78
79
# File 'lib/octocatalog-diff/catalog/computed.rb', line 76

def compilation_dir
  raise 'Catalog was not built' if @builddir.nil?
  @builddir.tempdir
end

#environmentObject

Environment used to compile catalog



82
83
84
# File 'lib/octocatalog-diff/catalog/computed.rb', line 82

def environment
  @opts.fetch(:environment, 'production')
end

#puppet_versionString

Get the Puppet version

Returns:

Raises:

  • (ArgumentError)


69
70
71
72
# File 'lib/octocatalog-diff/catalog/computed.rb', line 69

def puppet_version
  raise ArgumentError, '"puppet_binary" was not passed to OctocatalogDiff::Catalog::Computed' unless @puppet_binary
  @puppet_version ||= OctocatalogDiff::Util::PuppetVersion.puppet_version(@puppet_binary, @opts)
end