Module: Puppet::Util::Connection

Extended by:
Warnings
Defined in:
lib/puppet/util/connection.rb

Class Method Summary collapse

Methods included from Warnings

clear_warnings, debug_once, maybe_log, notice_once, warnonce

Class Method Details

.determine_port(port_setting, server_setting) ⇒ Integer

Determines which port to use based on the specified setting, taking into account HA fallback from server_list. For port there's a little bit of an extra snag: setting a specific server setting and relying on the default port for that server is common, so we also want to check if the assocaited SERVER setting has been set by the user. If either of those are set we ignore the failover-selected port.

Parameters:

  • port_setting (Symbol)

    The preferred port setting to use

  • server_setting (Symbol)

    The server setting assoicated with this route.

Returns:

  • (Integer)

    the port to use for use in the request


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/puppet/util/connection.rb', line 57

def self.determine_port(port_setting, server_setting)
  if (port_setting && port_setting != :serverport && Puppet.settings.set_by_config?(port_setting)) ||
     (server_setting && server_setting != :server && Puppet.settings.set_by_config?(server_setting))
    debug_once _("Selected port from the %{setting} setting: %{port}") % {setting: port_setting, port: Puppet.settings[port_setting].to_i}
    Puppet.settings[port_setting].to_i
  else
    port = Puppet.lookup(:serverport) do
      primary_server = Puppet.settings[:server_list][0]
      if primary_server
        # Port might not be set, so we want to fallback in that
        # case. We know we don't need to use `setting` here, since
        # the default value of every port setting is `serverport`
        if primary_server[1]
          #TRANSLATORS 'server_list' is the name of a setting and should not be translated
          debug_once _("Dynamically-bound port lookup failed; using first entry from the `server_list` setting: %{port}") % {port: primary_server[1]}
          primary_server[1]
        else
          #TRANSLATORS 'serverport' is the name of a setting and should not be translated
          debug_once _("Dynamically-bound port lookup failed; falling back to `serverport` setting: %{port}") % {port: Puppet.settings[:serverport]}
          Puppet.settings[:serverport]
        end
      else
        port_setting ||= :serverport
        debug_once _("Dynamically-bound port lookup failed; falling back to %{setting} setting: %{port}") % {setting: port_setting, port: Puppet.settings[port_setting]}
        Puppet.settings[port_setting]
      end
    end
    port.to_i
  end
end

.determine_server(setting) ⇒ String

Determines which server to use based on the specified setting, taking into account HA fallback from server_list.

Parameters:

  • setting (Symbol)

    The preferred server setting to use

Returns:

  • (String)

    the name of the server for use in the request


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/puppet/util/connection.rb', line 26

def self.determine_server(setting)
  if setting && setting != :server && Puppet.settings.set_by_config?(setting)
    debug_once _("Selected server from the %{setting} setting: %{server}") % {setting: setting, server: Puppet.settings[setting]}
    Puppet[setting]
  else
    server = Puppet.lookup(:server) do
      primary_server = Puppet.settings[:server_list][0]
      if primary_server
        #TRANSLATORS 'server_list' is the name of a setting and should not be translated
        debug_once _("Dynamically-bound server lookup failed; using first entry from the `server_list` setting: %{server}") % {server: primary_server[0]}
        primary_server[0]
      else
        setting ||= :server
        debug_once _("Dynamically-bound server lookup failed, falling back to %{setting} setting: %{server}") % {setting: setting, server: Puppet.settings[setting]}
        Puppet.settings[setting]
      end
    end
    server
  end
end