Class: Eclair::GCEItem

Inherits:
Item
  • Object
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

Methods included from ConfigHelper

#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

#instanceObject (readonly)

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

#colorObject



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

#commandObject



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(" || ")
  # puts joined_cmd
  "echo Attaching to #{name} \\[#{name}\\] && #{joined_cmd}"
end

#connectable?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/eclair/providers/gce/gce_item.rb', line 81

def connectable?
  status == "RUNNING"
end

#descriptionObject



41
42
43
# File 'lib/eclair/providers/gce/gce_item.rb', line 41

def description
  @instance["description"]
end

#headerObject



29
30
31
32
33
34
35
# File 'lib/eclair/providers/gce/gce_item.rb', line 29

def header
  <<-EOS
  #{name} (#{public_ip_address} #{private_ip_address})
  launched at #{launch_time.to_time}
  #{description}
  EOS
end

#idObject



15
16
17
# File 'lib/eclair/providers/gce/gce_item.rb', line 15

def id
  @instance["id"]
end

#labelObject



37
38
39
# File 'lib/eclair/providers/gce/gce_item.rb', line 37

def label
  " - #{name} [#{launched_at}]"
end

#nameObject



45
46
47
# File 'lib/eclair/providers/gce/gce_item.rb', line 45

def name
  @instance["name"]
end

#private_ip_addressObject



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_addressObject



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_keyObject



85
86
87
# File 'lib/eclair/providers/gce/gce_item.rb', line 85

def search_key
  name.downcase
end