diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/defaults.rb | 13 | ||||
-rw-r--r-- | lib/puppet/node/environment.rb | 45 |
2 files changed, 54 insertions, 4 deletions
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index a3991bbaa..da830952a 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -127,10 +127,15 @@ module Puppet namespaces and methods. This can be used as a coarse-grained authorization system for both ``puppetd`` and ``puppetmasterd``." ], - :environment => ["", "The environment Puppet is running in. For clients (e.g., ``puppetd``) this - determines the environment itself, which is used to find modules and much more. For - servers (i.e., ``puppetmasterd``) this provides the default environment for nodes we - know nothing about."], + :environments => ["production,development", "The valid environments for Puppet clients. + This is more useful as a server-side setting than client, but any + environment chosen must be in this list. Values should be + separated by a comma."], + :environment => ["development", "The environment Puppet is running in. For clients + (e.g., ``puppetd``) this determines the environment itself, which + is used to find modules and much more. For servers (i.e., + ``puppetmasterd``) this provides the default environment for nodes + we know nothing about."], :diff_args => ["", "Which arguments to pass to the diff command when printing differences between files."], :diff => ["diff", "Which diff command to use when printing differences between files."], :show_diff => [false, "Whether to print a contextual diff when files are being replaced. The diff 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 |