Module: ForemanRemoteExecution::HostExtensions
- Defined in:
- app/models/concerns/foreman_remote_execution/host_extensions.rb
Class Method Summary collapse
Instance Method Summary collapse
- #becomes(*args) ⇒ Object
- #drop_execution_interface_cache ⇒ Object
- #execution_interface ⇒ Object
- #execution_status(options = {}) ⇒ Object
- #execution_status_label(options = {}) ⇒ Object
- #host_params_hash ⇒ Object
- #reload(*args) ⇒ Object
- #remote_execution_proxies(provider, authorized = true) ⇒ Object
- #remote_execution_ssh_keys ⇒ Object
Class Method Details
.prepended(base) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/concerns/foreman_remote_execution/host_extensions.rb', line 3 def self.prepended(base) base.instance_eval do has_many :targeting_hosts, :dependent => :destroy, :foreign_key => 'host_id' has_many :template_invocations, :dependent => :destroy, :foreign_key => 'host_id' has_one :execution_status_object, :class_name => 'HostStatus::ExecutionStatus', :foreign_key => 'host_id', :dependent => :destroy has_many :run_host_job_tasks, :through => :template_invocations scoped_search :relation => :run_host_job_tasks, :on => :result, :rename => 'job_invocation.result', :ext_method => :search_by_job_invocation, :only_explicit => true, :complete_value => TemplateInvocation::TaskResultMap::REVERSE_MAP scoped_search :relation => :template_invocations, :on => :job_invocation_id, :rename => 'job_invocation.id', :only_explicit => true, :ext_method => :search_by_job_invocation scoped_search :relation => :execution_status_object, :on => :status, :rename => :execution_status, :complete_value => { :ok => HostStatus::ExecutionStatus::OK, :error => HostStatus::ExecutionStatus::ERROR } def search_by_job_invocation(key, operator, value) if key == 'job_invocation.result' operator = operator == '=' ? 'IN' : 'NOT IN' value = TemplateInvocation::TaskResultMap.status_to_task_result(value) end mapping = { 'job_invocation.id' => %(#{TemplateInvocation.table_name}.job_invocation_id #{operator} ?), 'job_invocation.result' => %(#{ForemanTasks::Task.table_name}.result #{operator} (?)), } { :conditions => sanitize_sql_for_conditions([mapping[key], value_to_sql(operator, value)]), :joins => { :template_invocations => [:run_host_job_task] }, } end end end |
Instance Method Details
#becomes(*args) ⇒ Object
94 95 96 97 98 |
# File 'app/models/concerns/foreman_remote_execution/host_extensions.rb', line 94 def becomes(*args) became = super(*args) became.drop_execution_interface_cache if became.respond_to? :drop_execution_interface_cache became end |
#drop_execution_interface_cache ⇒ Object
90 91 92 |
# File 'app/models/concerns/foreman_remote_execution/host_extensions.rb', line 90 def drop_execution_interface_cache @execution_interface = nil end |
#execution_interface ⇒ Object
63 64 65 |
# File 'app/models/concerns/foreman_remote_execution/host_extensions.rb', line 63 def execution_interface get_interface_by_flag(:execution) end |
#execution_status(options = {}) ⇒ Object
39 40 41 |
# File 'app/models/concerns/foreman_remote_execution/host_extensions.rb', line 39 def execution_status( = {}) @execution_status ||= get_status(HostStatus::ExecutionStatus).to_status() end |
#execution_status_label(options = {}) ⇒ Object
43 44 45 |
# File 'app/models/concerns/foreman_remote_execution/host_extensions.rb', line 43 def execution_status_label( = {}) @execution_status_label ||= get_status(HostStatus::ExecutionStatus).to_label() end |
#host_params_hash ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/concerns/foreman_remote_execution/host_extensions.rb', line 47 def host_params_hash params = super keys = remote_execution_ssh_keys source = 'global' if keys.present? value, safe_value = params.fetch('remote_execution_ssh_keys', {}).values_at(:value, :safe_value).map { |v| [v].flatten.compact } params['remote_execution_ssh_keys'] = {:value => value + keys, :safe_value => safe_value + keys, :source => source} end [:remote_execution_ssh_user, :remote_execution_effective_user_method, :remote_execution_connect_by_ip].each do |key| value = Setting[key] params[key.to_s] = {:value => value, :safe_value => value, :source => source} unless params.key?(key.to_s) end params end |
#reload(*args) ⇒ Object
100 101 102 103 |
# File 'app/models/concerns/foreman_remote_execution/host_extensions.rb', line 100 def reload(*args) drop_execution_interface_cache super(*args) end |
#remote_execution_proxies(provider, authorized = true) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/models/concerns/foreman_remote_execution/host_extensions.rb', line 67 def remote_execution_proxies(provider, = true) proxies = {} proxies[:subnet] = execution_interface.subnet.remote_execution_proxies.with_features(provider) if execution_interface&.subnet proxies[:fallback] = smart_proxies.with_features(provider) if Setting[:remote_execution_fallback_proxy] if Setting[:remote_execution_global_proxy] proxy_scope = if User.current.present? ::SmartProxy.with_taxonomy_scope_override(location, organization) else ::SmartProxy.unscoped end proxy_scope = proxy_scope. if proxies[:global] = proxy_scope.with_features(provider) end proxies end |
#remote_execution_ssh_keys ⇒ Object
86 87 88 |
# File 'app/models/concerns/foreman_remote_execution/host_extensions.rb', line 86 def remote_execution_ssh_keys remote_execution_proxies('SSH', false).values.flatten.uniq.map { |proxy| proxy.pubkey }.compact.uniq end |