Class: RemoteExecutionProvider

Inherits:
Object
  • Object
show all
Defined in:
app/models/remote_execution_provider.rb

Direct Known Subclasses

SSHExecutionProvider

Constant Summary collapse

EFFECTIVE_USER_METHODS =
%w[sudo dzdo su].freeze

Class Method Summary collapse

Class Method Details

.cleanup_working_dirs?(host) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
# File 'app/models/remote_execution_provider.rb', line 47

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



56
57
58
59
60
61
62
# File 'app/models/remote_execution_provider.rb', line 56

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



34
35
36
# File 'app/models/remote_execution_provider.rb', line 34

def effective_user(template_invocation)
  template_invocation.effective_user
end

.effective_user_method(host) ⇒ Object



38
39
40
41
42
43
44
45
# File 'app/models/remote_execution_provider.rb', line 38

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_ip_or_hostname(host) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/models/remote_execution_provider.rb', line 64

def find_ip_or_hostname(host)
  interfaces = effective_interfaces(host)
  if host_setting(host, :remote_execution_connect_by_ip)
    ip_interface = interfaces.find { |i| i.ip.present? }
  end
  if ip_interface
    ip_interface.ip
  else
    fqdn_interface = interfaces.find { |i| i.fqdn.present? }
    if fqdn_interface
      fqdn_interface.fqdn
    else
      raise _('Could not find any suitable interface for execution')
    end
  end
end

.host_setting(host, setting) ⇒ Object



81
82
83
# File 'app/models/remote_execution_provider.rb', line 81

def host_setting(host, setting)
  host.host_param(setting.to_s) || Setting[setting]
end

.humanized_nameObject



26
27
28
# File 'app/models/remote_execution_provider.rb', line 26

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_namesObject



18
19
20
# File 'app/models/remote_execution_provider.rb', line 18

def provider_names
  providers.keys.map(&:to_s)
end

.providersObject



10
11
12
# File 'app/models/remote_execution_provider.rb', line 10

def providers
  @providers ||= { }.with_indifferent_access
end

.proxy_command_options(template_invocation, host) ⇒ Object



22
23
24
# File 'app/models/remote_execution_provider.rb', line 22

def proxy_command_options(template_invocation, host)
  {}
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

.ssh_key_passphrase(_host) ⇒ Object



87
# File 'app/models/remote_execution_provider.rb', line 87

def ssh_key_passphrase(_host) end

.ssh_password(_host) ⇒ Object



85
# File 'app/models/remote_execution_provider.rb', line 85

def ssh_password(_host) end

.sudo_password(host) ⇒ Object



52
53
54
# File 'app/models/remote_execution_provider.rb', line 52

def sudo_password(host)
  host_setting(host, :remote_execution_sudo_password)
end

.supports_effective_user?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/models/remote_execution_provider.rb', line 30

def supports_effective_user?
  false
end