class Puppet::Environments::Directories
Reads environments from a directory on disk. Each environment is represented as a sub-directory. The environment's manifest setting is the `manifest` directory of the environment directory. The environment's modulepath setting is the global modulepath (from the `[server]` section for the server) prepended with the `modules` directory of the environment directory.
@api private
Public Class Methods
from_path(path, global_module_path)
click to toggle source
Generate an array of directory loaders from a path string. @param path [String] path to environment directories @param global_module_path [Array<String>] the global modulepath setting @return [Array<Puppet::Environments::Directories>] An array
of configured directory loaders.
# File lib/puppet/environments.rb 190 def self.from_path(path, global_module_path) 191 environments = path.split(File::PATH_SEPARATOR) 192 environments.map do |dir| 193 Puppet::Environments::Directories.new(dir, global_module_path) 194 end 195 end
new(environment_dir, global_module_path)
click to toggle source
# File lib/puppet/environments.rb 178 def initialize(environment_dir, global_module_path) 179 @environment_dir = Puppet::FileSystem.expand_path(environment_dir) 180 @global_module_path = global_module_path ? 181 global_module_path.map { |p| Puppet::FileSystem.expand_path(p) } : 182 nil 183 end
real_path(dir)
click to toggle source
# File lib/puppet/environments.rb 197 def self.real_path(dir) 198 if Puppet::FileSystem.symlink?(dir) && Puppet[:versioned_environment_dirs] 199 dir = Pathname.new Puppet::FileSystem.expand_path(Puppet::FileSystem.readlink(dir)) 200 end 201 return dir 202 end
Public Instance Methods
get(name)
click to toggle source
@!macro loader_get
# File lib/puppet/environments.rb 217 def get(name) 218 if validated_directory(File.join(@environment_dir, name.to_s)) 219 create_environment(name) 220 end 221 end
get_conf(name)
click to toggle source
@!macro loader_get_conf
# File lib/puppet/environments.rb 224 def get_conf(name) 225 envdir = validated_directory(File.join(@environment_dir, name.to_s)) 226 if envdir 227 Puppet::Settings::EnvironmentConf.load_from(envdir, @global_module_path) 228 else 229 nil 230 end 231 end
list()
click to toggle source
@!macro loader_list
# File lib/puppet/environments.rb 210 def list 211 valid_environment_names.collect do |name| 212 create_environment(name) 213 end 214 end
search_paths()
click to toggle source
@!macro loader_search_paths
# File lib/puppet/environments.rb 205 def search_paths 206 ["file://#{@environment_dir}"] 207 end
Private Instance Methods
create_environment(name)
click to toggle source
# File lib/puppet/environments.rb 235 def create_environment(name) 236 # interpolated modulepaths may be cached from prior environment instances 237 Puppet.settings.clear_environment_settings(name) 238 239 env_symbol = name.intern 240 setting_values = Puppet.settings.values(env_symbol, Puppet.settings.preferred_run_mode) 241 env = Puppet::Node::Environment.create( 242 env_symbol, 243 Puppet::Node::Environment.split_path(setting_values.interpolate(:modulepath)), 244 setting_values.interpolate(:manifest), 245 setting_values.interpolate(:config_version) 246 ) 247 248 configured_path = File.join(@environment_dir, name.to_s) 249 env.configured_path = configured_path 250 if Puppet.settings[:report_configured_environmentpath] 251 env.resolved_path = validated_directory(configured_path) 252 else 253 env.resolved_path = configured_path 254 end 255 256 env 257 end
valid_environment_names()
click to toggle source
# File lib/puppet/environments.rb 269 def valid_environment_names 270 return [] unless Puppet::FileSystem.directory?(@environment_dir) 271 Puppet::FileSystem.children(@environment_dir).map do |child| 272 Puppet::FileSystem.basename_string(child).intern if validated_directory(child) 273 end.compact 274 end
validated_directory(envdir)
click to toggle source
# File lib/puppet/environments.rb 259 def validated_directory(envdir) 260 env_name = Puppet::FileSystem.basename_string(envdir) 261 envdir = Puppet::Environments::Directories.real_path(envdir).to_s 262 if Puppet::FileSystem.directory?(envdir) && Puppet::Node::Environment.valid_name?(env_name) 263 envdir 264 else 265 nil 266 end 267 end