Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[#47156875] Decouple ElasticIP and KeyPair removal from VPC removal.

So even when we don't have any VPCs, it is possible to remove ElasticIPs and KeyPairs.
  • Loading branch information...
commit 4d81cfa01e477256ef7060609e01ae91d685e0cc 1 parent 5249f15
Jeffrey Peckham and Vinicius Fuentes authored
29 bosh_aws_bootstrap/lib/bosh/cli/commands/aws.rb
View
@@ -162,6 +162,8 @@ def destroy(config_file = nil)
delete_all_rds_dbs(config_file)
delete_all_s3(config_file)
delete_all_vpcs(config_file)
+ delete_all_key_pairs(config_file)
+ delete_all_elastic_ips(config_file)
delete_all_security_groups(config_file)
delete_all_route53_records(config_file)
end
@@ -292,15 +294,36 @@ def delete_all_vpcs(config_file)
vpc.delete_vpc
end
dhcp_options.uniq(&:id).map(&:delete)
-
- ec2.remove_all_key_pairs
- ec2.release_all_elastic_ips
end
else
say("No VPCs found")
end
end
+ usage "aws delete key_pairs"
+ desc "delete key pairs"
+ def delete_all_key_pairs(config_file)
+ config = load_yaml_file(config_file)
+ ec2 = Bosh::Aws::EC2.new(config["aws"])
+
+ if confirmed?("Are you sure you want to delete all SSH Keypairs?")
+ say "Deleting all key pairs..."
+ ec2.remove_all_key_pairs
+ end
+ end
+
+ usage "aws delete elastic_ips"
+ desc "delete elastic ips"
+ def delete_all_elastic_ips(config_file)
+ config = load_yaml_file(config_file)
+ ec2 = Bosh::Aws::EC2.new(config["aws"])
+
+ if confirmed?("Are you sure you want to delete all Elastic IPs?")
+ say "Releasing all elastic IPs..."
+ ec2.release_all_elastic_ips
+ end
+ end
+
usage "aws create key_pairs"
desc "create key pairs"
def create_key_pairs(config_file)
69 bosh_aws_bootstrap/spec/functional/aws_spec.rb
View
@@ -94,6 +94,8 @@ def stub_required_environment_variables
aws.should_receive(:delete_all_rds_dbs).with(config_file)
aws.should_receive(:delete_all_s3).with(config_file)
aws.should_receive(:delete_all_vpcs).with(config_file)
+ aws.should_receive(:delete_all_key_pairs).with(config_file)
+ aws.should_receive(:delete_all_elastic_ips).with(config_file)
aws.should_receive(:delete_all_security_groups).with(config_file)
aws.should_receive(:delete_all_route53_records).with(config_file)
aws.should_receive(:delete_all_elbs).with(config_file)
@@ -106,6 +108,8 @@ def stub_required_environment_variables
aws.should_receive(:delete_all_rds_dbs).with(default_config_filename)
aws.should_receive(:delete_all_s3).with(default_config_filename)
aws.should_receive(:delete_all_vpcs).with(default_config_filename)
+ aws.should_receive(:delete_all_key_pairs).with(default_config_filename)
+ aws.should_receive(:delete_all_elastic_ips).with(default_config_filename)
aws.should_receive(:delete_all_security_groups).with(default_config_filename)
aws.should_receive(:delete_all_route53_records).with(default_config_filename)
aws.should_receive(:delete_all_elbs).with(default_config_filename)
@@ -116,7 +120,6 @@ def stub_required_environment_variables
describe "aws delete_all security_groups" do
let(:config_file) { asset "config.yml" }
let(:fake_ec2) { mock('EC2') }
- let(:fake_vpc) { mock('VPC', id: 'vpc-1234') }
before do
Bosh::Aws::EC2.stub(:new).and_return(fake_ec2)
@@ -145,7 +148,6 @@ def stub_required_environment_variables
aws.delete_all_security_groups(config_file)
end
end
-
end
describe "aws create vpc" do
@@ -317,6 +319,67 @@ def make_fake_vpc!(overrides = {})
end
end
+ describe "aws destroy key pairs" do
+ let(:config_file) { asset "config.yml" }
+ let(:fake_ec2) { mock('EC2') }
+
+ before do
+ Bosh::Aws::EC2.stub(:new).and_return(fake_ec2)
+ end
+
+ context "when non-interactive" do
+ before do
+ aws.should_receive(:confirmed?).and_return(true)
+ end
+
+ it "should remove the key pairs" do
+ fake_ec2.should_receive(:remove_all_key_pairs).and_return(true)
+ aws.delete_all_key_pairs(config_file)
+ end
+ end
+
+ context "when interactive and bailing out" do
+ before do
+ aws.should_receive(:confirmed?).and_return(false)
+ end
+
+ it 'should not delete the key pairs' do
+ fake_ec2.should_not_receive(:remove_all_key_pairs)
+ aws.delete_all_key_pairs(config_file)
+ end
+ end
+ end
+ describe "aws destroy elastic ips" do
+ let(:config_file) { asset "config.yml" }
+ let(:fake_ec2) { mock('EC2') }
+
+ before do
+ Bosh::Aws::EC2.stub(:new).and_return(fake_ec2)
+ end
+
+ context "when non-interactive" do
+ before do
+ aws.should_receive(:confirmed?).and_return(true)
+ end
+
+ it "should remove the key pairs" do
+ fake_ec2.should_receive(:release_all_elastic_ips).and_return(true)
+ aws.delete_all_elastic_ips(config_file)
+ end
+ end
+
+ context "when interactive and bailing out" do
+ before do
+ aws.should_receive(:confirmed?).and_return(false)
+ end
+
+ it 'should not delete the key pairs' do
+ fake_ec2.should_not_receive(:release_all_elastic_ips)
+ aws.delete_all_elastic_ips(config_file)
+ end
+ end
+ end
+
describe "aws delete all vpcs" do
let(:fake_ec2) { mock('EC2') }
let(:fake_vpc) { mock('VPC', id: 'vpc-1234') }
@@ -331,8 +394,6 @@ def make_fake_vpc!(overrides = {})
aws.should_receive(:confirmed?).and_return(false)
Bosh::Aws::VPC.should_not_receive(:find)
- fake_ec2.should_not_receive(:remove_all_key_pairs)
- fake_ec2.should_not_receive(:release_all_elastic_ips)
aws.delete_all_vpcs(asset('config.yml'))
end
Please sign in to comment.
Something went wrong with that request. Please try again.