Class: AwsAuditor::EC2Instance
- Inherits:
-
Object
- Object
- AwsAuditor::EC2Instance
- Extended by:
- EC2Wrapper, InstanceHelper
- Defined in:
- lib/aws_auditor/ec2_instance.rb
Class Attribute Summary collapse
-
.instances ⇒ Object
Returns the value of attribute instances.
-
.reserved_instances ⇒ Object
Returns the value of attribute reserved_instances.
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.
-
#name ⇒ Object
Returns the value of attribute name.
-
#platform ⇒ Object
Returns the value of attribute platform.
-
#stack_name ⇒ Object
Returns the value of attribute stack_name.
Attributes included from EC2Wrapper
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(ec2_instance, count = 1) ⇒ EC2Instance
constructor
A new instance of EC2Instance.
- #to_s ⇒ Object
Methods included from InstanceHelper
compare, instance_count_hash, instance_hash, reserved_instance_hash
Constructor Details
#initialize(ec2_instance, count = 1) ⇒ EC2Instance
Returns a new instance of EC2Instance.
13 14 15 16 17 18 19 20 21 |
# File 'lib/aws_auditor/ec2_instance.rb', line 13 def initialize(ec2_instance, count=1) @id = ec2_instance.id @name = nil @platform = platform_helper(ec2_instance) @availability_zone = ec2_instance.availability_zone @instance_type = ec2_instance.instance_type @count = count @stack_name = nil end |
Class Attribute Details
.instances ⇒ Object
Returns the value of attribute instances.
9 10 11 |
# File 'lib/aws_auditor/ec2_instance.rb', line 9 def instances @instances end |
.reserved_instances ⇒ Object
Returns the value of attribute reserved_instances.
9 10 11 |
# File 'lib/aws_auditor/ec2_instance.rb', line 9 def reserved_instances @reserved_instances end |
Instance Attribute Details
#availability_zone ⇒ Object
Returns the value of attribute availability_zone.
12 13 14 |
# File 'lib/aws_auditor/ec2_instance.rb', line 12 def availability_zone @availability_zone end |
#count ⇒ Object
Returns the value of attribute count.
12 13 14 |
# File 'lib/aws_auditor/ec2_instance.rb', line 12 def count @count end |
#id ⇒ Object
Returns the value of attribute id.
12 13 14 |
# File 'lib/aws_auditor/ec2_instance.rb', line 12 def id @id end |
#instance_type ⇒ Object
Returns the value of attribute instance_type.
12 13 14 |
# File 'lib/aws_auditor/ec2_instance.rb', line 12 def instance_type @instance_type end |
#name ⇒ Object
Returns the value of attribute name.
12 13 14 |
# File 'lib/aws_auditor/ec2_instance.rb', line 12 def name @name end |
#platform ⇒ Object
Returns the value of attribute platform.
12 13 14 |
# File 'lib/aws_auditor/ec2_instance.rb', line 12 def platform @platform end |
#stack_name ⇒ Object
Returns the value of attribute stack_name.
12 13 14 |
# File 'lib/aws_auditor/ec2_instance.rb', line 12 def stack_name @stack_name end |
Class Method Details
.bucketize ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/aws_auditor/ec2_instance.rb', line 79 def self.bucketize buckets = {} get_instances.map do |instance| name = instance.stack_name || instance.name if name buckets[name] = [] unless buckets.has_key? name buckets[name] << instance else puts "Could not sort #{instance.id}, as it has no stack_name or name" end end buckets.sort_by{|k,v| k } end |
.get_instances ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/aws_auditor/ec2_instance.rb', line 27 def self.get_instances return @instances if @instances @instances = ec2.instances.map do |instance| next unless instance.status.to_s == 'running' new(instance) end.compact get_more_info end |
.get_reserved_instances ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/aws_auditor/ec2_instance.rb', line 36 def self.get_reserved_instances return @reserved_instances if @reserved_instances @reserved_instances = ec2.reserved_instances.map do |ri| next unless ri.state == 'active' new(ri, ri.instance_count) end.compact end |
Instance Method Details
#to_s ⇒ Object
23 24 25 |
# File 'lib/aws_auditor/ec2_instance.rb', line 23 def to_s "#{@platform} #{@availability_zone} #{@instance_type}" end |