Class: Puppet::Node::Environment
- Includes:
- Util::Cacher
- Defined in:
- lib/puppet/node/environment.rb
Overview
Model the environment that a node can operate in. This class just provides a simple wrapper for the functionality around environments.
Defined Under Namespace
Modules: Helper
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes included from Util::Cacher::Expirer
Class Method Summary collapse
-
.clear ⇒ Object
This is only used for testing.
- .current ⇒ Object
- .current=(env) ⇒ Object
-
.new(name = nil) ⇒ Object
Return an existing environment instance, or create a new one.
- .root ⇒ Object
Instance Method Summary collapse
-
#[](param) ⇒ Object
Return an environment-specific setting.
-
#initialize(name) ⇒ Environment
constructor
A new instance of Environment.
- #known_resource_types ⇒ Object
- #module(name) ⇒ Object
- #to_s ⇒ Object
- #to_sym ⇒ Object
-
#to_zaml(z) ⇒ Object
The only thing we care about when serializing an environment is its identity; everything else is ephemeral and should not be stored or transmitted.
- #validate_dirs(dirs) ⇒ Object
Methods included from Util::Cacher
Methods included from Util::Cacher::Expirer
#dependent_data_expired?, #expire
Constructor Details
#initialize(name) ⇒ Environment
Returns a new instance of Environment.
69 70 71 72 |
# File 'lib/puppet/node/environment.rb', line 69 def initialize(name) @name = name extend MonitorMixin end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
62 63 64 |
# File 'lib/puppet/node/environment.rb', line 62 def name @name end |
Class Method Details
.clear ⇒ Object
This is only used for testing.
58 59 60 |
# File 'lib/puppet/node/environment.rb', line 58 def self.clear @seen.clear end |
.current ⇒ Object
45 46 47 |
# File 'lib/puppet/node/environment.rb', line 45 def self.current Thread.current[:environment] || root end |
.current=(env) ⇒ Object
49 50 51 |
# File 'lib/puppet/node/environment.rb', line 49 def self.current=(env) Thread.current[:environment] = new(env) end |
.new(name = nil) ⇒ Object
Return an existing environment instance, or create a new one.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/puppet/node/environment.rb', line 30 def self.new(name = nil) return name if name.is_a?(self) name ||= Puppet.settings.value(:environment) raise ArgumentError, "Environment name must be specified" unless name symbol = name.to_sym return @seen[symbol] if @seen[symbol] obj = self.allocate obj.send :initialize, symbol @seen[symbol] = obj end |
Instance Method Details
#[](param) ⇒ Object
Return an environment-specific setting.
65 66 67 |
# File 'lib/puppet/node/environment.rb', line 65 def [](param) Puppet.settings.value(param, self.name) end |
#known_resource_types ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/puppet/node/environment.rb', line 74 def known_resource_types # This makes use of short circuit evaluation to get the right thread-safe # per environment semantics with an efficient most common cases; we almost # always just return our thread's known-resource types. Only at the start # of a compilation (after our thread var has been set to nil) or when the # environment has changed do we delve deeper. Thread.current[:known_resource_types] = nil if (krt = Thread.current[:known_resource_types]) && krt.environment != self Thread.current[:known_resource_types] ||= synchronize { if @known_resource_types.nil? or @known_resource_types.require_reparse? @known_resource_types = Puppet::Resource::TypeCollection.new(self) @known_resource_types.perform_initial_import end @known_resource_types } end |
#module(name) ⇒ Object
90 91 92 93 94 |
# File 'lib/puppet/node/environment.rb', line 90 def module(name) mod = Puppet::Module.new(name, self) return nil unless mod.exist? mod end |
#to_s ⇒ Object
123 124 125 |
# File 'lib/puppet/node/environment.rb', line 123 def to_s name.to_s end |
#to_sym ⇒ Object
127 128 129 |
# File 'lib/puppet/node/environment.rb', line 127 def to_sym to_s.to_sym end |
#to_zaml(z) ⇒ Object
The only thing we care about when serializing an environment is its identity; everything else is ephemeral and should not be stored or transmitted.
134 135 136 |
# File 'lib/puppet/node/environment.rb', line 134 def to_zaml(z) self.to_s.to_zaml(z) end |
#validate_dirs(dirs) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/puppet/node/environment.rb', line 138 def validate_dirs(dirs) dirs.collect do |dir| if dir !~ /^#{File::SEPARATOR}/ File.join(Dir.getwd, dir) else dir end end.find_all do |p| p =~ /^#{File::SEPARATOR}/ && FileTest.directory?(p) end end |