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
3 changes: 3 additions & 0 deletions EC2ssh.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,18 @@ Gem::Specification.new do |s|
s.add_runtime_dependency(%q<highline>, [">= 1.5.2"])
s.add_runtime_dependency(%q<aws>, [">= 2.5.6"])
s.add_runtime_dependency(%q<activesupport>, [">= 2.3.14"])
s.add_runtime_dependency(%q<terminal-table>, [">= 1.4.5"])
else
s.add_dependency(%q<highline>, [">= 1.5.2"])
s.add_dependency(%q<aws>, [">= 2.5.6"])
s.add_dependency(%q<activesupport>, [">= 2.3.14"])
s.add_dependency(%q<terminal-table>, [">= 1.4.5"])
end
else
s.add_dependency(%q<highline>, [">= 1.5.2"])
s.add_dependency(%q<aws>, [">= 2.5.6"])
s.add_dependency(%q<activesupport>, [">= 2.3.14"])
s.add_dependency(%q<terminal-table>, [">= 1.4.5"])
end
end

7 changes: 6 additions & 1 deletion lib/ec2ssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
silence_warnings { require 'aws' }
require 'yaml'
require 'fileutils'
require 'terminal-table'

module Ec2ssh

Expand All @@ -19,16 +20,20 @@ def initialize(file = "~/.ec2ssh", account=:default)
def select_instance(instances=[], filter_tag = nil, filter_ip = nil, filter_sg = nil)
# TODO: Order by region
# TODO: Ansi colors https://github.com/JEG2/highline/blob/master/examples/ansi_colors.rb
account_name = @config[:account_name]
instances = get_all_ec2_instances
n = 0
hostnames = []
rows = []
instances.each do |i|
if i[:aws_state] == "running" && check_filter_tag( filter_tag, i ) && check_filter_ip( filter_ip, i ) && check_filter_sg( filter_sg, i )
puts "#{n}. #{i[:aws_instance_id]}: %-20s\t%-50s\t%-10s\t%s" % [ i[:tags]["Name"], i[:aws_groups].join(','), i[:dns_name], i[:aws_private_ip_address] ]
rows << [n, i[:aws_instance_id], i[:tags]["Name"], [:aws_groups].join(','), i[:dns_name], i[:aws_private_ip_address]]
hostnames << i[:dns_name]
n = n + 1
end
end
table = Terminal::Table.new :title => account_name, :headings => ['#', 'instance_id', 'name', 'SG', 'dns_name', 'private_ip'], :rows => rows
puts table
template = @config[:template] || "ssh #{Etc.getlogin}@<instance>"
selected_host = ask("Host? ", Integer) { |q| q.in = 0..hostnames.count }
command = template.gsub("<instance>",hostnames[selected_host])
Expand Down
3 changes: 3 additions & 0 deletions lib/templates/ec2ssh_config_sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
---
# Default account to use
:default:
# account_name it is just for show the name on server list
:account_name: default
:id: yourid
:key: yourkey
# Regions to check for running instances
:regions:
- us-east-1
# Another account, you can ec2ssh second
:second:
:account_name: second
:id: yourid
:key: yourkey
:regions:
Expand Down