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.


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 != :masterport && 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 `masterport`
        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 'masterport' is the name of a setting and should not be translated
          debug_once _("Dynamically-bound port lookup failed; falling back to `masterport` setting: %{port}") % {port: Puppet.settings[:masterport]}
          Puppet.settings[:masterport]
        end
      else
        port_setting ||= :masterport
        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.


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