require 'csv' require_relative "../google" module AwsAuditor module Scripts class Export extend GoogleWrapper extend AWSWrapper class < b.downcase }, [rds_reserved_instances.values,rds_instances.values].flatten.map{ |x| x.to_s }.uniq.sort! { |a,b| a.downcase <=> b.downcase }, [cache_reserved_instances.values,cache_instances.values].flatten.map{ |x| x.to_s }.uniq.sort! { |a,b| a.downcase <=> b.downcase } ].flatten end def self.all_keys_hash(name = nil, value = nil) return @keys_hash if @keys_hash && @keys_hash[:name] == name @keys_hash = {:name => name} get_all_keys.each{ |key| @keys_hash[key] = value } @keys_hash end def self.get_all_arrays return @all_array if @all_array @all_array = [ec2_array,rds_array,cache_array].flatten end def self.ec2_array instance_array = [{name: "OPSWORKS"}] EC2Instance.bucketize.map do |stack_name, stack_instances| instance_array << {:name => stack_name}.merge(EC2Instance.instance_count_hash(stack_instances)) end instance_array end def self.rds_array instance_array = [{name: "RDS"}] rds_instances.each do |db_name, db| instance_array << Hash({:name => db_name, "#{db.to_s}" => "#{db.count}"}) end instance_array end def self.cache_array instance_array = [{name: "CACHE"}] cache_instances.each do |cache_name, cache| instance_array << Hash({:name => cache_name, "#{cache.to_s}" => "#{cache.count}"}) end instance_array end def self.get_all_counts total_array = [{:name => "TOTALS"}] total_array << all_keys_hash("Running Instances").merge(counts(:instance => true)) total_array << all_keys_hash("Reserved Instances", 0).merge(counts(:reserved => true)) total_array << all_keys_hash("Differences").merge(counts(:compare => true)) end def self.counts(options = {:instance => false, :reserved => false, :compare => false }) CLASS_TYPES.map do |class_type| klass = AwsAuditor.const_get(class_type) instances = klass.instance_count_hash(klass.get_instances) if options[:instance] instances = klass.instance_count_hash(klass.get_reserved_instances) if options[:reserved] instances = klass.compare if options[:compare] instances end.inject(:merge) end def self.ec2_instances @ec2_instances ||= EC2Instance.instance_hash end def self.ec2_reserved_instances @ec2_reserved_instances ||= EC2Instance.reserved_instance_hash end def self.rds_instances @rds_instances ||= RDSInstance.instance_hash end def self.rds_reserved_instances @rds_reserved_instances ||= RDSInstance.reserved_instance_hash end def self.cache_instances @cache_instances ||= CacheInstance.instance_hash end def self.cache_reserved_instances @cache_reserved_instances ||= CacheInstance.reserved_instance_hash end end end end