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
- .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_operation_name ⇒ Object
- .register(key, klass) ⇒ 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
Class Method Details
.alternative_names(host) ⇒ Object
139 140 141 |
# File 'app/models/remote_execution_provider.rb', line 139 def alternative_names(host) { :fqdn => find_fqdn(effective_interfaces(host)) } end |
.cleanup_working_dirs?(host) ⇒ Boolean
58 59 60 61 |
# File 'app/models/remote_execution_provider.rb', line 58 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
67 68 69 70 71 72 73 |
# File 'app/models/remote_execution_provider.rb', line 67 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
45 46 47 |
# File 'app/models/remote_execution_provider.rb', line 45 def effective_user(template_invocation) template_invocation.effective_user end |
.effective_user_method(host) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'app/models/remote_execution_provider.rb', line 49 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
63 64 65 |
# File 'app/models/remote_execution_provider.rb', line 63 def effective_user_password(host) host_setting(host, :remote_execution_effective_user_password) end |
.find_fqdn(interfaces) ⇒ Object
94 95 96 |
# File 'app/models/remote_execution_provider.rb', line 94 def find_fqdn(interfaces) interfaces.find { |i| i.fqdn.present? }.try(:fqdn) end |
.find_ip(host, interfaces) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/remote_execution_provider.rb', line 81 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
75 76 77 78 79 |
# File 'app/models/remote_execution_provider.rb', line 75 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
98 99 100 101 |
# File 'app/models/remote_execution_provider.rb', line 98 def host_setting(host, setting) param_value = host.host_param(setting.to_s) param_value.nil? ? Setting[setting] : param_value end |
.humanized_name ⇒ Object
34 35 36 |
# File 'app/models/remote_execution_provider.rb', line 34 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[:SSH] end |
.provider_input_namespace ⇒ Object
38 39 |
# File 'app/models/remote_execution_provider.rb', line 38 def provider_input_namespace end |
.provider_inputs ⇒ Object
109 110 111 |
# File 'app/models/remote_execution_provider.rb', line 109 def provider_inputs [] end |
.provider_inputs_doc ⇒ Object
113 114 115 |
# File 'app/models/remote_execution_provider.rb', line 113 def provider_inputs_doc {} end |
.provider_names ⇒ Object
18 19 20 |
# File 'app/models/remote_execution_provider.rb', line 18 def provider_names providers.keys.map(&:to_s) end |
.providers ⇒ Object
10 11 12 |
# File 'app/models/remote_execution_provider.rb', line 10 def providers @providers ||= { }.with_indifferent_access end |
.proxy_action_class ⇒ Object
121 122 123 |
# File 'app/models/remote_execution_provider.rb', line 121 def proxy_action_class 'Proxy::RemoteExecution::Ssh::Actions::RunScript' end |
.proxy_batch_size ⇒ Object
125 126 127 |
# File 'app/models/remote_execution_provider.rb', line 125 def proxy_batch_size Setting['foreman_tasks_proxy_batch_size'] end |
.proxy_command_options(template_invocation, host) ⇒ Object
22 23 24 |
# File 'app/models/remote_execution_provider.rb', line 22 def (template_invocation, host) {:proxy_operation_name => proxy_operation_name}.merge(proxy_command_provider_inputs(template_invocation)) end |
.proxy_command_provider_inputs(template_invocation) ⇒ Object
117 118 119 |
# File 'app/models/remote_execution_provider.rb', line 117 def proxy_command_provider_inputs(template_invocation) {} end |
.proxy_operation_name ⇒ Object
30 31 32 |
# File 'app/models/remote_execution_provider.rb', line 30 def proxy_operation_name 'ssh' end |
.register(key, klass) ⇒ Object
14 15 16 |
# File 'app/models/remote_execution_provider.rb', line 14 def register(key, klass) providers[key.to_sym] = 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
131 132 133 134 135 136 137 |
# File 'app/models/remote_execution_provider.rb', line 131 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
26 27 28 |
# File 'app/models/remote_execution_provider.rb', line 26 def secrets(_host) {} end |
.ssh_key_passphrase(_host) ⇒ Object
106 107 |
# File 'app/models/remote_execution_provider.rb', line 106 def ssh_key_passphrase(_host) end |
.ssh_password(_host) ⇒ Object
103 104 |
# File 'app/models/remote_execution_provider.rb', line 103 def ssh_password(_host) end |
.supports_effective_user? ⇒ Boolean
41 42 43 |
# File 'app/models/remote_execution_provider.rb', line 41 def supports_effective_user? false end |