-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathec2-create-keypair
More file actions
executable file
·35 lines (29 loc) · 966 Bytes
/
ec2-create-keypair
File metadata and controls
executable file
·35 lines (29 loc) · 966 Bytes
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
#! /usr/bin/env ruby
require "rubygems"
require "bundler/setup"
require "fog"
require "fileutils"
require 'trollop'
require 'yaml'
require_relative 'environment.rb'
require_relative 'menu.rb'
require_relative 'settings.rb'
include Environment
include Menu
opts = Trollop::options do
opt :environment, "", :type => :string
opt :name, "", :type => :string
end
environment = opts[:environment] || get_environment
settings = set_environment(environment)
key_pair_name = opts[:name] || input("what is the name of the ssh key pair?")
@connection = Fog::Compute::AWS.new(settings)
if @connection.key_pairs.all({'key-name' => [key_pair_name]}).size > 0
puts 'this key already exists'
else
settings= Settings.new(environment, key_pair_name)
key = @connection.key_pairs.create(:name => key_pair_name)
puts settings.ssh["key_path"]
File.open(settings.ssh["key_path"], 'w') {|f| f.write( key.private_key) }
File.chmod(0700, settings.ssh["key_path"])
end