Class: Eclair::GCEItem
- Inherits:
-
Item
- Object
- Item
- Eclair::GCEItem
show all
- Defined in:
- lib/eclair/providers/gce/gce_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) ⇒ GCEItem
Returns a new instance of GCEItem.
10
11
12
13
|
# File 'lib/eclair/providers/gce/gce_item.rb', line 10
def initialize instance
super()
@instance = instance
end
|
Instance Attribute Details
#instance ⇒ Object
Returns the value of attribute instance.
8
9
10
|
# File 'lib/eclair/providers/gce/gce_item.rb', line 8
def instance
@instance
end
|
Instance Method Details
#color ⇒ Object
19
20
21
22
23
24
25
26
27
|
# File 'lib/eclair/providers/gce/gce_item.rb', line 19
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/eclair/providers/gce/gce_item.rb', line 57
def command
hosts = [private_ip_address, public_ip_address].compact
ports = config.ssh_ports
ssh_options = config.ssh_options
ssh_command = config.ssh_command
username = "ubuntu"
format = config.exec_format
joined_cmd = hosts.map do |host|
ports.map do |port|
{
"{ssh_command}" => ssh_command,
"{ssh_options}" => ssh_options,
"{port}" => port,
"{username}" => username,
"{host}" => host,
"{ssh_key}" => ""
}.reduce(format) { |cmd,pair| cmd.sub(pair[0],pair[1].to_s) }
end
end.join(" || ")
"echo Attaching to #{name} \\[#{name}\\] && #{joined_cmd}"
end
|
#connectable? ⇒ Boolean
81
82
83
|
# File 'lib/eclair/providers/gce/gce_item.rb', line 81
def connectable?
status == "RUNNING"
end
|
#description ⇒ Object
41
42
43
|
# File 'lib/eclair/providers/gce/gce_item.rb', line 41
def description
@instance["description"]
end
|
29
30
31
32
33
34
35
|
# File 'lib/eclair/providers/gce/gce_item.rb', line 29
def
<<-EOS
#{name} (#{public_ip_address} #{private_ip_address})
launched at #{launch_time.to_time}
#{description}
EOS
end
|
#id ⇒ Object
15
16
17
|
# File 'lib/eclair/providers/gce/gce_item.rb', line 15
def id
@instance["id"]
end
|
#label ⇒ Object
37
38
39
|
# File 'lib/eclair/providers/gce/gce_item.rb', line 37
def label
" - #{name} [#{launched_at}]"
end
|
#name ⇒ Object
45
46
47
|
# File 'lib/eclair/providers/gce/gce_item.rb', line 45
def name
@instance["name"]
end
|
#private_ip_address ⇒ Object
53
54
55
|
# File 'lib/eclair/providers/gce/gce_item.rb', line 53
def private_ip_address
@instance.dig("networkInterfaces", 0, "networkIP")
end
|
#public_ip_address ⇒ Object
49
50
51
|
# File 'lib/eclair/providers/gce/gce_item.rb', line 49
def public_ip_address
@instance.dig("networkInterfaces", 0, "accessConfigs", 0, "natIP")
end
|
#search_key ⇒ Object
85
86
87
|
# File 'lib/eclair/providers/gce/gce_item.rb', line 85
def search_key
name.downcase
end
|