Class: Bolt::Transport::Remote

Inherits:
Base
  • Object
show all
Defined in:
lib/bolt/transport/remote.rb

Constant Summary

Constants inherited from Base

Base::ENVIRONMENT_METHODS, Base::STDIN_METHODS

Instance Attribute Summary

Attributes inherited from Base

#logger

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#assert_batch_size_one, #batch_command, #batch_connected?, #batch_script, #batch_task, #batch_upload, #batches, #connected?, #default_input_method, #envify_params, options, #provided_features, #run_command, #run_script, #select_implementation, #select_interpreter, #unwrap_sensitive_args, #upload, #with_events

Constructor Details

#initialize(executor) ⇒ Remote

TODO: this should have access to inventory so target doesn’t have to



26
27
28
29
30
# File 'lib/bolt/transport/remote.rb', line 26

def initialize(executor)
  super()

  @executor = executor
end

Class Method Details

.default_optionsObject



14
15
16
# File 'lib/bolt/transport/remote.rb', line 14

def self.default_options
  { 'run-on' => 'localhost' }
end

.filter_options(unfiltered) ⇒ Object

The options for the remote transport not defined.



10
11
12
# File 'lib/bolt/transport/remote.rb', line 10

def self.filter_options(unfiltered)
  unfiltered
end

.validate(options) ⇒ Object



18
19
20
21
22
23
# File 'lib/bolt/transport/remote.rb', line 18

def self.validate(options)
  # This will fail when validating global config
  # unless options['device-type']
  #  raise Bolt::ValidationError, 'Must specify device-type for devices'
  # end
end

Instance Method Details

#get_proxy(target) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bolt/transport/remote.rb', line 32

def get_proxy(target)
  inventory = target.inventory
  raise "Target was created without inventory? Not get_targets?" unless inventory
  proxy = inventory.get_targets(target.options['run-on'] || 'localhost').first

  if proxy.transport == 'remote'
    msg = "#{proxy.name} is not a valid run-on target for #{target.name} since is also remote."
    raise Bolt::Error.new(msg, 'bolt/invalid-remote-target')
  end
  proxy
end

#run_task(target, task, arguments, options = {}) ⇒ Object

Cannot batch because arugments differ



45
46
47
48
49
50
51
52
53
54
# File 'lib/bolt/transport/remote.rb', line 45

def run_task(target, task, arguments, options = {})
  proxy_target = get_proxy(target)
  transport = @executor.transport(proxy_target.protocol)
  arguments = arguments.merge('_target' => target.to_h.reject { |_, v| v.nil? })

  remote_task = task.remote_instance

  result = transport.run_task(proxy_target, remote_task, arguments, options)
  Bolt::Result.new(target, value: result.value)
end