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
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/aws/opsworks_cssh.rb', line 9
def self.start_opsworks_cssh(stack_name,user,force_private)
@resp_instances
options = {}
options['user'] = user
opsworks = Aws::OpsWorks::Client.new(region: 'us-east-1')
resp_stacks = opsworks.describe_stacks
resp_stacks.stacks.each do |stack|
if stack.name == stack_name
@resp_instances = opsworks.describe_instances({:stack_id => stack.stack_id})
break
end
end
unless @resp_instances
$stderr.puts "No such stack: #{stack_name}"
exit 1
end
dns = @resp_instances.instances.map { |instance|
if force_private == "private"
instance.private_ip || instance.public_ip
else
instance.public_ip || instance.private_ip
end
}
cssh = (/darwin/ =~ RUBY_PLATFORM) ? 'csshX' : 'cssh'
cmd = "#{cssh} -l #{options['user']} #{dns.join ' '}"
puts "Connecting to #{dns.length} instances"
puts cmd
exec cmd
end
|