Class: SSHKit::Custom::Config::Runner::Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/sshkit/custom/config/runner/abstract.rb

Direct Known Subclasses

Group, Parallel, Sequential

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ Abstract

Returns a new instance of Abstract.



42
43
44
# File 'lib/sshkit/custom/config/runner/abstract.rb', line 42

def initialize(options = nil)
  @options     = options || {}
end

Instance Attribute Details

#backendsObject

Returns the value of attribute backends.



9
10
11
# File 'lib/sshkit/custom/config/runner/abstract.rb', line 9

def backends
  @backends
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/sshkit/custom/config/runner/abstract.rb', line 10

def options
  @options
end

#wait_interval=(value) ⇒ Object

Sets the attribute wait_interval

Parameters:

  • value

    the value to set the attribute wait_interval to.



11
12
13
# File 'lib/sshkit/custom/config/runner/abstract.rb', line 11

def wait_interval=(value)
  @wait_interval = value
end

Class Method Details

.active_backendObject



34
35
36
# File 'lib/sshkit/custom/config/runner/abstract.rb', line 34

def self.active_backend
  scope[:active_backend]
end

.active_backend=(new_backend) ⇒ Object



38
39
40
# File 'lib/sshkit/custom/config/runner/abstract.rb', line 38

def self.active_backend=(new_backend)
  scope[:active_backend]=new_backend
end

.create_runner(opts) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sshkit/custom/config/runner/abstract.rb', line 13

def self.create_runner(opts)
  opts_with_defaults = { in: :parallel }.merge(opts)

  case opts_with_defaults[:in]
    when :parallel then Parallel
    when :sequence then Sequential
    when :groups then Group
    else
      raise RuntimeError, "Don't know how to handle run style #{opts_with_defaults[:in].inspect}"
  end.new(opts_with_defaults)

end

.scopeObject



30
31
32
# File 'lib/sshkit/custom/config/runner/abstract.rb', line 30

def self.scope
  @scope ||= ScopedStorage::Scope.new('sshkit_runner', scope_storage)
end

.scope_storageObject



26
27
28
# File 'lib/sshkit/custom/config/runner/abstract.rb', line 26

def self.scope_storage
  ScopedStorage::ThreadLocalStorage
end

Instance Method Details

#active_backendObject



46
47
48
# File 'lib/sshkit/custom/config/runner/abstract.rb', line 46

def active_backend
  self.class.active_backend
end

#active_backend=(new_backend) ⇒ Object



50
51
52
# File 'lib/sshkit/custom/config/runner/abstract.rb', line 50

def active_backend=(new_backend)
  self.class.active_backend=new_backend
end

#apply_to_bck(backend, &block) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/sshkit/custom/config/runner/abstract.rb', line 72

def apply_to_bck(backend, &block)
  begin

    self.active_backend = backend
    block.call(backend.host)

  rescue Exception => e
    e2 = ExecuteError.new e
    raise e2, "Exception while executing on host #{backend}: #{e.message}"
  ensure
    self.active_backend = nil
  end
end

#send_cmd(cmd, *args, &block) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/sshkit/custom/config/runner/abstract.rb', line 54

def send_cmd(cmd, *args, &block)

  begin

    if block
      args = Array(block.call(active_backend.host))
    end

    active_backend.send(cmd, *args)

  rescue Exception => e
    e2 = ExecuteError.new e
    raise e2, "Exception while executing on host #{active_backend.host}: #{e.message}"
  end

end