Class: AwsClean::Keypair

Inherits:
Base
  • Object
show all
Defined in:
lib/aws_clean/keypair.rb

Instance Method Summary collapse

Methods inherited from Base

#are_you_sure?, #initialize

Methods included from AwsServices

#ec2

Constructor Details

This class inherits a constructor from AwsClean::Base

Instance Method Details

#cleanObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/aws_clean/keypair.rb', line 4

def clean
  return if ENV['TEST'] # hack for specs

  inventory = AwsInventory::Keypair.new(header: false)
  inventory.data.each do |row|
    key_name, instances_count = row
    in_use = instances_count > 0
    next if in_use

    sure = are_you_sure?("About to keypair #{key_name}")
    if sure
      ec2.delete_key_pair(key_name: key_name)
      puts "Deleted #{key_name}"
    else
      puts "Did not delete #{key_name}"
    end
  end
end