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