Sha256: 2c17612c3ce66a782fda3eb7edecdbd2bdbd05539816f7fb8ae34fcc31ddb0de
Contents?: true
Size: 1.67 KB
Versions: 3
Compression:
Stored size: 1.67 KB
Contents
require_relative './instance_helper' module AwsAuditor class EC2Instance extend InstanceHelper extend EC2Wrapper attr_accessor :id, :platform, :availability_zone, :instance_type, :count 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 def to_s "#{@platform} #{@availability_zone} #{@instance_type}" end 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 def self.get_instances instances = ec2.instances instances.map do |instance| next unless instance.status.to_s == 'running' new(instance) end if instances end 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 end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
aws_auditor-0.1.2 | lib/aws_auditor/ec2_instance.rb |
aws_auditor-0.1.1 | lib/aws_auditor/ec2_instance.rb |
aws_auditor-0.1.0 | lib/aws_auditor/ec2_instance.rb |