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
61
62
63
64
65
66
|
# File 'lib/routes/ssh.rb', line 29
def opts_routing
puts
result = Blufin::Terminal::execute('awx l -r EC2Instances -j', capture: true, text: 'Getting EC2 instance data...')
puts
begin
instances = JSON.parse(result)
rescue => e
puts
puts result
Blufin::Terminal::error('Failed to parse AWS response JSON.', e.message)
end
accessible_instances = []
instances.each do |instance|
if instance.has_key?('State') && instance['State']['Name'] == 'running'
accessible_instances << {
:instance_id => instance['InstanceId'],
:public_ip => instance['PublicIpAddress'],
:public_dns => instance['PublicDnsName'],
:key => instance.has_key?('KeyName') ? instance['KeyName'] : "\xe2\x80\x94",
:tags => instance['Tags'],
:region => instance['region'],
:availability_zone => instance['Placement']['AvailabilityZone']
}
end
end
puts
puts "\x1B[38;5;198m#{accessible_instances.to_yaml}\x1B[0m"
end
|