Class: GCE::Host::HostData
- Inherits:
-
Object
- Object
- GCE::Host::HostData
- Defined in:
- lib/gce/host/host_data.rb
Overview
Represents each host
Instance Attribute Summary collapse
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
Instance Method Summary collapse
- #creation_timestamp ⇒ Object
- #hostname ⇒ Object
- #info ⇒ Object
-
#initialize(instance) ⇒ HostData
constructor
:hostname, # hostname :roles, # roles.split(‘,’) such as web:app1,db:app1 :instance, # Aws::GCE::Types::Instance itself.
- #inspect ⇒ Object
- #instance_id ⇒ Object
-
#ip ⇒ Object
compatibility with dino-host.
- #machine_type ⇒ Object
-
#match?(condition) ⇒ Boolean
match with condition or not.
- #private_ip_address ⇒ Object
- #private_ip_addresses ⇒ Object
- #provisioning? ⇒ Boolean
- #public_ip_address ⇒ Object
- #public_ip_addresses ⇒ Object
- #roles ⇒ Object
- #running? ⇒ Boolean
- #staging? ⇒ Boolean
-
#start_date ⇒ Object
compatibility with dino-host.
- #stopping? ⇒ Boolean
-
#terminated? ⇒ Boolean
NOTE: this is stopped status in the case of GCE unlike EC2.
- #to_hash ⇒ Object
-
#usages ⇒ Object
compatibility with dino-host.
- #zone ⇒ Object
Constructor Details
#initialize(instance) ⇒ HostData
:hostname, # hostname :roles, # roles.split(‘,’) such as web:app1,db:app1 :instance, # Aws::GCE::Types::Instance itself
and OPTIONAL_ARRAY_KEYS, OPTIONAL_STRING_KEYS
14 15 16 |
# File 'lib/gce/host/host_data.rb', line 14 def initialize(instance) @instance = instance end |
Instance Attribute Details
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
7 8 9 |
# File 'lib/gce/host/host_data.rb', line 7 def instance @instance end |
Instance Method Details
#creation_timestamp ⇒ Object
77 78 79 |
# File 'lib/gce/host/host_data.rb', line 77 def instance. end |
#hostname ⇒ Object
18 19 20 |
# File 'lib/gce/host/host_data.rb', line 18 def hostname instance.name end |
#info ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/gce/host/host_data.rb', line 150 def info if self.class.display_short_info? info = "#{hostname}:#{status}" info << "(#{roles.join(',')})" unless roles.empty? info << "[#{.join(',')}]" unless .empty? info << "{#{service}}" unless service.empty? info else to_hash.to_s end end |
#inspect ⇒ Object
162 163 164 |
# File 'lib/gce/host/host_data.rb', line 162 def inspect sprintf "#<GCE::Host::HostData %s>", info end |
#instance_id ⇒ Object
46 47 48 |
# File 'lib/gce/host/host_data.rb', line 46 def instance_id instance.id end |
#ip ⇒ Object
compatibility with dino-host
82 83 84 |
# File 'lib/gce/host/host_data.rb', line 82 def ip private_ip_address end |
#machine_type ⇒ Object
54 55 56 |
# File 'lib/gce/host/host_data.rb', line 54 def machine_type instance.machine_type.split('/').last end |
#match?(condition) ⇒ Boolean
match with condition or not
120 121 122 123 124 125 |
# File 'lib/gce/host/host_data.rb', line 120 def match?(condition) return false unless role_match?(condition) return false unless status_match?(condition) return false unless instance_match?(condition) true end |
#private_ip_address ⇒ Object
58 59 60 |
# File 'lib/gce/host/host_data.rb', line 58 def private_ip_address instance.network_interfaces.first.network_ip end |
#private_ip_addresses ⇒ Object
62 63 64 |
# File 'lib/gce/host/host_data.rb', line 62 def private_ip_addresses instance.network_interfaces.map(&:network_ip) end |
#provisioning? ⇒ Boolean
113 114 115 |
# File 'lib/gce/host/host_data.rb', line 113 def provisioning? instance.status == "PROVISIONING" end |
#public_ip_address ⇒ Object
66 67 68 69 |
# File 'lib/gce/host/host_data.rb', line 66 def public_ip_address access_configs = instance.network_interfaces.first.access_configs access_configs ? access_configs.first.nat_ip : nil end |
#public_ip_addresses ⇒ Object
71 72 73 74 75 |
# File 'lib/gce/host/host_data.rb', line 71 def public_ip_addresses instance.network_interfaces.map {|i| i.access_configs ? i.access_configs.map(&:nat_ip) : nil }.flatten(1).compact end |
#roles ⇒ Object
22 23 24 25 26 |
# File 'lib/gce/host/host_data.rb', line 22 def roles return @roles if @roles roles = find_array_key(Config.roles_key) @roles = roles.map {|role| GCE::Host::RoleData.build(role) } end |
#running? ⇒ Boolean
105 106 107 |
# File 'lib/gce/host/host_data.rb', line 105 def running? instance.status == "RUNNING" end |
#staging? ⇒ Boolean
109 110 111 |
# File 'lib/gce/host/host_data.rb', line 109 def staging? instance.status == "STAGING" end |
#start_date ⇒ Object
compatibility with dino-host
87 88 89 |
# File 'lib/gce/host/host_data.rb', line 87 def start_date end |
#stopping? ⇒ Boolean
101 102 103 |
# File 'lib/gce/host/host_data.rb', line 101 def stopping? instance.status == "STOPPING" end |
#terminated? ⇒ Boolean
NOTE: this is stopped status in the case of GCE unlike EC2
97 98 99 |
# File 'lib/gce/host/host_data.rb', line 97 def terminated? instance.status == "TERMINATED" end |
#to_hash ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/gce/host/host_data.rb', line 127 def to_hash params = { "hostname" => hostname, "roles" => roles, } Config.optional_string_keys.each do |key| field = StringUtil.underscore(key) params[field] = send(field) end Config.optional_array_keys.each do |key| field = StringUtil.underscore(key) params[field] = send(field) end params.merge!( "zone" => zone, "machine_type" => machine_type, "private_ip_address" => private_ip_address, "public_ip_address" => public_ip_address, "creation_timestamp" => , Config.status => send(Config.status), ) end |
#usages ⇒ Object
compatibility with dino-host
92 93 94 |
# File 'lib/gce/host/host_data.rb', line 92 def usages roles end |
#zone ⇒ Object
50 51 52 |
# File 'lib/gce/host/host_data.rb', line 50 def zone instance.zone.split('/').last end |