60: def ssh
61: opts = {}
62: opts[:group] = @option.group if @option.group
63: opts[:group] = :any if @option.all
64: opts[:id] = @option.instid if @option.instid
65:
66:
67: rye_opts = { :user => @global.user || Rudy.sysinfo.user, :debug => nil, :info => STDOUT }
68: if @@global.pkey
69: raise "Cannot find file #{@@global.pkey}" unless File.exists?(@@global.pkey)
70: raise InsecureKeyPermissions, @@global.pkey unless File.stat(@@global.pkey).mode == 33152
71: rye_opts[:keys] = @@global.pkey
72: end
73:
74:
75:
76:
77: if @argv.first
78: command, command_args = @argv.shift, @argv || []
79: li "#{command} #{command_args.join(' ')}" if @@global.verbose > 1
80:
81:
82: else
83: command, command_args = :interactive_ssh, @option.print.nil?
84: end
85:
86: checked = false
87: lt = Rudy::AWS::EC2::Instances.list_group(opts[:group], :running, opts[:id]) do |inst|
88:
89:
90: if @@global.quiet
91: print "You are #{rye_opts[:user].bright}. " if !checked
92: else
93: print "Connecting #{rye_opts[:user].bright}@#{inst.dns_public} "
94: li "(#{inst.awsid}, groups: #{inst.groups.join(', ')})"
95: end
96:
97:
98: if !checked && command != :interactive_ssh
99: execute_check(:medium) if rye_opts[:user] == "root"
100: checked = true
101: end
102:
103:
104: rbox = Rye::Box.new(inst.dns_public, rye_opts)
105: ret = rbox.send(command, command_args)
106: li ret unless command == :interactive_ssh
107: end
108: end