Top Level Namespace

Defined Under Namespace

Modules: Base Classes: GTBase, GTCluster

Instance Method Summary collapse

Instance Method Details

#setupObject



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/app.rb', line 1

def setup
  yaml = Hash.new
  unless File.directory?("#{ENV['HOME']}/.gaptool-ma") || File.exists?("#{ENV['HOME']}/.gaptool-ma")
    puts "Welcome to gaptool setup\nThis will set up your ~/.gaptool-ma configuration\nYou will need very little info here if you are NOT creating new nodes (e.g. just configuring and deploying)\nIf you ARE using the the 'init' facility, you will need your AWS ID, Secret, and EC2 PEM keys for relevant Availability Zones.".color(:red)
    puts "Starting with your AWS ID/Secret.\nIf you don't have these, just press enter.".color(:cyan)
    print "Enter your AWS ID: "
    yaml['aws_id'] = gets.chomp
    print "enter your AWS Secret: "
    yaml['aws_secret'] = gets.chomp
    puts "Now we will go through each AWS zone\nEnter a key NAME you have in each zone that you want associated with gaptool nodes.\nIf you don't have one, press enter.\nAfter each key, paste the path to the downloaded key.".color(:cyan)
    zones = [ 'us-east-1', 'us-west-1', 'us-west-2', 'eu-west-1', 'ap-southeast-1', 'ap-northeast-1', 'sa-east-1' ]
    yaml['awskeys'] = Hash.new
    yaml['initkeys'] = Hash.new
    zones.each do |zone|
      print "#{zone}: "
      yaml['awskeys'][zone] = gets.chomp
      if yaml['awskeys'][zone] != ''
        print "Path to #{zone}.pem: "
        yaml['initkeys'][yaml['awskeys'][zone]] = File.read(File.expand_path(gets.chomp))
      end
    end
    key = OpenSSL::PKey::RSA.new 2048
    type = key.ssh_type
    data = [ key.to_blob ].pack('m0')
    yaml['mykey'] = key.to_pem
    yaml['mypub'] = "#{type} #{data}"
    Dir.mkdir("#{ENV['HOME']}/.gaptool-ma")
    Dir.mkdir("#{ENV['HOME']}/.gaptool-ma/plugins")
    File.open("#{ENV['HOME']}/.gaptool-ma/plugins.yml", "w") {}
    File.open(File.expand_path("~/.gaptool-ma/user.yml"), 'w') {|f| f.write(yaml.to_yaml) }
    puts "Your ~/.gaptool-ma directory and user.yml have been configured\nPlease ask your administrator to provide you with a env.yml\nAdd the following public key to your github profile (or your git repo server)\nas well as in the authorized_keys file in your chef recipe for the admin user.".color(:cyan)
    puts yaml['mypub']
    exit 0
  end
end