Class: EC2::Host::EC2Client
- Inherits:
-
Object
- Object
- EC2::Host::EC2Client
- Defined in:
- lib/ec2/host/ec2_client.rb
Instance Method Summary (collapse)
Instance Method Details
- (Object) instance_id
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ec2/host/ec2_client.rb', line 20 def instance_id return @instance_id if @instance_id begin http_conn = Net::HTTP.new('169.254.169.254') http_conn.open_timeout = 5 @instance_id = http_conn.start {|http| http.get('/latest/meta-data/instance-id').body } rescue Net::OpenTimeout raise "HTTP connection to 169.254.169.254 is timeout. Probably, not an EC2 instance?" end end |
- (Object) instances(condition)
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ec2/host/ec2_client.rb', line 7 def instances(condition) filters = build_filters(condition) instances = if filters ec2.describe_instances(filters: filters) elsif instance_id = condition[:instance_id] ec2.describe_instances(instance_ids: Array(instance_id)) else ec2.describe_instances end instances.reservations.map(&:instances).flatten end |