Class: Puppet::Settings::EnvironmentConf Private

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/settings/environment_conf.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Configuration settings for a single directory Environment.

Defined Under Namespace

Classes: Static

Constant Summary collapse

ENVIRONMENT_CONF_ONLY_SETTINGS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

[:modulepath, :manifest, :config_version].freeze
VALID_SETTINGS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

(ENVIRONMENT_CONF_ONLY_SETTINGS + [:environment_timeout, :environment_data_provider, :static_catalogs, :rich_data]).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path_to_env, section, global_module_path) ⇒ EnvironmentConf

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create through EnvironmentConf.load_from()



49
50
51
52
53
# File 'lib/puppet/settings/environment_conf.rb', line 49

def initialize(path_to_env, section, global_module_path)
  @path_to_env = path_to_env
  @section = section
  @global_module_path = global_module_path
end

Instance Attribute Details

#global_modulepathObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



46
47
48
# File 'lib/puppet/settings/environment_conf.rb', line 46

def global_modulepath
  @global_modulepath
end

#path_to_envObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



46
47
48
# File 'lib/puppet/settings/environment_conf.rb', line 46

def path_to_env
  @path_to_env
end

#sectionObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



46
47
48
# File 'lib/puppet/settings/environment_conf.rb', line 46

def section
  @section
end

Class Method Details

.load_from(path_to_env, global_module_path) ⇒ EnvironmentConf

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

logs warnings if the environment.conf contains any ini sections,

Given a path to a directory environment, attempts to load and parse an environment.conf in ini format, and return an EnvironmentConf instance.

An environment.conf is optional, so if the file itself is missing, or empty, an EnvironmentConf with default values will be returned.

or has settings other than the three handled for directory environments (:manifest, :modulepath, :config_version)

Parameters:

  • path_to_env (String)

    path to the directory environment

  • global_module_path (Array<String>)

    the installation’s base modulepath setting, appended to default environment modulepaths

Returns:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/puppet/settings/environment_conf.rb', line 22

def self.load_from(path_to_env, global_module_path)
  path_to_env = File.expand_path(path_to_env)
  conf_file = File.join(path_to_env, 'environment.conf')
  config = nil

  begin
    config = Puppet.settings.parse_file(conf_file)
    validate(conf_file, config)
    section = config.sections[:main]
  rescue Errno::ENOENT
    # environment.conf is an optional file
  end

  new(path_to_env, section, global_module_path)
end

.static_for(environment, environment_timeout = 0, static_catalogs = false, rich_data = false) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Provides a configuration object tied directly to the passed environment. Configuration values are exactly those returned by the environment object, without interpolation. This is a special case for the default configured environment returned by the Puppet::Environments::StaticPrivate loader.



42
43
44
# File 'lib/puppet/settings/environment_conf.rb', line 42

def self.static_for(environment, environment_timeout = 0, static_catalogs = false, rich_data = false)
  Static.new(environment, environment_timeout, static_catalogs, nil, rich_data)
end

Instance Method Details

#config_versionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



123
124
125
126
127
# File 'lib/puppet/settings/environment_conf.rb', line 123

def config_version
  get_setting(:config_version) do |config_version|
    absolute(config_version)
  end
end

#environment_data_providerObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



95
96
97
98
99
# File 'lib/puppet/settings/environment_conf.rb', line 95

def environment_data_provider
  get_setting(:environment_data_provider, Puppet.settings.value(:environment_data_provider)) do |value|
    value
  end
end

#environment_timeoutObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



85
86
87
88
89
90
91
92
93
# File 'lib/puppet/settings/environment_conf.rb', line 85

def environment_timeout
  # gen env specific config or use the default value
  get_setting(:environment_timeout, Puppet.settings.value(:environment_timeout)) do |ttl|
    # munges the string form statically without really needed the settings system, only
    # its ability to munge "4s, 3m, 5d, and 'unlimited' into seconds - if already munged into
    # numeric form, the TTLSetting handles that.
    Puppet::Settings::TTLSetting.munge(ttl, 'environment_timeout')
  end
end

#manifestObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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
# File 'lib/puppet/settings/environment_conf.rb', line 55

def manifest
  puppet_conf_manifest = Pathname.new(Puppet.settings.value(:default_manifest))
  disable_per_environment_manifest = Puppet.settings.value(:disable_per_environment_manifest)

  fallback_manifest_directory =
  if puppet_conf_manifest.absolute?
    puppet_conf_manifest.to_s
  else
    File.join(@path_to_env, puppet_conf_manifest.to_s)
  end

  if disable_per_environment_manifest
    environment_conf_manifest = absolute(raw_setting(:manifest))
    if environment_conf_manifest && fallback_manifest_directory != environment_conf_manifest
      errmsg = ["The 'disable_per_environment_manifest' setting is true, but the",
      "environment located at #{@path_to_env} has a manifest setting in its",
      "environment.conf of '#{environment_conf_manifest}' which does not match",
      "the default_manifest setting '#{puppet_conf_manifest}'. If this",
      "environment is expecting to find modules in",
      "'#{environment_conf_manifest}', they will not be available!"]
      Puppet.err(errmsg.join(' '))
    end
    fallback_manifest_directory.to_s
  else
    get_setting(:manifest, fallback_manifest_directory) do |manifest|
      absolute(manifest)
    end
  end
end

#modulepathObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



101
102
103
104
105
106
107
108
109
# File 'lib/puppet/settings/environment_conf.rb', line 101

def modulepath
  default_modulepath = [File.join(@path_to_env, "modules")] + @global_module_path
  get_setting(:modulepath, default_modulepath) do |modulepath|
    path = modulepath.kind_of?(String) ?
      modulepath.split(File::PATH_SEPARATOR) :
      modulepath
    path.map { |p| absolute(p) }.join(File::PATH_SEPARATOR)
  end
end

#raw_setting(setting_name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



129
130
131
132
# File 'lib/puppet/settings/environment_conf.rb', line 129

def raw_setting(setting_name)
  setting = section.setting(setting_name) if section
  setting.value if setting
end

#rich_dataObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



111
112
113
114
115
# File 'lib/puppet/settings/environment_conf.rb', line 111

def rich_data
  get_setting(:rich_data, Puppet.settings.value(:rich_data)) do |value|
    value
  end
end

#static_catalogsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



117
118
119
120
121
# File 'lib/puppet/settings/environment_conf.rb', line 117

def static_catalogs
  get_setting(:static_catalogs, Puppet.settings.value(:static_catalogs)) do |value|
    value
  end
end