diff options
author | Luke Kanies <luke@madstop.com> | 2007-11-20 01:08:34 -0600 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2007-11-20 01:08:34 -0600 |
commit | 8cc07adda20b4e63bbad5b2759303d00d215341c (patch) | |
tree | e8157ba56cabb51ba67d9eb8d355a40ef4e96c4c /lib/puppet/node.rb | |
parent | 53008e567fd64f391e0b45652b2f4ac1551ccf47 (diff) | |
download | puppet-8cc07adda20b4e63bbad5b2759303d00d215341c.tar.gz puppet-8cc07adda20b4e63bbad5b2759303d00d215341c.tar.xz puppet-8cc07adda20b4e63bbad5b2759303d00d215341c.zip |
Using the Environment class to determine the default environment,
rather than plenty of different places having the logic of how
to determine the default environment.
Diffstat (limited to 'lib/puppet/node.rb')
-rw-r--r-- | lib/puppet/node.rb | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/puppet/node.rb b/lib/puppet/node.rb index 9758c895c..2d87b6515 100644 --- a/lib/puppet/node.rb +++ b/lib/puppet/node.rb @@ -3,6 +3,7 @@ require 'puppet/indirector' # A simplistic class for managing the node information itself. class Puppet::Node require 'puppet/node/facts' + require 'puppet/node/environment' # Set up indirection, so that nodes can be looked for in # the node sources. @@ -19,19 +20,23 @@ class Puppet::Node attr_accessor :name, :classes, :parameters, :source, :ipaddress, :names attr_reader :time - attr_writer :environment + + # Set the environment, making sure that it's valid. + def environment=(value) + raise(ArgumentError, "Invalid environment %s" % value) unless Puppet::Node::Environment.valid?(value) + @environment = value + end # Do not return environments that are the empty string, and use # explicitly set environments, then facts, then a central env # value. def environment - unless @environment and @environment != "" - if env = parameters["environment"] and env != "" - @environment = env - elsif env = Puppet[:environment] and env != "" + unless @environment + if env = parameters["environment"] + raise(ArgumentError, "Invalid environment %s from parameters" % env) unless Puppet::Node::Environment.valid?(env) @environment = env else - @environment = nil + @environment = Puppet::Node::Environment.new.name.to_s end end @environment @@ -66,7 +71,7 @@ class Puppet::Node @parameters = options[:parameters] || {} - @environment = options[:environment] + self.environment = options[:environment] if options[:environment] @time = Time.now end |