Class: RemoteExecutionProvider
- Inherits:
-
Object
- Object
- RemoteExecutionProvider
- Defined in:
- app/models/remote_execution_provider.rb
Direct Known Subclasses
Constant Summary collapse
- EFFECTIVE_USER_METHODS =
%w[sudo dzdo su].freeze
Class Method Summary collapse
- .alternative_names(host) ⇒ Object
- .cleanup_working_dirs?(host) ⇒ Boolean
- .effective_interfaces(host) ⇒ Object
- .effective_user(template_invocation) ⇒ Object
- .effective_user_method(host) ⇒ Object
- .effective_user_password(host) ⇒ Object
- .find_fqdn(interfaces) ⇒ Object
- .find_ip(host, interfaces) ⇒ Object
- .find_ip_or_hostname(host) ⇒ Object
- .host_setting(host, setting) ⇒ Object
- .humanized_name ⇒ Object
- .provider_for(type) ⇒ Object
- .provider_input_namespace ⇒ Object
- .provider_inputs ⇒ Object
- .provider_inputs_doc ⇒ Object
- .provider_names ⇒ Object
- .provider_proxy_features ⇒ Object
- .providers ⇒ Object
- .proxy_action_class ⇒ Object
- .proxy_batch_size ⇒ Object
- .proxy_command_options(template_invocation, host) ⇒ Object
- .proxy_command_provider_inputs(template_invocation) ⇒ Object
- .proxy_feature ⇒ Object
- .proxy_operation_name ⇒ Object
- .register(key, klass) ⇒ Object
- .registered_name ⇒ Object
-
.required_proxy_selector_for(template) ⇒ Object
Return a specific proxy selector to use for running a given template Returns either nil to use the default selector or an instance of a (sub)class of ::ForemanTasks::ProxySelector.
- .secrets(_host) ⇒ Object
- .ssh_key_passphrase(_host) ⇒ Object
- .ssh_password(_host) ⇒ Object
- .supports_effective_user? ⇒ Boolean
- .time_to_pickup(job_invocation, host) ⇒ Object
Class Method Details
.alternative_names(host) ⇒ Object
155 156 157 |
# File 'app/models/remote_execution_provider.rb', line 155 def alternative_names(host) { :fqdn => find_fqdn(effective_interfaces(host)) } end |
.cleanup_working_dirs?(host) ⇒ Boolean
74 75 76 77 |
# File 'app/models/remote_execution_provider.rb', line 74 def cleanup_working_dirs?(host) setting = host_setting(host, :remote_execution_cleanup_working_dirs) [true, 'true', 'True', 'TRUE', '1'].include?(setting) end |
.effective_interfaces(host) ⇒ Object
83 84 85 86 87 88 89 |
# File 'app/models/remote_execution_provider.rb', line 83 def effective_interfaces(host) interfaces = [] %w(execution primary provision).map do |flag| interfaces << host.send(flag + '_interface') end interfaces.compact.uniq end |
.effective_user(template_invocation) ⇒ Object
61 62 63 |
# File 'app/models/remote_execution_provider.rb', line 61 def effective_user(template_invocation) template_invocation.effective_user end |
.effective_user_method(host) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'app/models/remote_execution_provider.rb', line 65 def effective_user_method(host) method = host_setting(host, :remote_execution_effective_user_method) unless EFFECTIVE_USER_METHODS.include?(method) raise _('Effective user method "%{current_value}" is not one of %{valid_methods}') % { :current_value => method, :valid_methods => EFFECTIVE_USER_METHODS} end method end |
.effective_user_password(host) ⇒ Object
79 80 81 |
# File 'app/models/remote_execution_provider.rb', line 79 def effective_user_password(host) host_setting(host, :remote_execution_effective_user_password) end |
.find_fqdn(interfaces) ⇒ Object
110 111 112 |
# File 'app/models/remote_execution_provider.rb', line 110 def find_fqdn(interfaces) interfaces.find { |i| i.fqdn.present? }.try(:fqdn) end |
.find_ip(host, interfaces) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'app/models/remote_execution_provider.rb', line 97 def find_ip(host, interfaces) if host_setting(host, :remote_execution_connect_by_ip) ip4_address = interfaces.find { |i| i.ip.present? }.try(:ip) ip6_address = interfaces.find { |i| i.ip6.present? }.try(:ip6) if host_setting(host, :remote_execution_connect_by_ip_prefer_ipv6) ip6_address || ip4_address else ip4_address || ip6_address end end end |
.find_ip_or_hostname(host) ⇒ Object
91 92 93 94 95 |
# File 'app/models/remote_execution_provider.rb', line 91 def find_ip_or_hostname(host) interfaces = effective_interfaces host find_ip(host, interfaces) || find_fqdn(interfaces) || raise(_('Could not find any suitable interface for execution')) end |
.host_setting(host, setting) ⇒ Object
114 115 116 117 |
# File 'app/models/remote_execution_provider.rb', line 114 def host_setting(host, setting) param_value = host.host_param(setting.to_s) param_value.nil? ? Setting[setting] : param_value end |
.humanized_name ⇒ Object
50 51 52 |
# File 'app/models/remote_execution_provider.rb', line 50 def humanized_name self.name end |
.provider_for(type) ⇒ Object
6 7 8 |
# File 'app/models/remote_execution_provider.rb', line 6 def provider_for(type) providers[type.to_s] || providers[:script] end |
.provider_input_namespace ⇒ Object
54 55 |
# File 'app/models/remote_execution_provider.rb', line 54 def provider_input_namespace end |
.provider_inputs ⇒ Object
125 126 127 |
# File 'app/models/remote_execution_provider.rb', line 125 def provider_inputs [] end |
.provider_inputs_doc ⇒ Object
129 130 131 |
# File 'app/models/remote_execution_provider.rb', line 129 def provider_inputs_doc {} end |
.provider_names ⇒ Object
27 28 29 |
# File 'app/models/remote_execution_provider.rb', line 27 def provider_names providers.keys.map(&:to_s) end |
.provider_proxy_features ⇒ Object
31 32 33 |
# File 'app/models/remote_execution_provider.rb', line 31 def provider_proxy_features providers.values.map(&:proxy_feature).flatten.uniq.compact end |
.providers ⇒ Object
19 20 21 |
# File 'app/models/remote_execution_provider.rb', line 19 def providers @providers ||= { }.with_indifferent_access end |
.proxy_action_class ⇒ Object
137 138 139 |
# File 'app/models/remote_execution_provider.rb', line 137 def proxy_action_class 'Proxy::RemoteExecution::Ssh::Actions::RunScript' end |
.proxy_batch_size ⇒ Object
141 142 143 |
# File 'app/models/remote_execution_provider.rb', line 141 def proxy_batch_size Setting['foreman_tasks_proxy_batch_size'] end |
.proxy_command_options(template_invocation, host) ⇒ Object
35 36 37 38 39 40 |
# File 'app/models/remote_execution_provider.rb', line 35 def (template_invocation, host) { :proxy_operation_name => proxy_operation_name, :time_to_pickup => time_to_pickup(template_invocation.job_invocation, host), }.merge(proxy_command_provider_inputs(template_invocation)) end |
.proxy_command_provider_inputs(template_invocation) ⇒ Object
133 134 135 |
# File 'app/models/remote_execution_provider.rb', line 133 def proxy_command_provider_inputs(template_invocation) {} end |
.proxy_feature ⇒ Object
15 16 17 |
# File 'app/models/remote_execution_provider.rb', line 15 def proxy_feature registered_name end |
.proxy_operation_name ⇒ Object
46 47 48 |
# File 'app/models/remote_execution_provider.rb', line 46 def proxy_operation_name 'ssh' end |
.register(key, klass) ⇒ Object
23 24 25 |
# File 'app/models/remote_execution_provider.rb', line 23 def register(key, klass) providers[key.to_sym] = klass end |
.registered_name ⇒ Object
10 11 12 13 |
# File 'app/models/remote_execution_provider.rb', line 10 def registered_name klass = self ::RemoteExecutionProvider.providers.key(klass) end |
.required_proxy_selector_for(template) ⇒ Object
Return a specific proxy selector to use for running a given template Returns either nil to use the default selector or an instance of a (sub)class of ::ForemanTasks::ProxySelector
147 148 149 150 151 152 153 |
# File 'app/models/remote_execution_provider.rb', line 147 def required_proxy_selector_for(template) if template.remote_execution_features .where(:proxy_selector_override => ::RemoteExecutionProxySelector::INTERNAL_PROXY) .any? ::DefaultProxyProxySelector.new end end |
.secrets(_host) ⇒ Object
42 43 44 |
# File 'app/models/remote_execution_provider.rb', line 42 def secrets(_host) {} end |
.ssh_key_passphrase(_host) ⇒ Object
122 123 |
# File 'app/models/remote_execution_provider.rb', line 122 def ssh_key_passphrase(_host) end |
.ssh_password(_host) ⇒ Object
119 120 |
# File 'app/models/remote_execution_provider.rb', line 119 def ssh_password(_host) end |
.supports_effective_user? ⇒ Boolean
57 58 59 |
# File 'app/models/remote_execution_provider.rb', line 57 def supports_effective_user? false end |
.time_to_pickup(job_invocation, host) ⇒ Object
159 160 161 162 |
# File 'app/models/remote_execution_provider.rb', line 159 def time_to_pickup(job_invocation, host) time = job_invocation.time_to_pickup || host_setting(host, 'remote_execution_time_to_pickup') Integer(time) if time end |