summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2005-08-02 00:24:18 +0000
committerLuke Kanies <luke@madstop.com>2005-08-02 00:24:18 +0000
commit74dac8fd6f46c35cf79b15f1f7358bc32d4c7716 (patch)
tree8b123cbd0b481d443cb882c704e7f2e16934d702 /lib
parent8bf85e2faeb8a4776b64cf6cebac4733ff3739d5 (diff)
downloadpuppet-74dac8fd6f46c35cf79b15f1f7358bc32d4c7716.tar.gz
puppet-74dac8fd6f46c35cf79b15f1f7358bc32d4c7716.tar.xz
puppet-74dac8fd6f46c35cf79b15f1f7358bc32d4c7716.zip
adding some consistency and tests to the whole puppet defaults system
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@485 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet.rb75
-rw-r--r--lib/puppet/client.rb4
-rwxr-xr-xlib/puppet/filebucket.rb2
-rw-r--r--lib/puppet/storage.rb22
-rw-r--r--lib/puppet/type.rb14
-rwxr-xr-xlib/puppet/type/pfilebucket.rb4
6 files changed, 84 insertions, 37 deletions
diff --git a/lib/puppet.rb b/lib/puppet.rb
index 99ab48860..67b407ae3 100644
--- a/lib/puppet.rb
+++ b/lib/puppet.rb
@@ -15,6 +15,25 @@ require 'puppet/log'
#
# it's also a place to find top-level commands like 'debug'
module Puppet
+# if Process.uid == 0
+# PUPPETCONF = "/etc/puppet"
+# PUPPETVAR = "/var/puppet"
+# else
+# PUPPETCONF = File.expand_path("~/.puppet")
+# PUPPETVAR = File.expand_path("~/.puppet/var")
+# end
+#
+# CERTDIR = File.join(PUPPETCONF, "certs")
+# CERTFILE = File.join(CERTDIR, "localhost.crt")
+# CERTKEY = File.join(CERTDIR, "localhost.key")
+#
+# RRDDIR = File.join(PUPPETROOT, "rrd")
+# LOGDIR = File.join(PUPPETROOT, "log")
+# LOGFILE = File.join(LOGDIR, "puppet.log")
+#
+# STATEDIR = File.join(PUPPETROOT, "state")
+# CHECKSUMFILE = File.join(STATEDIR, "checksums")
+#
class Error < RuntimeError
attr_accessor :stack, :line, :file
def initialize(message)
@@ -51,6 +70,11 @@ module Puppet
# configuration parameter access and stuff
def self.[](param)
+ if param.is_a?(String)
+ param = param.intern
+ elsif ! param.is_a?(Symbol)
+ raise ArgumentError, "Invalid parameter type %s" % param.class
+ end
case param
when :debug:
if Puppet::Log.level == :debug
@@ -63,7 +87,44 @@ module Puppet
when :logdest:
return Puppet::Log.destination
else
- return @@config[param]
+ if @@config.include?(param)
+ return @@config[param]
+ else
+ # here's where we define our defaults
+ returnval = case param
+ when :puppetconf:
+ if Process.uid == 0
+ "/etc/puppet"
+ else
+ File.expand_path("~/.puppet/var")
+ end
+ when :puppetvar:
+ if Process.uid == 0
+ "/var/puppet"
+ else
+ File.expand_path("~/.puppet")
+ end
+ when :rrdgraph: false
+ when :noop: false
+ when :puppetport: 8139
+ when :masterport: 8140
+ when :rrddir: File.join(self[:puppetvar], "rrd")
+ when :logdir: File.join(self[:puppetvar], "log")
+ when :bucketdir: File.join(self[:puppetvar], "bucket")
+ when :logfile: File.join(self[:logdir], "puppet.log")
+ when :statedir: File.join(self[:puppetvar], "state")
+ when :checksumfile: File.join(self[:statedir], "checksums")
+ when :certdir: File.join(self[:puppetconf], "certs")
+ when :localcert: File.join(self[:certdir], "localhost.crt")
+ when :localkey: File.join(self[:certdir], "localhost.key")
+ when :localpub: File.join(self[:certdir], "localhost.pub")
+ when :mastercert: File.join(self[:certdir], "puppetmaster.crt")
+ when :masterkey: File.join(self[:certdir], "puppetmaster.key")
+ when :masterpub: File.join(self[:certdir], "puppetmaster.pub")
+ else
+ raise ArgumentError, "Invalid parameter %s" % param
+ end
+ end
end
end
@@ -100,18 +161,6 @@ module Puppet
end
}
end
-
- self[:rrdgraph] = false
- if Process.uid == 0
- self[:puppetroot] = "/var/puppet"
- else
- self[:puppetroot] = File.expand_path("~/.puppet")
- end
-
- self[:rrddir] = File.join(self[:puppetroot],"rrd")
- self[:logdir] = File.join(self[:puppetroot],"log")
- self[:logfile] = File.join(self[:puppetroot],"log/puppet.log")
- self[:statefile] = File.join(self[:puppetroot],"log/state")
end
require 'puppet/type'
diff --git a/lib/puppet/client.rb b/lib/puppet/client.rb
index e4dd00801..d96bc158d 100644
--- a/lib/puppet/client.rb
+++ b/lib/puppet/client.rb
@@ -141,9 +141,9 @@ module Puppet
Puppet::Storage.init
Puppet::Storage.load
rescue => detail
- Puppet.err "Corrupt state file %s" % Puppet[:statefile]
+ Puppet.err "Corrupt state file %s" % Puppet[:checksumfile]
begin
- File.unlink(Puppet[:statefile])
+ File.unlink(Puppet[:checksumfile])
retry
rescue => detail
raise Puppet::Error.new("Cannot remove %s: %s" %
diff --git a/lib/puppet/filebucket.rb b/lib/puppet/filebucket.rb
index e67b58668..f0e717146 100755
--- a/lib/puppet/filebucket.rb
+++ b/lib/puppet/filebucket.rb
@@ -61,7 +61,7 @@ module FileBucket
hash.delete(:Path)
else
if defined? Puppet
- @bucket = File.join(Puppet[:puppetroot], "bucket")
+ @bucket = Puppet[:bucketdir]
else
@bucket = File.expand_path("~/.filebucket")
end
diff --git a/lib/puppet/storage.rb b/lib/puppet/storage.rb
index 67c2dbeab..c7c4a7ae1 100644
--- a/lib/puppet/storage.rb
+++ b/lib/puppet/storage.rb
@@ -25,16 +25,16 @@ module Puppet
self.init
def self.load
- if Puppet[:statefile].nil?
+ if Puppet[:checksumfile].nil?
raise "Somehow the statefile is nil"
end
- unless File.exists?(Puppet[:statefile])
- Puppet.info "Statefile %s does not exist" % Puppet[:statefile]
+ unless File.exists?(Puppet[:checksumfile])
+ Puppet.info "Statefile %s does not exist" % Puppet[:checksumfile]
return
end
- #Puppet.debug "Loading statefile %s" % Puppet[:statefile]
- File.open(Puppet[:statefile]) { |file|
+ #Puppet.debug "Loading statefile %s" % Puppet[:checksumfile]
+ File.open(Puppet[:checksumfile]) { |file|
file.each { |line|
myclass, key, value = line.split(@@splitchar)
@@ -61,22 +61,22 @@ module Puppet
end
def self.store
- unless FileTest.directory?(File.dirname(Puppet[:statefile]))
+ unless FileTest.directory?(File.dirname(Puppet[:checksumfile]))
begin
- Puppet.recmkdir(File.dirname(Puppet[:statefile]))
+ Puppet.recmkdir(File.dirname(Puppet[:checksumfile]))
Puppet.info "Creating state directory %s" %
- File.dirname(Puppet[:statefile])
+ File.dirname(Puppet[:checksumfile])
rescue => detail
Puppet.err "Could not create state file: %s" % detail
return
end
end
- unless FileTest.exist?(Puppet[:statefile])
- Puppet.info "Creating state file %s" % Puppet[:statefile]
+ unless FileTest.exist?(Puppet[:checksumfile])
+ Puppet.info "Creating state file %s" % Puppet[:checksumfile]
end
- File.open(Puppet[:statefile], File::CREAT|File::WRONLY, 0600) { |file|
+ File.open(Puppet[:checksumfile], File::CREAT|File::WRONLY, 0600) { |file|
@@state.each { |klass, thash|
thash.each { |key,value|
mvalue = Marshal::dump(value)
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 4f58a971c..b96b01daa 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -57,7 +57,7 @@ class Type < Puppet::Element
#@paramdoc = Hash.new
# the methods that can be called from within the language
- @allowedmethods = [:noop,:debug,:statefile]
+ @allowedmethods = [:noop,:debug,:checksumfile]
# the parameters that all instances will accept
@@metaparams = [
@@ -246,7 +246,7 @@ class Type < Puppet::Element
def Type.statefile(value)
if value =~ /^\//
- Puppet[:statefile] = value
+ Puppet[:checksumfile] = value
else
raise "Statefile %s must be fully qualified" % value
end
@@ -1076,14 +1076,14 @@ class Type < Puppet::Element
end # Puppet::Type
end
-require 'puppet/type/service'
+require 'puppet/statechange'
+require 'puppet/type/component'
require 'puppet/type/exec'
-require 'puppet/type/filebucket'
+require 'puppet/type/package'
require 'puppet/type/pfile'
+require 'puppet/type/pfilebucket'
+require 'puppet/type/service'
require 'puppet/type/symlink'
-require 'puppet/type/package'
-require 'puppet/type/component'
-require 'puppet/statechange'
#require 'puppet/type/typegen'
#require 'puppet/type/typegen/filetype'
#require 'puppet/type/typegen/filerecord'
diff --git a/lib/puppet/type/pfilebucket.rb b/lib/puppet/type/pfilebucket.rb
index 16a323960..7fa059979 100755
--- a/lib/puppet/type/pfilebucket.rb
+++ b/lib/puppet/type/pfilebucket.rb
@@ -43,9 +43,7 @@ module Puppet
)
end
else
- @parameters[:path] ||= File.join(
- Puppet[:puppetroot], "bucket"
- )
+ @parameters[:path] ||= Puppet[:bucketdir]
begin
@bucket = FileBucket::Dipper.new(
:Path => @parameters[:path]