Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rmoriz committed Jan 26, 2016
1 parent c193007 commit a586377
Show file tree
Hide file tree
Showing 11 changed files with 246 additions and 135 deletions.
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--require spec_helper
17 changes: 17 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Metrics/LineLength:
Enabled: false

Metrics/MethodLength:
Enabled: false

Style/FileName:
Enabled: false

Style/Documentation:
Enabled: false

Metrics/ClassLength:
Enabled: false

Metrics/AbcSize:
Enabled: false
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source "https://rubygems.org"
source 'https://rubygems.org'

# Specify your gem's dependencies in hetzner.gemspec
gemspec
23 changes: 13 additions & 10 deletions example.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
require "rubygems"
require "hetzner-bootstrap"
require 'rubygems'
require 'hetzner-bootstrap'

# get your API login from Hetzner's customer panel at: https://robot.your-server.de/
# assign env variables:
Expand All @@ -10,7 +10,10 @@
# rbenv-tip: checkout rbenv-vars, it's awesome!
# https://github.com/sstephenson/rbenv-vars/

bs = Hetzner::Bootstrap.new(api: Hetzner::API.new(ENV['ROBOT_USER'], ENV['ROBOT_PASSWORD']))
bs = Hetzner::Bootstrap.new(api: Hetzner::API.new(
ENV['ROBOT_USER'],
ENV['ROBOT_PASSWORD']
))

# 2 disks, software raid 1, etc.
template = <<EOT
Expand Down Expand Up @@ -91,18 +94,18 @@
EOT

# the post_install hook is a great place to setup further software/system provisioning
# the post_install hook is a great place to setup further
# software/system provisioning
#
post_install = <<EOT
# knife bootstrap <%= ip %> -N <%= hostname %> "role[base],role[kvm_host]"
EOT

# duplicate entry for each system
bs << { :ip => "1.2.3.4",
:template => template, # string will be parsed by erubis
:hostname => 'server100.example.com', # will be used for setting the systems' hostname
:public_keys => "~/.ssh/id_dsa.pub", # will be copied over to the freshly bootstrapped system
:post_install => post_install } # will be called locally at the end and can be used e.g. to run a chef bootstrap
bs << { ip: '1.2.3.4',
template: template, # string will be parsed by erubis
hostname: 'server100', # sets hostname
public_keys: '~/.ssh/id_dsa.pub', # will be copied to your system
post_install: post_install } # will be executed *locally* at the end

bs.bootstrap!

25 changes: 13 additions & 12 deletions hetzner-bootstrap.gemspec
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "hetzner/bootstrap/version"
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
require 'hetzner/bootstrap/version'

Gem::Specification.new do |s|
s.name = "hetzner-bootstrap"
s.name = 'hetzner-bootstrap'
s.version = Hetzner::Bootstrap::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Roland Moriz"]
s.email = ["roland@moriz.de"]
s.homepage = "http://moriz.de/opensource/hetzner-api"
s.summary = %q{Easy bootstrapping of hetzner.de rootservers using hetzner-api}
s.description = %q{Easy bootstrapping of hetzner.de rootservers using hetzner-api}
s.authors = ['Roland Moriz']
s.email = ['roland@moriz.de']
s.homepage = 'http://moriz.de/opensource/hetzner-api'
s.summary = 'Easy bootstrapping of hetzner.de rootservers using hetzner-api'
s.description = 'Easy bootstrapping of hetzner.de rootservers using hetzner-api'

s.add_dependency 'hetzner-api', '>= 1.1.0'
s.add_dependency 'net-ssh', '>= 2.6.0'
s.add_dependency 'erubis', '>= 2.7.0'

s.add_development_dependency "rspec", ">= 2.13.0"
s.add_development_dependency "rake"
s.add_development_dependency 'rspec', '~> 3.4.0'
s.add_development_dependency 'rake'
s.add_development_dependency 'rubocop', '~> 0.36.0'

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
s.require_paths = ['lib']
end
32 changes: 15 additions & 17 deletions lib/hetzner-bootstrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,40 @@ def initialize(options = {})
end

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

def <<(param)
add_target param
end

def bootstrap!(options = {})
def bootstrap!(_options = {})
@targets.each do |target|
#fork do
target.use_api @api
target.use_logger @logger
bootstrap_one_target! target
#end
# fork do
target.use_api @api
target.use_logger @logger
bootstrap_one_target! target
# end
end
#Process.waitall
# Process.waitall
end

def bootstrap_one_target!(target)
actions = (target.actions || @actions)
actions.each_with_index do |action, index|

actions.each_with_index do |action, _index|
loghack = "\b" * 24 # remove: "[bootstrap_one_target!] ".length
target.logger.info "#{loghack}[#{action}] #{sprintf "%-20s", "START"}"
target.logger.info "#{loghack}[#{action}] #{format '%-20s', 'START'}"
d = Benchmark.realtime do
target.send action
end
target.logger.info "#{loghack}[#{action}] FINISHED in #{sprintf "%.5f",d} seconds"
target.logger.info "#{loghack}[#{action}] FINISHED in #{format '%.5f', d} seconds"
end
rescue => e
puts "something bad happened unexpectedly: #{e.class} => #{e.message}"
end
end
end

Loading

0 comments on commit a586377

Please sign in to comment.