summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-10-09 10:50:07 -0500
committerLuke Kanies <luke@madstop.com>2007-10-09 10:50:07 -0500
commitafa1dee5eb3a8b5249715e61f9894b04ab34a6ae (patch)
tree71f3d553f38a1f3c873038dcd26d2376064ee6b6 /lib/puppet
parent275af562b462813ddf5ddbad2192ddc2bf57770c (diff)
parent1befcc46926a27ec5f799d6ad8caa59c3b808c4c (diff)
downloadpuppet-afa1dee5eb3a8b5249715e61f9894b04ab34a6ae.tar.gz
puppet-afa1dee5eb3a8b5249715e61f9894b04ab34a6ae.tar.xz
puppet-afa1dee5eb3a8b5249715e61f9894b04ab34a6ae.zip
Merge branch 'routing' of http://git.rickbradley.com/puppet into routing
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/defaults.rb9
-rw-r--r--lib/puppet/feature/base.rb2
-rw-r--r--lib/puppet/indirector/indirection.rb67
-rw-r--r--lib/puppet/indirector/ldap/node.rb7
-rw-r--r--lib/puppet/network/http_server.rb3
-rw-r--r--lib/puppet/network/http_server/mongrel.rb (renamed from lib/puppet/network/server/mongrel.rb)4
-rw-r--r--lib/puppet/network/http_server/webrick.rb (renamed from lib/puppet/network/server/webrick.rb)4
-rw-r--r--lib/puppet/network/rest_server.rb37
-rw-r--r--lib/puppet/network/server.rb66
-rw-r--r--lib/puppet/property.rb3
-rwxr-xr-xlib/puppet/provider/package/dpkg.rb9
-rwxr-xr-xlib/puppet/provider/package/sun.rb2
-rw-r--r--lib/puppet/provider/service/freebsd.rb46
13 files changed, 167 insertions, 92 deletions
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
index 1b0b402ec..6ea4eef4c 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -500,15 +500,6 @@ module Puppet
"The server through which to send email reports."]
)
- # This needs to be in main because it's used too early in the system, such that
- # we get an infinite loop otherwise.
- self.setdefaults(:main,
- :facts_terminus => ["yaml",
- "The backend store to use for client facts."],
- :checksum_terminus => ["file",
- "The backend store to use for storing files by checksum (i.e., filebuckets)."]
- )
-
self.setdefaults(:rails,
:dblocation => { :default => "$statedir/clientconfigs.sqlite3",
:mode => 0660,
diff --git a/lib/puppet/feature/base.rb b/lib/puppet/feature/base.rb
index 6368d0931..518e9b419 100644
--- a/lib/puppet/feature/base.rb
+++ b/lib/puppet/feature/base.rb
@@ -18,7 +18,7 @@ Puppet.features.add(:libshadow, :libs => ["shadow"])
Puppet.features.add(:root) { require 'puppet/util/suidmanager'; Puppet::Util::SUIDManager.uid == 0 }
# We've got mongrel available
-Puppet.features.add(:mongrel, :libs => %w{rubygems mongrel puppet/network/server/mongrel})
+Puppet.features.add(:mongrel, :libs => %w{rubygems mongrel puppet/network/http_server/mongrel})
# We have lcs diff
Puppet.features.add :diff, :libs => %w{diff/lcs diff/lcs/hunk}
diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb
index 9cc116e40..3a6284877 100644
--- a/lib/puppet/indirector/indirection.rb
+++ b/lib/puppet/indirector/indirection.rb
@@ -17,34 +17,26 @@ class Puppet::Indirector::Indirection
# Create and return our cache terminus.
def cache
- terminus(cache_name)
+ raise(Puppet::DevError, "Tried to cache when no cache class was set") unless cache_class
+ terminus(cache_class)
end
# Should we use a cache?
def cache?
- cache_name ? true : false
- end
-
- # Figure out the cache name, if there is one. If there's no name, then
- # caching is disabled.
- def cache_name
- unless @cache_name
- setting_name = "%s_cache" % self.name
- if ! Puppet.settings.valid?(setting_name) or (value = Puppet.settings[setting_name] and value == "none")
- @cache_name = nil
- else
- @cache_name = value
- @cache_name = @cache_name.intern if @cache_name.is_a?(String)
- end
- end
- @cache_name
+ cache_class ? true : false
+ end
+
+ attr_reader :cache_class
+ # Define a terminus class to be used for caching.
+ def cache_class=(class_name)
+ validate_terminus_class(class_name)
+ @cache_class = class_name
end
# Clear our cached list of termini, and reset the cache name
# so it's looked up again.
# This is only used for testing.
def clear_cache
- @cache_name = nil
@termini.clear
end
@@ -65,7 +57,7 @@ class Puppet::Indirector::Indirection
end
@termini = {}
@terminus_types = {}
- @cache_name = nil
+ @cache_class = nil
raise(ArgumentError, "Indirection %s is already defined" % @name) if @@indirections.find { |i| i.name == @name }
@@indirections << self
end
@@ -73,22 +65,31 @@ class Puppet::Indirector::Indirection
# Return the singleton terminus for this indirection.
def terminus(terminus_name = nil)
# Get the name of the terminus.
- unless terminus_name
- param_name = "%s_terminus" % self.name
- if Puppet.settings.valid?(param_name)
- terminus_name = Puppet.settings[param_name]
- else
- terminus_name = Puppet[:default_terminus]
- end
- unless terminus_name and terminus_name.to_s != ""
- raise ArgumentError, "Invalid terminus name %s" % terminus_name.inspect
- end
- terminus_name = terminus_name.intern if terminus_name.is_a?(String)
+ unless terminus_name ||= terminus_class
+ raise Puppet::DevError, "No terminus specified for %s; cannot redirect" % self.name
end
return @termini[terminus_name] ||= make_terminus(terminus_name)
end
+ attr_reader :terminus_class
+
+ # Specify the terminus class to use.
+ def terminus_class=(terminus_class)
+ validate_terminus_class(terminus_class)
+ @terminus_class = terminus_class
+ end
+
+ # This is used by terminus_class= and cache=.
+ def validate_terminus_class(terminus_class)
+ unless terminus_class and terminus_class.to_s != ""
+ raise ArgumentError, "Invalid terminus name %s" % terminus_class.inspect
+ end
+ unless Puppet::Indirector::Terminus.terminus_class(terminus_class, self.name)
+ raise ArgumentError, "Could not find terminus %s for indirection %s" % [terminus_class, self.name]
+ end
+ end
+
def find(*args)
terminus.find(*args)
end
@@ -111,10 +112,10 @@ class Puppet::Indirector::Indirection
private
# Create a new terminus instance.
- def make_terminus(name)
+ def make_terminus(terminus_class)
# Load our terminus class.
- unless klass = Puppet::Indirector::Terminus.terminus_class(name, self.name)
- raise ArgumentError, "Could not find terminus %s for indirection %s" % [name, self.name]
+ unless klass = Puppet::Indirector::Terminus.terminus_class(terminus_class, self.name)
+ raise ArgumentError, "Could not find terminus %s for indirection %s" % [terminus_class, self.name]
end
return klass.new
end
diff --git a/lib/puppet/indirector/ldap/node.rb b/lib/puppet/indirector/ldap/node.rb
index 6f35b575c..2e800abbe 100644
--- a/lib/puppet/indirector/ldap/node.rb
+++ b/lib/puppet/indirector/ldap/node.rb
@@ -21,8 +21,11 @@ class Puppet::Indirector::Ldap::Node < Puppet::Indirector::Ldap
raise ArgumentError, "Found loop in LDAP node parents; %s appears twice" % parent
end
parents << parent
- ldapsearch(parent) do |entry|
- parent_info = process(parent, entry)
+
+ ldapsearch(parent) { |entry| parent_info = process(parent, entry) }
+
+ unless parent_info
+ raise Puppet::Error.new("Could not find parent node '%s'" % parent)
end
information[:classes] += parent_info[:classes]
parent_info[:parameters].each do |param, value|
diff --git a/lib/puppet/network/http_server.rb b/lib/puppet/network/http_server.rb
new file mode 100644
index 000000000..e3826a654
--- /dev/null
+++ b/lib/puppet/network/http_server.rb
@@ -0,0 +1,3 @@
+# Just a stub, so we can correctly scope other classes.
+module Puppet::Network::HTTPServer # :nodoc:
+end
diff --git a/lib/puppet/network/server/mongrel.rb b/lib/puppet/network/http_server/mongrel.rb
index 8cd7e807b..ba4b048b3 100644
--- a/lib/puppet/network/server/mongrel.rb
+++ b/lib/puppet/network/http_server/mongrel.rb
@@ -31,7 +31,7 @@ require 'rubygems'
require 'mongrel'
require 'xmlrpc/server'
require 'puppet/network/xmlrpc/server'
-require 'puppet/network/server'
+require 'puppet/network/http_server'
require 'puppet/network/client_request'
require 'puppet/daemon'
@@ -49,7 +49,7 @@ require 'resolv'
# handler.xmlrpc_server.add_handler("my.add") { |a, b| a.to_i + b.to_i }
# </pre>
module Puppet::Network
- class Server::Mongrel < ::Mongrel::HttpHandler
+ class HTTPServer::Mongrel < ::Mongrel::HttpHandler
include Puppet::Daemon
attr_reader :xmlrpc_server
diff --git a/lib/puppet/network/server/webrick.rb b/lib/puppet/network/http_server/webrick.rb
index dd9a91c7c..2cf85b7b6 100644
--- a/lib/puppet/network/server/webrick.rb
+++ b/lib/puppet/network/http_server/webrick.rb
@@ -6,7 +6,7 @@ require 'fcntl'
require 'puppet/sslcertificates/support'
require 'puppet/network/xmlrpc/webrick_servlet'
-require 'puppet/network/server'
+require 'puppet/network/http_server'
require 'puppet/network/client'
module Puppet
@@ -14,7 +14,7 @@ module Puppet
module Network
# The old-school, pure ruby webrick server, which is the default serving
# mechanism.
- class Server::WEBrick < WEBrick::HTTPServer
+ class HTTPServer::WEBrick < WEBrick::HTTPServer
include Puppet::Daemon
include Puppet::SSLCertificates::Support
diff --git a/lib/puppet/network/rest_server.rb b/lib/puppet/network/rest_server.rb
deleted file mode 100644
index d1206928c..000000000
--- a/lib/puppet/network/rest_server.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-class Puppet::Network::RESTServer
- attr_reader :server
-
- def initialize(args = {})
- raise(ArgumentError, "requires :server to be specified") unless args[:server]
- @routes = {}
- @listening = false
- @server = args[:server]
- end
-
- def register(*indirections)
- raise ArgumentError, "indirection names are required" if indirections.empty?
- indirections.flatten.each { |i| @routes[i.to_sym] = true }
- end
-
- def unregister(*indirections)
- indirections = @routes.keys if indirections.empty?
- indirections.flatten.each do |i|
- raise(ArgumentError, "indirection [%s] is not known" % i) unless @routes[i.to_sym]
- @routes.delete(i.to_sym)
- end
- end
-
- def listening?
- @listening
- end
-
- def listen
- raise "Cannot listen -- already listening" if listening?
- @listening = true
- end
-
- def unlisten
- raise "Cannot unlisten -- not currently listening" unless listening?
- @listening = false
- end
-end
diff --git a/lib/puppet/network/server.rb b/lib/puppet/network/server.rb
index 0dee30b10..84a71a6b4 100644
--- a/lib/puppet/network/server.rb
+++ b/lib/puppet/network/server.rb
@@ -1,4 +1,66 @@
-# Just a stub, so we can correctly scope other classes.
-module Puppet::Network::Server # :nodoc:
+class Puppet::Network::Server
+ attr_reader :server_type
+
+ # which HTTP server subclass actually handles web requests of a certain type? (e.g., :rest => RESTServer)
+ def self.server_class_by_name(name)
+ klass = (name.to_s + 'Server').to_sym
+ const_get klass
+ end
+
+ # we will actually return an instance of the Server subclass which handles the HTTP web server, instead of
+ # an instance of this generic Server class. A tiny bit of sleight-of-hand is necessary to make this happen.
+ def self.new(args = {})
+ server_type = Puppet[:servertype] or raise "No servertype configuration found."
+ obj = self.server_class_by_name(server_type).allocate
+ obj.send :initialize, args.merge(:server_type => server_type)
+ obj
+ end
+
+ def initialize(args = {})
+ @routes = {}
+ @listening = false
+ @server_type = args[:server_type]
+ self.register(args[:handlers]) if args[:handlers]
+ end
+
+ def register(*indirections)
+ raise ArgumentError, "indirection names are required" if indirections.empty?
+ indirections.flatten.each { |i| @routes[i.to_sym] = true }
+ end
+
+ def unregister(*indirections)
+ indirections = @routes.keys if indirections.empty?
+ indirections.flatten.each do |i|
+ raise(ArgumentError, "indirection [%s] is not known" % i) unless @routes[i.to_sym]
+ @routes.delete(i.to_sym)
+ end
+ end
+
+ def listening?
+ @listening
+ end
+
+ def listen
+ raise "Cannot listen -- already listening" if listening?
+ start_web_server
+ @listening = true
+ end
+
+ def unlisten
+ raise "Cannot unlisten -- not currently listening" unless listening?
+ stop_web_server
+ @listening = false
+ end
+
+ private
+
+ def start_web_server
+ raise NotImplementedError, "this method needs to be implemented by the actual web server (sub)class"
+ end
+
+ def stop_web_server
+ raise NotImplementedError, "this method needs to be implemented by the actual web server (sub)class"
+ end
end
+
diff --git a/lib/puppet/property.rb b/lib/puppet/property.rb
index cd3c35b38..84620bfb6 100644
--- a/lib/puppet/property.rb
+++ b/lib/puppet/property.rb
@@ -56,8 +56,7 @@ class Property < Puppet::Parameter
# Look up a value's name, so we can find options and such.
def self.value_name(value)
- name = symbolize(value)
- if @parametervalues[name]
+ if value != '' and name = symbolize(value) and @parametervalues.include?(name)
return name
elsif ary = self.match?(value)
return ary[0]
diff --git a/lib/puppet/provider/package/dpkg.rb b/lib/puppet/provider/package/dpkg.rb
index 44e6a985c..512170a73 100755
--- a/lib/puppet/provider/package/dpkg.rb
+++ b/lib/puppet/provider/package/dpkg.rb
@@ -56,9 +56,18 @@ Puppet::Type.type(:package).provide :dpkg, :parent => Puppet::Provider::Package
dpkg "-i", file
end
+ def update
+ self.install
+ end
+
# Return the version from the package.
def latest
output = dpkg_deb "--show", @resource[:source]
+ matches = /^(\S+)\t(\S+)$/.match(output).captures
+ unless matches[0].match(@resource[:name])
+ Puppet.warning "source doesn't contain named package, but %s" % matches[0]
+ end
+ matches[1]
end
def query
diff --git a/lib/puppet/provider/package/sun.rb b/lib/puppet/provider/package/sun.rb
index e204e6d58..927596df2 100755
--- a/lib/puppet/provider/package/sun.rb
+++ b/lib/puppet/provider/package/sun.rb
@@ -51,8 +51,6 @@ Puppet::Type.type(:package).provide :sun, :parent => Puppet::Provider::Package d
unless names[name].nil?
hash[names[name]] = value
end
- else
- raise "Could not find %s" % name
end
when /\s+\d+.+/:
# nothing; we're ignoring the FILES info
diff --git a/lib/puppet/provider/service/freebsd.rb b/lib/puppet/provider/service/freebsd.rb
new file mode 100644
index 000000000..31fdacb86
--- /dev/null
+++ b/lib/puppet/provider/service/freebsd.rb
@@ -0,0 +1,46 @@
+# Manage FreeBSD services.
+Puppet::Type.type(:service).provide :freebsd, :parent => :init do
+ desc "FreeBSD's (and probably NetBSD?) form of ``init``-style service
+ management; uses ``rc-update`` for service enabling and disabling."
+
+ commands :rcupdate => "/usr/local/sbin/rc-update"
+
+ defaultfor :operatingsystem => :freebsd
+
+ def self.defpath
+ superclass.defpath
+ end
+
+ def disable
+ begin
+ output = rcupdate("disable", @model[:name])
+ rescue Puppet::ExecutionFailure
+ raise Puppet::Error, "Could not disable %s: %s" %
+ [self.name, output]
+ end
+ end
+
+ def enabled?
+ begin
+ output = rcupdate("enabled", @model[:name])
+ rescue Puppet::ExecutionFailure
+ return :false
+ end
+
+ # If it's enabled, output is 0
+ if output =~ /^0$/
+ return :true
+ end
+
+ return :false
+ end
+
+ def enable
+ begin
+ output = rcupdate("enable", @model[:name])
+ rescue Puppet::ExecutionFailure => detail
+ raise Puppet::Error, "Could not enable %s: %s" %
+ [self.name, detail]
+ end
+ end
+end