Class: Hetzner::Bootstrap
- Inherits:
-
Object
- Object
- Hetzner::Bootstrap
- Defined in:
- lib/hetzner-bootstrap.rb,
lib/hetzner/bootstrap/target.rb,
lib/hetzner/bootstrap/version.rb,
lib/hetzner/bootstrap/template.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
'1.3.0'.freeze
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#api ⇒ Object
Returns the value of attribute api.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#targets ⇒ Object
Returns the value of attribute targets.
Instance Method Summary collapse
- #<<(param) ⇒ Object
- #add_target(param) ⇒ Object
- #bootstrap!(_options = {}) ⇒ Object
- #bootstrap_one_target!(target) ⇒ Object
-
#initialize(options = {}) ⇒ Bootstrap
constructor
A new instance of Bootstrap.
Constructor Details
#initialize(options = {}) ⇒ Bootstrap
Returns a new instance of Bootstrap.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/hetzner-bootstrap.rb', line 16 def initialize( = {}) @targets = [] @actions = %w(enable_rescue_mode reset wait_for_ssh_down wait_for_ssh_up installimage reboot wait_for_ssh_down wait_for_ssh_up verify_installation copy_ssh_keys update_local_known_hosts post_install post_install_remote) @api = [:api] @logger = [:logger] || Logger.new(STDOUT) end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
13 14 15 |
# File 'lib/hetzner-bootstrap.rb', line 13 def actions @actions end |
#api ⇒ Object
Returns the value of attribute api.
12 13 14 |
# File 'lib/hetzner-bootstrap.rb', line 12 def api @api end |
#logger ⇒ Object
Returns the value of attribute logger.
14 15 16 |
# File 'lib/hetzner-bootstrap.rb', line 14 def logger @logger end |
#targets ⇒ Object
Returns the value of attribute targets.
11 12 13 |
# File 'lib/hetzner-bootstrap.rb', line 11 def targets @targets end |
Instance Method Details
#<<(param) ⇒ Object
43 44 45 |
# File 'lib/hetzner-bootstrap.rb', line 43 def <<(param) add_target param end |
#add_target(param) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/hetzner-bootstrap.rb', line 35 def add_target(param) @targets << if param.is_a? Hetzner::Bootstrap::Target param else Hetzner::Bootstrap::Target.new(param) end end |
#bootstrap!(_options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/hetzner-bootstrap.rb', line 47 def bootstrap!( = {}) @targets.each do |target| # fork do target.use_api @api target.use_logger @logger bootstrap_one_target! target # end end # Process.waitall end |
#bootstrap_one_target!(target) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/hetzner-bootstrap.rb', line 58 def bootstrap_one_target!(target) actions = (target.actions || @actions) actions.each_with_index do |action, _index| loghack = "\b" * 24 # remove: "[bootstrap_one_target!] ".length target.logger.info "#{loghack}[#{action}] #{format '%-20s', 'START'}" d = Benchmark.realtime do target.send action end target.logger.info "#{loghack}[#{action}] FINISHED in #{format '%.5f', d} seconds" end rescue => e puts "something bad happened unexpectedly: #{e.class} => #{e.}" end |