Class: Hetzner::Bootstrap

Inherits:
Object
  • Object
show all
Defined in:
lib/hetzner-bootstrap.rb,
lib/hetzner/bootstrap/target.rb,
lib/hetzner/bootstrap/version.rb,
lib/hetzner/bootstrap/template.rb

Defined Under Namespace

Classes: Target, Template

Constant Summary collapse

VERSION =
'1.4.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Bootstrap

Returns a new instance of Bootstrap.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/hetzner-bootstrap.rb', line 18

def initialize(options = {})
  @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         = options[:api]
  @logger      = options[:logger] || Logger.new(STDOUT)
end

Instance Attribute Details

#actionsObject

Returns the value of attribute actions.



15
16
17
# File 'lib/hetzner-bootstrap.rb', line 15

def actions
  @actions
end

#apiObject

Returns the value of attribute api.



14
15
16
# File 'lib/hetzner-bootstrap.rb', line 14

def api
  @api
end

#loggerObject

Returns the value of attribute logger.



16
17
18
# File 'lib/hetzner-bootstrap.rb', line 16

def logger
  @logger
end

#targetsObject

Returns the value of attribute targets.



13
14
15
# File 'lib/hetzner-bootstrap.rb', line 13

def targets
  @targets
end

Instance Method Details

#<<(param) ⇒ Object



45
46
47
# File 'lib/hetzner-bootstrap.rb', line 45

def <<(param)
  add_target param
end

#add_target(param) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/hetzner-bootstrap.rb', line 37

def add_target(param)
  @targets << if param.is_a? Hetzner::Bootstrap::Target
                param
              else
                Hetzner::Bootstrap::Target.new(param)
              end
end

#bootstrap!(_options = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/hetzner-bootstrap.rb', line 49

def bootstrap!(_options = {})
  @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



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/hetzner-bootstrap.rb', line 60

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 StandardError => e
  puts "something bad happened unexpectedly: #{e.class} => #{e.message}"
end