Class: Exos::Commands::SSH
Constant Summary collapse
- PROTOCOLS =
%w(mosh ssh).freeze
Instance Attribute Summary
Attributes inherited from Command
Instance Method Summary collapse
Methods inherited from Command
Constructor Details
This class inherits a constructor from Exos::Commands::Command
Instance Method Details
#run ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/exos/commands/ssh.rb', line 23 def run # Handle "connection string" style parameter. if conn = args.first user, str = conn.split("@") abort "Malformed parameter: user@[instance-name|instance-id]." if str.nil? str.match(/i-[0-9a-f]+/i) ? .id = str : .name = str else user = .user end abort "Must specify username with -u or 'user@instance-name' parameter." if user.nil? if .id instance = ec2.servers.all("instance-id" => .id).first elsif .name instance = ec2.servers.all("tag:Name" => .name).first else instance = ec2.servers.all("tag:Role" => .role).first end abort "No instance found. Exiting." if instance.nil? puts "Connecting to instance #{ instance.id }..." host = "#{ user }@#{ instance.dns_name }" if .proto abort "Unknown protocol '#{ .proto }'." unless PROTOCOLS.include?(.proto) exec "#{ .proto } #{ host }" else begin exec "mosh #{ host }" rescue Errno::ENOENT exec "ssh #{ host }" end end end |