Class: EC2::Host::HostData
- Inherits:
-
Object
- Object
- EC2::Host::HostData
- Defined in:
- lib/ec2/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
- #availability_zone ⇒ Object
- #dedicated? ⇒ Boolean (also: #dedicated)
- #hostname ⇒ Object
- #info ⇒ Object
-
#initialize(instance) ⇒ HostData
constructor
:hostname, # tag:Name or hostname part of private_dns_name :roles, # tag:Roles.split(‘,’) such as web:app1,db:app1 :region, # ENV, :instance, # Aws::EC2::Types::Instance itself.
- #inspect ⇒ Object
- #instance_id ⇒ Object
- #instance_lifecycle ⇒ Object
- #instance_type ⇒ Object
-
#ip ⇒ Object
compatibility with dino-host.
- #launch_time ⇒ Object
-
#match?(condition) ⇒ Boolean
match with condition or not.
- #monitoring ⇒ Object
- #pending? ⇒ Boolean
- #placement ⇒ Object
- #private_ip_address ⇒ Object
- #public_ip_address ⇒ Object
- #region ⇒ Object
- #roles ⇒ Object
- #running? ⇒ Boolean
- #shutting_down? ⇒ Boolean
- #spot? ⇒ Boolean (also: #spot)
-
#start_date ⇒ Object
compatibility with dino-host.
- #state ⇒ Object
- #stopped? ⇒ Boolean
- #stopping? ⇒ Boolean
- #tenancy ⇒ Object
- #terminated? ⇒ Boolean
- #to_hash ⇒ Object
-
#usages ⇒ Object
compatibility with dino-host.
Constructor Details
#initialize(instance) ⇒ HostData
:hostname, # tag:Name or hostname part of private_dns_name :roles, # tag:Roles.split(‘,’) such as web:app1,db:app1 :region, # ENV, :instance, # Aws::EC2::Types::Instance itself
and OPTIONAL_ARRAY_TAGS, OPTIONAL_STRING_TAGS
15 16 17 |
# File 'lib/ec2/host/host_data.rb', line 15 def initialize(instance) @instance = instance end |
Instance Attribute Details
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
7 8 9 |
# File 'lib/ec2/host/host_data.rb', line 7 def instance @instance end |
Instance Method Details
#availability_zone ⇒ Object
82 83 84 |
# File 'lib/ec2/host/host_data.rb', line 82 def availability_zone instance.placement.availability_zone end |
#dedicated? ⇒ Boolean Also known as: dedicated
138 139 140 |
# File 'lib/ec2/host/host_data.rb', line 138 def dedicated? tenancy == 'dedicated' end |
#hostname ⇒ Object
19 20 21 22 23 24 |
# File 'lib/ec2/host/host_data.rb', line 19 def hostname return @hostname if @hostname @hostname = find_string_tag(Config.hostname_tag) @hostname = instance.private_dns_name.split('.').first if @hostname.empty? @hostname end |
#info ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/ec2/host/host_data.rb', line 182 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
194 195 196 |
# File 'lib/ec2/host/host_data.rb', line 194 def inspect sprintf "#<Aws::Host::HostData %s>", info end |
#instance_id ⇒ Object
50 51 52 |
# File 'lib/ec2/host/host_data.rb', line 50 def instance_id instance.instance_id end |
#instance_lifecycle ⇒ Object
90 91 92 |
# File 'lib/ec2/host/host_data.rb', line 90 def instance_lifecycle instance.instance_lifecycle end |
#instance_type ⇒ Object
54 55 56 |
# File 'lib/ec2/host/host_data.rb', line 54 def instance_type instance.instance_type end |
#ip ⇒ Object
compatibility with dino-host
95 96 97 |
# File 'lib/ec2/host/host_data.rb', line 95 def ip private_ip_address end |
#launch_time ⇒ Object
66 67 68 |
# File 'lib/ec2/host/host_data.rb', line 66 def launch_time instance.launch_time end |
#match?(condition) ⇒ Boolean
match with condition or not
146 147 148 149 150 151 152 153 |
# File 'lib/ec2/host/host_data.rb', line 146 def match?(condition) if condition[:state].nil? return false if (terminated? or shutting_down?) end return false unless role_match?(condition) return false unless instance_match?(condition) true end |
#monitoring ⇒ Object
74 75 76 |
# File 'lib/ec2/host/host_data.rb', line 74 def monitoring instance.monitoring.state end |
#pending? ⇒ Boolean
129 130 131 |
# File 'lib/ec2/host/host_data.rb', line 129 def pending? state == "pending" end |
#placement ⇒ Object
78 79 80 |
# File 'lib/ec2/host/host_data.rb', line 78 def placement instance.placement end |
#private_ip_address ⇒ Object
58 59 60 |
# File 'lib/ec2/host/host_data.rb', line 58 def private_ip_address instance.private_ip_address end |
#public_ip_address ⇒ Object
62 63 64 |
# File 'lib/ec2/host/host_data.rb', line 62 def public_ip_address instance.public_ip_address end |
#region ⇒ Object
32 33 34 |
# File 'lib/ec2/host/host_data.rb', line 32 def region Config.aws_region end |
#roles ⇒ Object
26 27 28 29 30 |
# File 'lib/ec2/host/host_data.rb', line 26 def roles return @roles if @roles roles = find_array_tag(Config.roles_tag) @roles = roles.map {|role| EC2::Host::RoleData.build(role) } end |
#running? ⇒ Boolean
125 126 127 |
# File 'lib/ec2/host/host_data.rb', line 125 def running? state == "running" end |
#shutting_down? ⇒ Boolean
113 114 115 |
# File 'lib/ec2/host/host_data.rb', line 113 def shutting_down? state == "shutting-down" end |
#spot? ⇒ Boolean Also known as: spot
133 134 135 |
# File 'lib/ec2/host/host_data.rb', line 133 def spot? instance_lifecycle == 'spot' end |
#start_date ⇒ Object
compatibility with dino-host
100 101 102 |
# File 'lib/ec2/host/host_data.rb', line 100 def start_date launch_time end |
#state ⇒ Object
70 71 72 |
# File 'lib/ec2/host/host_data.rb', line 70 def state instance.state.name end |
#stopped? ⇒ Boolean
121 122 123 |
# File 'lib/ec2/host/host_data.rb', line 121 def stopped? state == "stopped" end |
#stopping? ⇒ Boolean
117 118 119 |
# File 'lib/ec2/host/host_data.rb', line 117 def stopping? state == "stopping" end |
#tenancy ⇒ Object
86 87 88 |
# File 'lib/ec2/host/host_data.rb', line 86 def tenancy instance.placement.tenancy end |
#terminated? ⇒ Boolean
109 110 111 |
# File 'lib/ec2/host/host_data.rb', line 109 def terminated? state == "terminated" end |
#to_hash ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/ec2/host/host_data.rb', line 155 def to_hash params = { "hostname" => hostname, "roles" => roles, } Config..each do |tag| field = StringUtil.underscore(tag) params[field] = send(field) end Config..each do |tag| field = StringUtil.underscore(tag) params[field] = send(field) end params.merge!( "region" => region, "availability_zone" => availability_zone, "instance_id" => instance_id, "instance_type" => instance_type, "private_ip_address" => private_ip_address, "public_ip_address" => public_ip_address, "launch_time" => launch_time, "state" => state, "monitoring" => monitoring, "spot" => spot, ) end |
#usages ⇒ Object
compatibility with dino-host
105 106 107 |
# File 'lib/ec2/host/host_data.rb', line 105 def usages roles end |