1
# the available clients
4
require 'puppet/network/xmlrpc/client'
5
require 'puppet/util/subclass_loader'
6
require 'puppet/util/methodhelper'
7
require 'puppet/sslcertificates/support'
9
require 'puppet/network/handler'
13
# Some versions of ruby don't have this method defined, which basically causes
14
# us to never use ssl. Yay.
24
# JJM: This is a "backport" of sorts to older ruby versions which
25
# do not have this accessor. See #896 for more information.
26
attr_accessor :enable_post_connection_check unless Net::HTTP.method_defined? "enable_post_connection_check"
29
# The base class for all of the clients. Many clients just directly
30
# call methods, but some of them need to do some extra work or
31
# provide a different interface.
32
class Puppet::Network::Client
35
extend Puppet::Util::SubclassLoader
36
include Puppet::Util::MethodHelper
38
# This handles reading in the key and such-like.
39
include Puppet::SSLCertificates::Support
41
attr_accessor :schedule, :lastrun, :local, :stopping
45
# Set up subclass loading
46
handle_subclasses :client, "puppet/network/client"
48
# Determine what clients look for when being passed an object for local
49
# client/server stuff. E.g., you could call Client::CA.new(:CA => ca).
51
@drivername ||= self.name
54
# Figure out the handler for our client.
56
@handler ||= Puppet::Network::Handler.handler(self.name)
59
# The class that handles xmlrpc interaction for us.
60
def self.xmlrpc_client
61
@xmlrpc_client ||= Puppet::Network::XMLRPCClient.handler_class(self.handler)
66
# to whom do we connect?
69
if hash.include?(:Cache)
75
driverparam = self.class.drivername
76
if hash.include?(:Server)
77
args = {:Server => hash[:Server]}
78
@server = hash[:Server]
79
args[:Port] = hash[:Port] || Puppet[:masterport]
81
@driver = self.class.xmlrpc_client.new(args)
85
# We have to start the HTTP connection manually before we start
86
# sending it requests or keep-alive won't work. Note that with #1010,
87
# we don't currently actually want keep-alive.
88
@driver.start if @driver.respond_to? :start and Puppet::Network::HttpPool.keep_alive?
91
elsif hash.include?(driverparam)
92
@driver = hash[driverparam]
94
@driver = self.class.handler.new
98
raise Puppet::Network::ClientError, "#{self.class} must be passed a Server or #{driverparam}"
102
# Are we a local client?
111
# Make sure we set the driver up when we read the cert in.
112
def recycle_connection
113
@driver.recycle_connection if @driver.respond_to?(:recycle_connection)
116
# A wrapper method to run and then store the last run time
119
Puppet.notice "In shutdown progress; skipping run"
124
self.lastrun = Time.now.to_i
126
puts detail.backtrace if Puppet[:trace]
127
Puppet.err "Could not run #{self.class}: #{detail}"
132
raise Puppet::DevError, "Client type #{self.class} did not override run"
136
if sched = self.schedule
137
return sched.match?(self.lastrun)
145
Puppet.notice "Already in shutdown"
148
Puppet::Util::Storage.store if self.respond_to? :running? and self.running?
153
# Start listening for events. We're pretty much just listening for
156
# Create our timer. Puppet will handle observing it and such.
158
timer = Puppet.newtimer(
160
:interval => Puppet[:runinterval],
166
self.runnow if self.scheduled?
168
puts detail.backtrace if Puppet[:trace]
169
Puppet.err "Could not run client; got otherwise uncaught exception: #{detail}"
173
# Run once before we start following the timer
177
require 'puppet/network/client/proxy'