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
- .cleanup_working_dirs?(host) ⇒ Boolean
- .effective_interfaces(host) ⇒ Object
- .effective_user(template_invocation) ⇒ Object
- .effective_user_method(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_names ⇒ Object
- .providers ⇒ Object
- .proxy_action_class ⇒ Object
- .proxy_command_options(template_invocation, host) ⇒ 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
- .sudo_password(host) ⇒ Object
- .supports_effective_user? ⇒ Boolean
Class Method Details
.cleanup_working_dirs?(host) ⇒ Boolean
55 56 57 58 |
# File 'app/models/remote_execution_provider.rb', line 55 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
64 65 66 67 68 69 70 |
# File 'app/models/remote_execution_provider.rb', line 64 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
42 43 44 |
# File 'app/models/remote_execution_provider.rb', line 42 def effective_user(template_invocation) template_invocation.effective_user end |
.effective_user_method(host) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'app/models/remote_execution_provider.rb', line 46 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 |
.find_fqdn(interfaces) ⇒ Object
84 85 86 |
# File 'app/models/remote_execution_provider.rb', line 84 def find_fqdn(interfaces) interfaces.find { |i| i.fqdn.present? }.try(:fqdn) end |
.find_ip(host, interfaces) ⇒ Object
78 79 80 81 82 |
# File 'app/models/remote_execution_provider.rb', line 78 def find_ip(host, interfaces) if host_setting(host, :remote_execution_connect_by_ip) interfaces.find { |i| i.ip.present? }.try(:ip) end end |
.find_ip_or_hostname(host) ⇒ Object
72 73 74 75 76 |
# File 'app/models/remote_execution_provider.rb', line 72 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
88 89 90 |
# File 'app/models/remote_execution_provider.rb', line 88 def host_setting(host, setting) host.host_param(setting.to_s) || Setting[setting] 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_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
98 99 100 |
# File 'app/models/remote_execution_provider.rb', line 98 def proxy_action_class ForemanRemoteExecutionCore::Actions::RunScript 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} 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
104 105 |
# File 'app/models/remote_execution_provider.rb', line 104 def required_proxy_selector_for(_template) 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
95 96 |
# File 'app/models/remote_execution_provider.rb', line 95 def ssh_key_passphrase(_host) end |
.ssh_password(_host) ⇒ Object
92 93 |
# File 'app/models/remote_execution_provider.rb', line 92 def ssh_password(_host) end |
.sudo_password(host) ⇒ Object
60 61 62 |
# File 'app/models/remote_execution_provider.rb', line 60 def sudo_password(host) host_setting(host, :remote_execution_sudo_password) end |
.supports_effective_user? ⇒ Boolean
38 39 40 |
# File 'app/models/remote_execution_provider.rb', line 38 def supports_effective_user? false end |