Class: Eclair::EC2Item
- Inherits:
-
Item
- Object
- Item
- Eclair::EC2Item
show all
- Defined in:
- lib/eclair/providers/ec2/ec2_item.rb
Instance Attribute Summary collapse
Attributes inherited from Item
#selected, #visible
Instance Method Summary
collapse
Methods inherited from Item
#select, #title, #toggle_select
#config
Constructor Details
#initialize(instance) ⇒ EC2Item
Returns a new instance of EC2Item.
12
13
14
15
|
# File 'lib/eclair/providers/ec2/ec2_item.rb', line 12
def initialize instance
super()
@instance = instance
end
|
Instance Attribute Details
#instance ⇒ Object
Returns the value of attribute instance.
10
11
12
|
# File 'lib/eclair/providers/ec2/ec2_item.rb', line 10
def instance
@instance
end
|
Instance Method Details
#color ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'lib/eclair/providers/ec2/ec2_item.rb', line 21
def color
if @selected
[Curses::COLOR_YELLOW, -1, Curses::A_BOLD]
elsif !connectable?
[Curses::COLOR_BLACK, -1, Curses::A_BOLD]
else
[Curses::COLOR_WHITE, -1]
end
end
|
#command ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/eclair/providers/ec2/ec2_item.rb', line 31
def command
hosts = [@instance.public_ip_address, @instance.private_ip_address].compact
ports = config.ssh_ports
ssh_options = config.ssh_options
ssh_command = config.ssh_command
username = config.ssh_username.call(image)
key_cmd = config.ssh_keys[@instance.key_name] ? "-i #{config.ssh_keys[@instance.key_name]}" : ""
format = config.exec_format
joined_cmd = hosts.map do |host|
ports.map do |port|
{
"{ssh_command}" => ssh_command,
"{ssh_options}" => ssh_options,
"{port}" => port,
"{ssh_key}" => key_cmd,
"{username}" => username,
"{host}" => host,
}.reduce(format) { |cmd,pair| cmd.sub(pair[0],pair[1].to_s) }
end
end.join(" || ")
"echo Attaching to #{Shellwords.escape(name)} \\[#{@instance.instance_id}\\] && #{joined_cmd}"
end
|
#connectable? ⇒ Boolean
83
84
85
|
# File 'lib/eclair/providers/ec2/ec2_item.rb', line 83
def connectable?
![32, 48, 80].include?(@instance.state[:code])
end
|
64
65
66
67
68
69
|
# File 'lib/eclair/providers/ec2/ec2_item.rb', line 64
def
<<-EOS
#{name} (#{@instance.instance_id}) [#{@instance.state[:name]}] #{@instance.private_ip_address}
launched at #{@instance.launch_time.to_time}
EOS
end
|
#id ⇒ Object
17
18
19
|
# File 'lib/eclair/providers/ec2/ec2_item.rb', line 17
def id
@instance.id
end
|
#image ⇒ Object
56
57
58
|
# File 'lib/eclair/providers/ec2/ec2_item.rb', line 56
def image
@image ||= provider.find_image_by_id(@instance.image_id)
end
|
#info ⇒ Object
75
76
77
78
79
80
81
|
# File 'lib/eclair/providers/ec2/ec2_item.rb', line 75
def info
{
instance: @instance,
image: provider.image_loaded? ? image : "ami info not loaded yet",
security_groups: provider.security_group_loaded? ? security_groups : "sg info not loaded yet",
}
end
|
#label ⇒ Object
71
72
73
|
# File 'lib/eclair/providers/ec2/ec2_item.rb', line 71
def label
" - #{name} [#{launched_at}]"
end
|
#name ⇒ Object
87
88
89
90
91
92
93
94
95
|
# File 'lib/eclair/providers/ec2/ec2_item.rb', line 87
def name
return @name if @name
begin
tag = @instance.tags.find{|t| t.key == "Name"}
@name = tag ? tag.value : "noname"
rescue
@name = "terminated"
end
end
|
#search_key ⇒ Object
101
102
103
|
# File 'lib/eclair/providers/ec2/ec2_item.rb', line 101
def search_key
name.downcase
end
|
#security_groups ⇒ Object
97
98
99
|
# File 'lib/eclair/providers/ec2/ec2_item.rb', line 97
def security_groups
@security_groups ||= @instance.security_groups.map{|sg| provider.find_security_group_by_id(sg.group_id)}
end
|
#vpc ⇒ Object
60
61
62
|
# File 'lib/eclair/providers/ec2/ec2_item.rb', line 60
def vpc
@vpc ||= provider.find_vpc_by_id(@instance.vpc_id)
end
|