Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 107 additions & 5 deletions Rakefile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@
File.join(STATEDIR, 'config.yml'),
]

KNOWN_ISPS = {
hetzner: {
name: "Hetzner (hetzner.com)",
keys: %i{user password},
},
ovh: {
name: "OVH (ovh.com)",
keys: %i{app_key app_secret consumer_key},
},
serverscom: {
name: "Servers.com",
keys: %i{mail token password},
},
leaseweb: {
multiple: true,
name: "Leaseweb (leaseweb.com)",
keys: %i{apikey},
},
}


$conf = {}
CONFIG_FILES.each do |config_yml|
$conf.deep_merge!(YAML.load_file(config_yml).deep_symbolize_keys) if File.exist?(config_yml)
Expand Down Expand Up @@ -58,9 +79,90 @@
puts "STATEDIR=#{STATEDIR}: #{File.directory?(STATEDIR)}"
puts "PRIVATE_SSH_KEY=#{PRIVATE_SSH_KEY}: #{File.exist?(PRIVATE_SSH_KEY)}"
puts
puts "Hetzner account configured: #{!!$conf[:hetzner]}"
puts "OVH account configured: #{!!$conf[:ovh]}"
puts "Soyoustart account configured: #{!!$conf[:soyoustart]}"
puts "Servers.com account configured: #{!!$conf[:serverscom]}"
puts "Leaseweb accounts configured: #{($conf[:leaseweb] && $conf[:leaseweb].keys.join(', ')) || "none"}"
KNOWN_ISPS.each do |isp,isp_setup|
if isp_setup[:multiple]
puts "#{isp_setup[:name]} accounts configured: #{($conf[isp] && $conf[isp].keys.join(', ')) || "none"}"
else
puts "#{isp_setup[:name]}: #{!!$conf[isp]}"
end
end
end

def prompt(*args)
print *args, ": "
STDIN.gets.chomp
end

def yesno(*args)
response = nil
loop do
response = prompt(*args," (Y/N)").upcase
break if ['Y', 'N'].include? response
end
response == 'Y'
end

def prompt_config(isp_setup, isp_conf, isp_name)
puts isp_name
isp_setup[:keys].each do |isp_key|
new_value = prompt("#{isp_key} (current '#{isp_conf[isp_key]}', blank to not touch, '.' to remove)")
if new_value == '.'
isp_conf.delete(isp_key)
elsif new_value != ""
isp_conf[isp_key] = new_value
end
end
end

desc "interactively setup a minimal config"
task :configure do
local_conf = {}
local_conf.deep_merge!(YAML.load_file(CONFIG_FILES[-1]).deep_symbolize_keys) if File.exist?(CONFIG_FILES[-1])

KNOWN_ISPS.each do |isp, isp_setup|
isp_conf = local_conf[isp] || ($conf[isp] || {})

next unless yesno("Configure #{isp_setup[:name]}")

if isp_setup[:multiple]
loop do
puts "#{isp_setup[:name]} - known accounts: #{isp_conf.keys.join(', ')}"
subaccount = prompt "ID for subaccount (blank for done)"
if subaccount != ""
prompt_config(isp_setup, isp_conf[subaccount.to_sym] ||= {}, "#{isp_setup[:name]}[#{subaccount}]")
else
break
end
end
else
prompt_config(isp_setup, isp_conf, isp_setup[:name])
end
if isp_conf.values.all?{|r| r == ''}
local_conf.delete(isp)
else
puts YAML.dump(isp_conf)
if yesno("Keep this config for #{isp}")
local_conf[isp] = isp_conf
end
end
end

%x{mkdir -p #{File.dirname(CONFIG_FILES[-1])}}
File.write(CONFIG_FILES[-1],YAML.dump(local_conf))

if File.exist?(PRIVATE_SSH_KEY)
puts "SSH keys exists, keeping"
else
puts "No ssh key, generating now."
puts "For OVH, please uploaded it in the web ui" if local_conf[:ovh]
puts "Generating a private key. For OVH please upload it in the web ui"
%x{mkdir -p #{File.dirname(PRIVATE_SSH_KEY)}}
%x{ssh-keygen -t rsa -f #{PRIVATE_SSH_KEY} -N ''}
end

pem_file = "#{PRIVATE_SSH_KEY}.pub.pem"
if !File.exist?(pem_file)
puts "Also creating a PEM file for the SSH key"
%x{ssh-keygen -f #{PRIVATE_SSH_KEY} -e -m pem > #{pem_file}}
end
end
2 changes: 2 additions & 0 deletions setup/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ rvm install `cat .ruby-version`
cd $ROOT_DIR
gem install bundler
bundle install
rake configure
rake
1 change: 0 additions & 1 deletion tasks/support/baremetal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def baremetal_isps
# TODO: generic bootstrap
hetzner_init
leaseweb_init
soyoustart_init
ovh_init
serverscom_init
end
Expand Down
4 changes: 2 additions & 2 deletions tasks/support/leaseweb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def leaseweb_init
host[:isp][:rack] = info['location']['rack']
host[:isp][:costs] = details['contract']['pricePerFrequency']
host[:isp][:currency] = details['contract']['currency'] || 'USD'
hardware_details['result']['network'].each_with_index.map { |interface, index|
hardware_details['result']['network'].each_with_index.map { |interface, index|
#puts interface['settings']['speed'].class
unless interface['settings']['speed'].nil?
unless interface['settings']['speed'].nil?
host[:isp]["network_#{index}".to_sym] = {}
host[:isp]["network_#{index}".to_sym][:mac] = interface['mac_address']
host[:isp]["network_#{index}".to_sym][:speed] = interface['settings']['speed']
Expand Down
54 changes: 0 additions & 54 deletions tasks/support/soyoustart.rb

This file was deleted.