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 189 def self.from_path(path, global_module_path) 190 environments = path.split(File::PATH_SEPARATOR) 191 environments.map do |dir| 192 Puppet::Environments::Directories.new(dir, global_module_path) 193 end 194 end
new(environment_dir, global_module_path)
click to toggle source
# File lib/puppet/environments.rb 177 def initialize(environment_dir, global_module_path) 178 @environment_dir = Puppet::FileSystem.expand_path(environment_dir) 179 @global_module_path = global_module_path ? 180 global_module_path.map { |p| Puppet::FileSystem.expand_path(p) } : 181 nil 182 end
real_path(dir)
click to toggle source
# File lib/puppet/environments.rb 196 def self.real_path(dir) 197 if Puppet::FileSystem.symlink?(dir) && Puppet[:versioned_environment_dirs] 198 dir = Pathname.new Puppet::FileSystem.expand_path(Puppet::FileSystem.readlink(dir)) 199 end 200 return dir 201 end
Public Instance Methods
get(name)
click to toggle source
@!macro loader_get
# File lib/puppet/environments.rb 216 def get(name) 217 if validated_directory(File.join(@environment_dir, name.to_s)) 218 create_environment(name) 219 end 220 end
get_conf(name)
click to toggle source
@!macro loader_get_conf
# File lib/puppet/environments.rb 223 def get_conf(name) 224 envdir = validated_directory(File.join(@environment_dir, name.to_s)) 225 if envdir 226 Puppet::Settings::EnvironmentConf.load_from(envdir, @global_module_path) 227 else 228 nil 229 end 230 end
list()
click to toggle source
@!macro loader_list
# File lib/puppet/environments.rb 209 def list 210 valid_environment_names.collect do |name| 211 create_environment(name) 212 end 213 end
search_paths()
click to toggle source
@!macro loader_search_paths
# File lib/puppet/environments.rb 204 def search_paths 205 ["file://#{@environment_dir}"] 206 end
Private Instance Methods
create_environment(name)
click to toggle source
# File lib/puppet/environments.rb 234 def create_environment(name) 235 # interpolated modulepaths may be cached from prior environment instances 236 Puppet.settings.clear_environment_settings(name) 237 238 env_symbol = name.intern 239 setting_values = Puppet.settings.values(env_symbol, Puppet.settings.preferred_run_mode) 240 env = Puppet::Node::Environment.create( 241 env_symbol, 242 Puppet::Node::Environment.split_path(setting_values.interpolate(:modulepath)), 243 setting_values.interpolate(:manifest), 244 setting_values.interpolate(:config_version) 245 ) 246 env 247 end
valid_environment_names()
click to toggle source
# File lib/puppet/environments.rb 259 def valid_environment_names 260 return [] unless Puppet::FileSystem.directory?(@environment_dir) 261 Puppet::FileSystem.children(@environment_dir).map do |child| 262 Puppet::FileSystem.basename_string(child).intern if validated_directory(child) 263 end.compact 264 end
validated_directory(envdir)
click to toggle source
# File lib/puppet/environments.rb 249 def validated_directory(envdir) 250 env_name = Puppet::FileSystem.basename_string(envdir) 251 envdir = Puppet::Environments::Directories.real_path(envdir).to_s 252 if Puppet::FileSystem.directory?(envdir) && Puppet::Node::Environment.valid_name?(env_name) 253 envdir 254 else 255 nil 256 end 257 end