Class: Puppet::Network::XMLRPCClient

Inherits:
XMLRPC::Client
  • Object
show all
Extended by:
Util, Util::ClassGen
Defined in:
lib/puppet/network/xmlrpc/client.rb

Defined Under Namespace

Classes: ErrorHandler

Constant Summary collapse

@@error_handlers =

Use a class variable so all subclasses have access to it.

{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util::ClassGen

genclass, genmodule, rmclass

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

Methods included from Util::MethodHelper

#requiredopts, #set_options, #symbolize_options

Constructor Details

#initialize(hash = {}) ⇒ XMLRPCClient

Returns a new instance of XMLRPCClient.



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/puppet/network/xmlrpc/client.rb', line 158

def initialize(hash = {})
  hash[:Path] ||= "/RPC2"
  hash[:Server] ||= Puppet[:server]
  hash[:Port] ||= Puppet[:masterport]
  hash[:HTTPProxyHost] ||= Puppet[:http_proxy_host]
  hash[:HTTPProxyPort] ||= Puppet[:http_proxy_port]

  if "none" == hash[:HTTPProxyHost]
    hash[:HTTPProxyHost] = nil
    hash[:HTTPProxyPort] = nil
  end


        super(
            
    hash[:Server],
    hash[:Path],
    hash[:Port],
    hash[:HTTPProxyHost],
    hash[:HTTPProxyPort],
    
    nil, # user
    nil, # password
    true, # use_ssl
    Puppet[:configtimeout] # use configured timeout (#1176)
  )
  @http = Puppet::Network::HttpPool.http_instance(@host, @port)
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



156
157
158
# File 'lib/puppet/network/xmlrpc/client.rb', line 156

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



156
157
158
# File 'lib/puppet/network/xmlrpc/client.rb', line 156

def port
  @port
end

#puppet_portObject

Returns the value of attribute puppet_port.



15
16
17
# File 'lib/puppet/network/xmlrpc/client.rb', line 15

def puppet_port
  @puppet_port
end

#puppet_serverObject

Returns the value of attribute puppet_server.



15
16
17
# File 'lib/puppet/network/xmlrpc/client.rb', line 15

def puppet_server
  @puppet_server
end

Class Method Details

.error_handler(exception) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/puppet/network/xmlrpc/client.rb', line 59

def self.error_handler(exception)
  if handler = @@error_handlers[exception.class]
    return handler
  else
    return @@error_handlers[:default]
  end
end

.handle_error(*exceptions, &block) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/puppet/network/xmlrpc/client.rb', line 67

def self.handle_error(*exceptions, &block)
  handler = ErrorHandler.new(&block)

  exceptions.each do |exception|
    @@error_handlers[exception] = handler
  end
end

.handler_class(handler) ⇒ Object



46
47
48
# File 'lib/puppet/network/xmlrpc/client.rb', line 46

def self.handler_class(handler)
  @clients[handler] || self.mkclient(handler)
end

.mkclient(handler) ⇒ Object

Create a netclient for each handler



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/puppet/network/xmlrpc/client.rb', line 24

def self.mkclient(handler)
  interface = handler.interface
  namespace = interface.prefix

  # Create a subclass for every client type.  This is
  # so that all of the methods are on their own class,
  # so that their namespaces can define the same methods if
  # they want.
  constant = handler.name.to_s.capitalize
  name = namespace.downcase
  newclient = genclass(name, :hash => @clients, :constant => constant)

  interface.methods.each { |ary|
    method = ary[0]
    newclient.send(:define_method,method) { |*args|
      make_rpc_call(namespace, method, *args)
    }
  }

  newclient
end

Instance Method Details

#httpObject



152
153
154
# File 'lib/puppet/network/xmlrpc/client.rb', line 152

def http
  @http ||= Puppet::Network::HttpPool.http_instance(host, port, true)
end

#localObject



203
204
205
# File 'lib/puppet/network/xmlrpc/client.rb', line 203

def local
  false
end

#local?Boolean

Returns:

  • (Boolean)


207
208
209
# File 'lib/puppet/network/xmlrpc/client.rb', line 207

def local?
  false
end

#make_rpc_call(namespace, method, *args) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/puppet/network/xmlrpc/client.rb', line 139

def make_rpc_call(namespace, method, *args)
  Puppet.debug "Calling #{namespace}.#{method}"
  begin
    call("#{namespace}.#{method}",*args)
  rescue SystemExit,NoMemoryError
    raise
  rescue Exception => detail
    retry if self.class.error_handler(detail).execute(self, detail, namespace, method) == :retry
  end
ensure
  http.finish if http.started?
end

#recycle_connectionObject

Get rid of our existing connection, replacing it with a new one. This should only happen if we lose our connection somehow (e.g., an EPIPE) or we’ve just downloaded certs and we need to create new http instances with the certs added.



191
192
193
194
195
# File 'lib/puppet/network/xmlrpc/client.rb', line 191

def recycle_connection
  http.finish if http.started?
  @http = nil
  self.http # force a new one
end

#startObject



197
198
199
200
201
# File 'lib/puppet/network/xmlrpc/client.rb', line 197

def start
    @http.start unless @http.started?
rescue => detail
    Puppet.err "Could not connect to server: #{detail}"
end