Class: Ridley::Bootstrapper
- Inherits:
-
Object
- Object
- Ridley::Bootstrapper
- Includes:
- Celluloid, Celluloid::Logger
- Defined in:
- lib/ridley/bootstrapper.rb,
lib/ridley/bootstrapper/context.rb
Overview
Defined Under Namespace
Classes: Context
Instance Attribute Summary collapse
- #contexts ⇒ Array<Bootstrapper::Context> readonly
- #hosts ⇒ Array<String> readonly
- #ssh_config ⇒ Hash readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hosts, options = {}) ⇒ Bootstrapper
constructor
A new instance of Bootstrapper.
- #run ⇒ SSH::ResponseSet
Constructor Details
#initialize(hosts, options = {}) ⇒ Bootstrapper
Returns a new instance of Bootstrapper.
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ridley/bootstrapper.rb', line 57 def initialize(hosts, = {}) @hosts = Array(hosts).collect(&:to_s).uniq @ssh_config = { user: .fetch(:ssh_user), password: [:ssh_password], keys: [:ssh_keys], timeout: ([:ssh_timeout] || 1.5) } @contexts = @hosts.collect do |host| Context.new(host, ) end end |
Instance Attribute Details
#contexts ⇒ Array<Bootstrapper::Context> (readonly)
25 26 27 |
# File 'lib/ridley/bootstrapper.rb', line 25 def contexts @contexts end |
#hosts ⇒ Array<String> (readonly)
22 23 24 |
# File 'lib/ridley/bootstrapper.rb', line 22 def hosts @hosts end |
#ssh_config ⇒ Hash (readonly)
28 29 30 |
# File 'lib/ridley/bootstrapper.rb', line 28 def ssh_config @ssh_config end |
Class Method Details
.default_template ⇒ String
13 14 15 |
# File 'lib/ridley/bootstrapper.rb', line 13 def default_template templates_path.join('omnibus.erb').to_s end |
Instance Method Details
#run ⇒ SSH::ResponseSet
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/ridley/bootstrapper.rb', line 72 def run if contexts.length >= 2 pool = SSH::Worker.pool(size: contexts.length, args: [self.ssh_config]) else pool = SSH::Worker.new(self.ssh_config) end responses = contexts.collect do |context| pool.future.run(context.host, context.boot_command) end.collect(&:value) SSH::ResponseSet.new.tap do |response_set| responses.each do || status, response = case status when :ok response_set.add_ok(response) when :error response_set.add_error(response) end end end ensure pool.terminate if pool end |