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 su].freeze

Class Method Summary collapse

Class Method Details

.effective_interfaces(host) ⇒ Object



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

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



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/models/remote_execution_provider.rb', line 55

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



72
73
74
# File 'app/models/remote_execution_provider.rb', line 72

def host_setting(host, setting)
  host.params[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

.supports_effective_user?Boolean

Returns:

  • (Boolean)


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

def supports_effective_user?
  false
end