Module: ForemanRemoteExecution::HostExtensions

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/foreman_remote_execution/host_extensions.rb

Instance Method Summary collapse

Instance Method Details

#becomes_with_remote_execution(*args) ⇒ Object



68
69
70
71
72
# File 'app/models/concerns/foreman_remote_execution/host_extensions.rb', line 68

def becomes_with_remote_execution(*args)
  became = becomes_without_remote_execution(*args)
  became.drop_execution_interface_cache if became.respond_to? :drop_execution_interface_cache
  became
end

#drop_execution_interface_cacheObject



64
65
66
# File 'app/models/concerns/foreman_remote_execution/host_extensions.rb', line 64

def drop_execution_interface_cache
  @execution_interface = nil
end

#execution_interfaceObject



37
38
39
# File 'app/models/concerns/foreman_remote_execution/host_extensions.rb', line 37

def execution_interface
  get_interface_by_flag(:execution)
end

#execution_status(options = {}) ⇒ Object



19
20
21
# File 'app/models/concerns/foreman_remote_execution/host_extensions.rb', line 19

def execution_status(options = {})
  @execution_status ||= get_status(HostStatus::ExecutionStatus).to_status(options)
end

#execution_status_label(options = {}) ⇒ Object



23
24
25
# File 'app/models/concerns/foreman_remote_execution/host_extensions.rb', line 23

def execution_status_label(options = {})
  @execution_status_label ||= get_status(HostStatus::ExecutionStatus).to_label(options)
end

#params_with_remote_executionObject



27
28
29
30
31
32
33
34
35
# File 'app/models/concerns/foreman_remote_execution/host_extensions.rb', line 27

def params_with_remote_execution
  params = params_without_remote_execution
  keys = remote_execution_ssh_keys
  params['remote_execution_ssh_keys'] = keys unless keys.blank?
  [:remote_execution_ssh_user, :remote_execution_effective_user_method].each do |key|
    params[key.to_s] = Setting[key] unless params.key?(key.to_s)
  end
  params
end

#reload_with_remote_execution(*args) ⇒ Object



74
75
76
77
# File 'app/models/concerns/foreman_remote_execution/host_extensions.rb', line 74

def reload_with_remote_execution(*args)
  drop_execution_interface_cache
  reload_without_remote_execution(*args)
end

#remote_execution_proxies(provider, authorized = true) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/models/concerns/foreman_remote_execution/host_extensions.rb', line 41

def remote_execution_proxies(provider, authorized = true)
  proxies = {}
  proxies[:subnet]   = execution_interface.subnet.remote_execution_proxies.with_features(provider) if execution_interface && 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 Taxonomy.enabled_taxonomies.any?
                    ::SmartProxy.with_taxonomy_scope_override(location, organization)
                  else
                    proxy_scope = ::SmartProxy
                  end

    proxy_scope = proxy_scope.authorized if authorized
    proxies[:global] = proxy_scope.with_features(provider)
  end

  proxies
end

#remote_execution_ssh_keysObject



60
61
62
# File 'app/models/concerns/foreman_remote_execution/host_extensions.rb', line 60

def remote_execution_ssh_keys
  remote_execution_proxies('SSH', false).values.flatten.uniq.map { |proxy| proxy.pubkey }.compact.uniq
end