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_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
Class Method Details
.alternative_names(host) ⇒ Object
148 149 150 |
# File 'app/models/remote_execution_provider.rb', line 148 def alternative_names(host) { :fqdn => find_fqdn(effective_interfaces(host)) } end |
.cleanup_working_dirs?(host) ⇒ Boolean
67 68 69 70 |
# File 'app/models/remote_execution_provider.rb', line 67 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
76 77 78 79 80 81 82 |
# File 'app/models/remote_execution_provider.rb', line 76 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
54 55 56 |
# File 'app/models/remote_execution_provider.rb', line 54 def effective_user(template_invocation) template_invocation.effective_user end |
.effective_user_method(host) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'app/models/remote_execution_provider.rb', line 58 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
72 73 74 |
# File 'app/models/remote_execution_provider.rb', line 72 def effective_user_password(host) host_setting(host, :remote_execution_effective_user_password) end |
.find_fqdn(interfaces) ⇒ Object
103 104 105 |
# File 'app/models/remote_execution_provider.rb', line 103 def find_fqdn(interfaces) interfaces.find { |i| i.fqdn.present? }.try(:fqdn) end |
.find_ip(host, interfaces) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/models/remote_execution_provider.rb', line 90 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
84 85 86 87 88 |
# File 'app/models/remote_execution_provider.rb', line 84 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
107 108 109 110 |
# File 'app/models/remote_execution_provider.rb', line 107 def host_setting(host, setting) param_value = host.host_param(setting.to_s) param_value.nil? ? Setting[setting] : param_value end |
.humanized_name ⇒ Object
43 44 45 |
# File 'app/models/remote_execution_provider.rb', line 43 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
47 48 |
# File 'app/models/remote_execution_provider.rb', line 47 def provider_input_namespace end |
.provider_inputs ⇒ Object
118 119 120 |
# File 'app/models/remote_execution_provider.rb', line 118 def provider_inputs [] end |
.provider_inputs_doc ⇒ Object
122 123 124 |
# File 'app/models/remote_execution_provider.rb', line 122 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 |
.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
130 131 132 |
# File 'app/models/remote_execution_provider.rb', line 130 def proxy_action_class 'Proxy::RemoteExecution::Ssh::Actions::RunScript' end |
.proxy_batch_size ⇒ Object
134 135 136 |
# File 'app/models/remote_execution_provider.rb', line 134 def proxy_batch_size Setting['foreman_tasks_proxy_batch_size'] end |
.proxy_command_options(template_invocation, host) ⇒ Object
31 32 33 |
# File 'app/models/remote_execution_provider.rb', line 31 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
126 127 128 |
# File 'app/models/remote_execution_provider.rb', line 126 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
39 40 41 |
# File 'app/models/remote_execution_provider.rb', line 39 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 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
140 141 142 143 144 145 146 |
# File 'app/models/remote_execution_provider.rb', line 140 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
35 36 37 |
# File 'app/models/remote_execution_provider.rb', line 35 def secrets(_host) {} end |
.ssh_key_passphrase(_host) ⇒ Object
115 116 |
# File 'app/models/remote_execution_provider.rb', line 115 def ssh_key_passphrase(_host) end |
.ssh_password(_host) ⇒ Object
112 113 |
# File 'app/models/remote_execution_provider.rb', line 112 def ssh_password(_host) end |
.supports_effective_user? ⇒ Boolean
50 51 52 |
# File 'app/models/remote_execution_provider.rb', line 50 def supports_effective_user? false end |