Class: Ec2ssh::App
- Inherits:
-
Object
- Object
- Ec2ssh::App
- Defined in:
- lib/ec2ssh.rb
Instance Method Summary collapse
-
#initialize(file = "~/.ec2ssh", account = :default) ⇒ App
constructor
A new instance of App.
- #select_instance(instances = []) ⇒ Object
Constructor Details
#initialize(file = "~/.ec2ssh", account = :default) ⇒ App
Returns a new instance of App.
15 16 17 |
# File 'lib/ec2ssh.rb', line 15 def initialize(file = "~/.ec2ssh", account=:default) @config = read_aws_config(file, account) end |
Instance Method Details
#select_instance(instances = []) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ec2ssh.rb', line 19 def select_instance(instances=[]) # TODO: Order by region # TODO: Ansi colors https://github.com/JEG2/highline/blob/master/examples/ansi_colors.rb instances = get_all_ec2_instances n = 0 hostnames = [] instances.each do |i| if i[:aws_state] == "running" puts "#{n}. #{i[:aws_instance_id]}: %-20s\t%-60s\t%-10s\t%s" % [ i[:tags]["Name"], i[:aws_groups].join(','), i[:ssh_key_name], i[:dns_name] ] hostnames << i[:dns_name] n = n + 1 end end 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]) exec(command) end |