Class: Puppet::Network::Client
- Extended by:
- Util::SubclassLoader
- Includes:
- SSLCertificates::Support, Util, Util::MethodHelper
- Defined in:
- lib/puppet/network/client.rb
Overview
The base class for all of the clients. Many clients just directly call methods, but some of them need to do some extra work or provide a different interface.
Direct Known Subclasses
Constant Summary collapse
- Client =
self
Instance Attribute Summary collapse
-
#driver ⇒ Object
readonly
Returns the value of attribute driver.
-
#lastrun ⇒ Object
Returns the value of attribute lastrun.
-
#local ⇒ Object
Returns the value of attribute local.
-
#schedule ⇒ Object
Returns the value of attribute schedule.
-
#stopping ⇒ Object
Returns the value of attribute stopping.
Attributes included from Util::SubclassLoader
Attributes included from SSLCertificates::Support
Class Method Summary collapse
-
.drivername ⇒ Object
Determine what clients look for when being passed an object for local client/server stuff.
-
.handler ⇒ Object
Figure out the handler for our client.
-
.xmlrpc_client ⇒ Object
The class that handles xmlrpc interaction for us.
Instance Method Summary collapse
-
#initialize(hash) ⇒ Client
constructor
Create our client.
-
#local? ⇒ Boolean
Are we a local client?.
-
#recycle_connection ⇒ Object
Make sure we set the driver up when we read the cert in.
- #run ⇒ Object
-
#runnow ⇒ Object
A wrapper method to run and then store the last run time.
- #scheduled? ⇒ Boolean
- #shutdown ⇒ Object
-
#start ⇒ Object
Start listening for events.
Methods included from Util::SubclassLoader
each, handle_subclasses, inherited, method_missing, name, subclasses
Methods included from SSLCertificates::Support
keytype, #rename_files_with_uppercase, #requestcert
Methods included from Util::MethodHelper
#requiredopts, #set_options, #symbolize_options
Methods included from Util
activerecord_version, benchmark, chuser, classproxy, #execfail, #execpipe, execute, logmethods, memory, proxy, recmkdir, secure_open, symbolize, symbolizehash, symbolizehash!, synchronize_on, thinmark, #threadlock, which, withumask
Methods included from Util::POSIX
#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Constructor Details
#initialize(hash) ⇒ Client
Create our client.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/puppet/network/client.rb', line 65 def initialize(hash) # to whom do we connect? @server = nil if hash.include?(:Cache) @cache = hash[:Cache] else @cache = true end driverparam = self.class.drivername if hash.include?(:Server) args = {:Server => hash[:Server]} @server = hash[:Server] args[:Port] = hash[:Port] || Puppet[:masterport] @driver = self.class.xmlrpc_client.new(args) self.read_cert # We have to start the HTTP connection manually before we start # sending it requests or keep-alive won't work. Note that with #1010, # we don't currently actually want keep-alive. @driver.start if @driver.respond_to? :start and Puppet::Network::HttpPool.keep_alive? @local = false elsif hash.include?(driverparam) @driver = hash[driverparam] if @driver == true @driver = self.class.handler.new end @local = true else raise Puppet::Network::ClientError, "#{self.class} must be passed a Server or #{driverparam}" end end |
Instance Attribute Details
#driver ⇒ Object (readonly)
Returns the value of attribute driver.
43 44 45 |
# File 'lib/puppet/network/client.rb', line 43 def driver @driver end |
#lastrun ⇒ Object
Returns the value of attribute lastrun.
41 42 43 |
# File 'lib/puppet/network/client.rb', line 41 def lastrun @lastrun end |
#local ⇒ Object
Returns the value of attribute local.
41 42 43 |
# File 'lib/puppet/network/client.rb', line 41 def local @local end |
#schedule ⇒ Object
Returns the value of attribute schedule.
41 42 43 |
# File 'lib/puppet/network/client.rb', line 41 def schedule @schedule end |
#stopping ⇒ Object
Returns the value of attribute stopping.
41 42 43 |
# File 'lib/puppet/network/client.rb', line 41 def stopping @stopping end |
Class Method Details
.drivername ⇒ Object
Determine what clients look for when being passed an object for local client/server stuff. E.g., you could call Client::CA.new(:CA => ca).
50 51 52 |
# File 'lib/puppet/network/client.rb', line 50 def self.drivername @drivername ||= self.name end |
.handler ⇒ Object
Figure out the handler for our client.
55 56 57 |
# File 'lib/puppet/network/client.rb', line 55 def self.handler @handler ||= Puppet::Network::Handler.handler(self.name) end |
.xmlrpc_client ⇒ Object
The class that handles xmlrpc interaction for us.
60 61 62 |
# File 'lib/puppet/network/client.rb', line 60 def self.xmlrpc_client @xmlrpc_client ||= Puppet::Network::XMLRPCClient.handler_class(self.handler) end |
Instance Method Details
#local? ⇒ Boolean
Are we a local client?
103 104 105 106 107 108 109 |
# File 'lib/puppet/network/client.rb', line 103 def local? if @local true else false end end |
#recycle_connection ⇒ Object
Make sure we set the driver up when we read the cert in.
112 113 114 |
# File 'lib/puppet/network/client.rb', line 112 def recycle_connection @driver.recycle_connection if @driver.respond_to?(:recycle_connection) end |
#run ⇒ Object
131 132 133 |
# File 'lib/puppet/network/client.rb', line 131 def run raise Puppet::DevError, "Client type #{self.class} did not override run" end |
#runnow ⇒ Object
A wrapper method to run and then store the last run time
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/puppet/network/client.rb', line 117 def runnow if self.stopping Puppet.notice "In shutdown progress; skipping run" return end begin self.run self.lastrun = Time.now.to_i rescue => detail puts detail.backtrace if Puppet[:trace] Puppet.err "Could not run #{self.class}: #{detail}" end end |
#scheduled? ⇒ Boolean
135 136 137 138 139 140 141 |
# File 'lib/puppet/network/client.rb', line 135 def scheduled? if sched = self.schedule return sched.match?(self.lastrun) else return true end end |
#shutdown ⇒ Object
143 144 145 146 147 148 149 150 151 |
# File 'lib/puppet/network/client.rb', line 143 def shutdown if self.stopping Puppet.notice "Already in shutdown" else self.stopping = true Puppet::Util::Storage.store if self.respond_to? :running? and self.running? rmpidfile end end |
#start ⇒ Object
Start listening for events. We’re pretty much just listening for timer events here.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/puppet/network/client.rb', line 155 def start # Create our timer. Puppet will handle observing it and such. timer = Puppet.newtimer( :interval => Puppet[:runinterval], :tolerance => 1, :start? => true ) do begin self.runnow if self.scheduled? rescue => detail puts detail.backtrace if Puppet[:trace] Puppet.err "Could not run client; got otherwise uncaught exception: #{detail}" end end # Run once before we start following the timer self.runnow end |