Class: Puppet::Resource::Catalog::Compiler

Inherits:
Indirector::Code show all
Includes:
Util, Util::Checksums
Defined in:
lib/puppet/indirector/catalog/compiler.rb

Constant Summary

Constants included from Util::Checksums

Util::Checksums::KNOWN_CHECKSUMS

Constants included from Util

Util::ALNUM, Util::ALPHA, Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE, Util::ESCAPED, Util::HEX, Util::HttpProxy, Util::PUPPET_STACK_INSERTION_FRAME, Util::RESERVED, Util::RFC_3986_URI_REGEX, Util::UNRESERVED, Util::UNSAFE

Constants included from Util::POSIX

Util::POSIX::LOCALE_ENV_VARS, Util::POSIX::USER_ENV_VARS

Constants included from Util::SymbolicFileMode

Util::SymbolicFileMode::SetGIDBit, Util::SymbolicFileMode::SetUIDBit, Util::SymbolicFileMode::StickyBit, Util::SymbolicFileMode::SymbolicMode, Util::SymbolicFileMode::SymbolicSpecialToBit

Constants included from Util::Docs

Util::Docs::HEADER_LEVELS

Instance Attribute Summary collapse

Attributes included from Util::Docs

#doc, #nodoc

Instance Method Summary collapse

Methods included from Util::Checksums

checksum?, checksum_file, checksum_stream, ctime, ctime?, ctime_file, ctime_stream, known_checksum_types, md5, md5?, md5_file, md5_hex_length, md5_stream, md5lite, md5lite?, md5lite_file, md5lite_hex_length, md5lite_stream, mtime, mtime?, mtime_file, mtime_stream, none, none?, none_file, none_stream, sha1, sha1?, sha1_file, sha1_hex_length, sha1_stream, sha1lite, sha1lite?, sha1lite_file, sha1lite_hex_length, sha1lite_stream, sha224, sha224?, sha224_file, sha224_hex_length, sha224_stream, sha256, sha256?, sha256_file, sha256_hex_length, sha256_stream, sha256lite, sha256lite?, sha256lite_file, sha256lite_hex_length, sha256lite_stream, sha384, sha384?, sha384_file, sha384_hex_length, sha384_stream, sha512, sha512?, sha512_file, sha512_hex_length, sha512_stream, sumdata, sumtype, valid_checksum?

Methods included from Util

absolute_path?, benchmark, chuser, clear_environment, create_erb, default_env, deterministic_rand, deterministic_rand_int, exit_on_fail, format_backtrace_array, format_puppetstack_frame, get_env, get_environment, logmethods, merge_environment, path_to_uri, pretty_backtrace, replace_file, resolve_stackframe, rfc2396_escape, safe_posix_fork, set_env, skip_external_facts, symbolizehash, thinmark, uri_encode, uri_query_encode, uri_to_path, uri_unescape, which, withenv, withumask

Methods included from Util::POSIX

#get_posix_field, #gid, groups_of, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid

Methods included from Util::SymbolicFileMode

#display_mode, #normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?

Methods inherited from Indirector::Terminus

abstract_terminus?, #allow_remote_requests?, const2name, #indirection, indirection_name, inherited, mark_as_abstract_terminus, #model, model, #name, name2const, register_terminus_class, terminus_class, terminus_classes, #terminus_type, #validate, #validate_key, #validate_model

Methods included from Util::InstanceLoader

#instance_hash, #instance_load, #instance_loader, #instance_loading?, #loaded_instance, #loaded_instances

Methods included from Util::Docs

#desc, #dochook, #doctable, #markdown_definitionlist, #markdown_header, #nodoc?, #pad, scrub

Constructor Details

#initializeCompiler

Returns a new instance of Compiler.



98
99
100
101
102
# File 'lib/puppet/indirector/catalog/compiler.rb', line 98

def initialize
  Puppet::Util::Profiler.profile(_("Setup server facts for compiling"), [:compiler, :init_server_facts]) do
    set_server_facts
  end
end

Instance Attribute Details

#codeObject



19
20
21
# File 'lib/puppet/indirector/catalog/compiler.rb', line 19

def code
  @code
end

Instance Method Details

#extract_facts_from_request(request) ⇒ Puppet::Node::Facts

Returns facts object corresponding to facts in request.

Parameters:

Returns:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/puppet/indirector/catalog/compiler.rb', line 24

def extract_facts_from_request(request)
  text_facts = request.options[:facts]
  return unless text_facts

  format = request.options[:facts_format]
  unless format
    raise ArgumentError, _("Facts but no fact format provided for %{request}") % { request: request.key }
  end

  Puppet::Util::Profiler.profile(_("Found facts"), [:compiler, :find_facts]) do
    facts = text_facts.is_a?(Puppet::Node::Facts) ? text_facts :
                                                    convert_wire_facts(text_facts, format)

    unless facts.name == request.key
      raise Puppet::Error, _("Catalog for %{request} was requested with fact definition for the wrong node (%{fact_name}).") % { request: request.key.inspect, fact_name: facts.name.inspect }
    end

    return facts
  end
end

#filter(catalog) ⇒ Object

filter-out a catalog to remove exported resources



92
93
94
95
96
# File 'lib/puppet/indirector/catalog/compiler.rb', line 92

def filter(catalog)
  return catalog.filter(&:virtual?) if catalog.respond_to?(:filter)

  catalog
end

#find(request) ⇒ Object

Compile a node’s catalog.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/puppet/indirector/catalog/compiler.rb', line 52

def find(request)
  facts = extract_facts_from_request(request)

  save_facts_from_request(facts, request) unless facts.nil?

  node = node_from_request(facts, request)
  node.trusted_data = Puppet.lookup(:trusted_information) { Puppet::Context::TrustedInformation.local(node) }.to_h

  if node.environment
    # If the requested environment name doesn't match the server specified environment
    # name, as determined by the node terminus, and the request wants us to check for an
    # environment mismatch, then return an empty catalog with the server-specified
    # enviroment.
    if request.remote? && request.options[:check_environment]
      # The "environment" may be same while environment objects differ. This
      # is most likely because the environment cache was flushed between the request
      # processing and node lookup. Environment overrides `==` but requires the
      # name and modulepath to be the same. When using versioned environment dirs the
      # same "environment" can have different modulepaths so simply compare names here.
      if node.environment.name != request.environment.name
        Puppet.warning _("Requested environment '%{request_env}' did not match server specified environment '%{server_env}'") % { request_env: request.environment.name, server_env: node.environment.name }
        return Puppet::Resource::Catalog.new(node.name, node.environment)
      end
    end

    node.environment.with_text_domain do
      envs = Puppet.lookup(:environments)
      envs.guard(node.environment.name)
      begin
        compile(node, request.options)
      ensure
        envs.unguard(node.environment.name)
      end
    end
  else
    compile(node, request.options)
  end
end

#networked?Boolean

Is our compiler part of a network, or are we just local?

Returns:

  • (Boolean)


105
106
107
# File 'lib/puppet/indirector/catalog/compiler.rb', line 105

def networked?
  Puppet.run_mode.server?
end

#require_environment?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/puppet/indirector/catalog/compiler.rb', line 109

def require_environment?
  false
end

#save_facts_from_request(facts, request) ⇒ Object



45
46
47
48
49
# File 'lib/puppet/indirector/catalog/compiler.rb', line 45

def save_facts_from_request(facts, request)
  Puppet::Node::Facts.indirection.save(facts, nil,
                                       :environment => request.environment,
                                       :transaction_uuid => request.options[:transaction_uuid])
end