Class: AwsEc2DnsName
- Inherits:
-
Object
- Object
- AwsEc2DnsName
- Defined in:
- lib/aws_ec2_dns_name.rb,
lib/aws_ec2_dns_name/instance.rb
Defined Under Namespace
Classes: Instance
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
-
#initialize(region: nil, access_key_id: nil, secret_access_key: nil) ⇒ AwsEc2DnsName
constructor
A new instance of AwsEc2DnsName.
- #instances ⇒ Array<AwsEc2DnsName:Instance> (also: #list)
Constructor Details
#initialize(region: nil, access_key_id: nil, secret_access_key: nil) ⇒ AwsEc2DnsName
Returns a new instance of AwsEc2DnsName.
13 14 15 16 17 |
# File 'lib/aws_ec2_dns_name.rb', line 13 def initialize(region: nil, access_key_id: nil, secret_access_key: nil) self.client = Aws::EC2::Client.new(region: region, access_key_id: access_key_id, secret_access_key: secret_access_key) end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
8 9 10 |
# File 'lib/aws_ec2_dns_name.rb', line 8 def client @client end |
Instance Method Details
#instances ⇒ Array<AwsEc2DnsName:Instance> Also known as: list
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/aws_ec2_dns_name.rb', line 20 def instances client.describe_instances.first.reservations.map do |reservation| ec2_instance = reservation.instances.first name_tag = ec2_instance..find { |tag| tag.key == "Name" } next unless name_tag name_tag_value = name_tag.value dns_name = dns_name(ec2_instance) # dns_name of terminated instance is empty string next if dns_name == "" AwsEc2DnsName::Instance.new(name_tag_value, dns_name) end.compact.sort_by { |i| i[:name_tag] } end |