Class: AwsAuditor::EC2Instance
- Inherits:
-
Object
- Object
- AwsAuditor::EC2Instance
- Extended by:
- EC2Wrapper, InstanceHelper
- Defined in:
- lib/aws_auditor/ec2_instance.rb
Instance Attribute Summary collapse
-
#availability_zone ⇒ Object
Returns the value of attribute availability_zone.
-
#count ⇒ Object
Returns the value of attribute count.
-
#id ⇒ Object
Returns the value of attribute id.
-
#instance_type ⇒ Object
Returns the value of attribute instance_type.
-
#platform ⇒ Object
Returns the value of attribute platform.
Attributes included from EC2Wrapper
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(ec2_instance, count = 1) ⇒ EC2Instance
constructor
A new instance of EC2Instance.
- #platform_helper(ec2_instance) ⇒ Object
- #to_s ⇒ Object
Methods included from InstanceHelper
compare, instance_count_hash, instance_hash
Constructor Details
#initialize(ec2_instance, count = 1) ⇒ EC2Instance
Returns a new instance of EC2Instance.
9 10 11 12 13 14 15 |
# File 'lib/aws_auditor/ec2_instance.rb', line 9 def initialize(ec2_instance, count=1) @id = ec2_instance.id @platform = platform_helper(ec2_instance) @availability_zone = ec2_instance.availability_zone @instance_type = ec2_instance.instance_type @count = count end |
Instance Attribute Details
#availability_zone ⇒ Object
Returns the value of attribute availability_zone.
8 9 10 |
# File 'lib/aws_auditor/ec2_instance.rb', line 8 def availability_zone @availability_zone end |
#count ⇒ Object
Returns the value of attribute count.
8 9 10 |
# File 'lib/aws_auditor/ec2_instance.rb', line 8 def count @count end |
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/aws_auditor/ec2_instance.rb', line 8 def id @id end |
#instance_type ⇒ Object
Returns the value of attribute instance_type.
8 9 10 |
# File 'lib/aws_auditor/ec2_instance.rb', line 8 def instance_type @instance_type end |
#platform ⇒ Object
Returns the value of attribute platform.
8 9 10 |
# File 'lib/aws_auditor/ec2_instance.rb', line 8 def platform @platform end |
Class Method Details
.get_instances ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/aws_auditor/ec2_instance.rb', line 45 def self.get_instances instances = ec2.instances instances.map do |instance| next unless instance.status.to_s == 'running' new(instance) end if instances end |
.get_reserved_instances ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/aws_auditor/ec2_instance.rb', line 53 def self.get_reserved_instances reserved_instances = ec2.reserved_instances reserved_instances.map do |ri| next unless ri.state == 'active' new(ri, ri.instance_count) end if reserved_instances end |
Instance Method Details
#platform_helper(ec2_instance) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/aws_auditor/ec2_instance.rb', line 21 def platform_helper(ec2_instance) if ec2_instance.class.to_s == 'AWS::EC2::Instance' if ec2_instance.vpc? return 'VPC' elsif ec2_instance.platform if ec2_instance.platform.downcase.include? 'windows' return 'Windows' else return 'Linux' end else return 'Linux' end elsif ec2_instance.class.to_s == 'AWS::EC2::ReservedInstances' if ec2_instance.product_description.downcase.include? 'vpc' return 'VPC' elsif ec2_instance.product_description.downcase.include? 'windows' return 'Windows' else return 'Linux' end end end |
#to_s ⇒ Object
17 18 19 |
# File 'lib/aws_auditor/ec2_instance.rb', line 17 def to_s "#{@platform} #{@availability_zone} #{@instance_type}" end |