diff options
author | Luke Kanies <luke@madstop.com> | 2007-11-19 18:27:38 -0600 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2007-11-19 18:27:38 -0600 |
commit | 9e5fc76eb77a9b90afb384d34a8e5bf63f79af6e (patch) | |
tree | 3c07be783978ae1d03213fb073e68d2b4fa97a8a /lib/puppet/node | |
parent | cc88441a61929714fcf6a26e121d6bec2184d8eb (diff) | |
download | puppet-9e5fc76eb77a9b90afb384d34a8e5bf63f79af6e.tar.gz puppet-9e5fc76eb77a9b90afb384d34a8e5bf63f79af6e.tar.xz puppet-9e5fc76eb77a9b90afb384d34a8e5bf63f79af6e.zip |
Fixing #911 and #912 -- there's a default environment (development)
and you have to specify the valid environments for your site.
Diffstat (limited to 'lib/puppet/node')
-rw-r--r-- | lib/puppet/node/environment.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/puppet/node/environment.rb b/lib/puppet/node/environment.rb new file mode 100644 index 000000000..ada7f4eea --- /dev/null +++ b/lib/puppet/node/environment.rb @@ -0,0 +1,45 @@ +# Model the environment that a node can operate in. This class just +# provides a simple wrapper for the functionality around environments. +class Puppet::Node::Environment + # Return the list of valid environments. Just looks them up in + # the settings. + def self.valid + Puppet.settings.value(:environments).split(",").collect { |e| e.to_sym } + end + + # Is the provided environment valid? + def self.valid?(name) + valid.include?(name.to_sym) + end + + @seen = {} + + # Return an existing environment instance, or create a new one, + # validating the environment name. + def self.new(name = nil) + name ||= Puppet.settings.value(:environment) + + raise ArgumentError, "Environment name must be specified" unless name + + raise(ArgumentError, "'%s' is not a valid environment" % name) unless valid?(name) + + symbol = name.to_sym + + return @seen[symbol] if @seen[symbol] + + obj = self.allocate + obj.send :initialize, symbol + @seen[symbol] = obj + end + + attr_reader :name + + # Return an environment-specific setting. + def [](param) + Puppet.settings.value(param, self.name) + end + + def initialize(name) + @name = name + end +end |