Module: Orchestration::SSH

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

Instance Method Summary collapse

Instance Method Details

#drop_from_known_hosts(proxy_id) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/concerns/foreman_remote_execution/orchestration/ssh.rb', line 11

def drop_from_known_hosts(proxy_id)
  _, _, target = host_kind_target
  return true if target.nil?

  proxy = ::SmartProxy.find(proxy_id)
  begin
    proxy.drop_host_from_known_hosts(target)
  rescue ::ProxyAPI::ProxyException => e
    if e.wrapped_exception.is_a?(RestClient::NotFound)
      # ignore 404 when known_hosts entry is missing or the module was not enabled
      Foreman::Logging.exception "Proxy failed to delete SSH known_hosts for #{name}, #{ip}", e, :level => :error
    else
      raise e
    end
  rescue => e
    Rails.logger.warn e.message
    return false
  end
  true
end

#queue_ssh_destroyObject



46
47
48
# File 'app/models/concerns/foreman_remote_execution/orchestration/ssh.rb', line 46

def queue_ssh_destroy
  should_drop_from_known_hosts? && ssh_destroy
end

#should_drop_from_known_hosts?Boolean

Returns:

  • (Boolean)


50
51
52
53
# File 'app/models/concerns/foreman_remote_execution/orchestration/ssh.rb', line 50

def should_drop_from_known_hosts?
  host, = host_kind_target
  host && !host.new_record? && host.build && host.changes.key?('build')
end

#ssh_destroyObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/concerns/foreman_remote_execution/orchestration/ssh.rb', line 32

def ssh_destroy
  logger.debug "Scheduling SSH known_hosts cleanup"

  host, _kind, _target = host_kind_target
  # #remote_execution_proxies may not be defined on the host object in some case
  # for example Host::Discovered does not have it defined, even though these hosts
  # have Nic::Managed interfaces associated with them
  proxies = (host.try(:remote_execution_proxies, 'SSH') || {}).values
  proxies.flatten.uniq.each do |proxy|
    queue.create(id: queue_id(proxy.id), name: _("Remove SSH known hosts for %s") % self,
      priority: 200, action: [self, :drop_from_known_hosts, proxy.id])
  end
end