Class: Puppet::HTTP::Resolver::ServerList Private
- Inherits:
-
Puppet::HTTP::Resolver
- Object
- Puppet::HTTP::Resolver
- Puppet::HTTP::Resolver::ServerList
- Defined in:
- lib/puppet/http/resolver/server_list.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Use the server_list setting to resolve a service. This resolver is only used if server_list is set either on the command line or in the configuration file.
Instance Method Summary collapse
-
#get_success?(uri, session, ssl_context: nil, error_handler: nil) ⇒ Boolean
private
Check if a server and port is available.
-
#initialize(client, server_list_setting:, default_port:, services:) ⇒ ServerList
constructor
private
A new instance of ServerList.
-
#resolve(session, name, ssl_context: nil, error_handler: nil) ⇒ nil, Puppet::HTTP::Service
private
Walk the server_list to find a server and port that will connect successfully.
Methods inherited from Puppet::HTTP::Resolver
Constructor Details
#initialize(client, server_list_setting:, default_port:, services:) ⇒ ServerList
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ServerList.
20 21 22 23 24 25 26 |
# File 'lib/puppet/http/resolver/server_list.rb', line 20 def initialize(client, server_list_setting:, default_port:, services: ) @client = client @server_list_setting = server_list_setting @default_port = default_port @services = services @resolved_url = nil end |
Instance Method Details
#get_success?(uri, session, ssl_context: nil, error_handler: nil) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if a server and port is available
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/puppet/http/resolver/server_list.rb', line 85 def get_success?(uri, session, ssl_context: nil, error_handler: nil) response = @client.get(uri, options: {ssl_context: ssl_context}) return true if response.success? Puppet.debug(_("Puppet server %{host}:%{port} is unavailable: %{code} %{reason}") % { host: uri.host, port: uri.port, code: response.code, reason: response.reason }) return false rescue => detail error_handler.call(detail) if error_handler #TRANSLATORS 'server_list' is the name of a setting and should not be translated Puppet.debug _("Unable to connect to server from server_list setting: %{detail}") % {detail: detail} return false end |
#resolve(session, name, ssl_context: nil, error_handler: nil) ⇒ nil, Puppet::HTTP::Service
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Walk the server_list to find a server and port that will connect successfully.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/puppet/http/resolver/server_list.rb', line 47 def resolve(session, name, ssl_context: nil, error_handler: nil) # If we're configured to use an explicit service host, e.g. report_server # then don't use server_list to resolve the `:report` service. return nil unless @services.include?(name) # If we resolved the URL already, use its host & port for the service if @resolved_url return Puppet::HTTP::Service.create_service(@client, session, name, @resolved_url.host, @resolved_url.port) end # Return the first simple service status endpoint we can connect to @server_list_setting.value.each do |server| host = server[0] port = server[1] || @default_port uri = URI("https://#{host}:#{port}/status/v1/simple/master") if get_success?(uri, session, ssl_context: ssl_context, error_handler: error_handler) @resolved_url = uri return Puppet::HTTP::Service.create_service(@client, session, name, host, port) end end raise Puppet::Error, _("Could not select a functional puppet master from server_list: '%{server_list}'") % { server_list: @server_list_setting.print(@server_list_setting.value) } end |