Class: Bosh::AwsCliPlugin::VpcDestroyer
- Inherits:
-
Object
- Object
- Bosh::AwsCliPlugin::VpcDestroyer
- Defined in:
- lib/bosh_cli_plugin_aws/vpc_destroyer.rb
Instance Method Summary collapse
- #delete_all ⇒ Object
-
#initialize(ui, config) ⇒ VpcDestroyer
constructor
A new instance of VpcDestroyer.
Constructor Details
#initialize(ui, config) ⇒ VpcDestroyer
Returns a new instance of VpcDestroyer.
3 4 5 6 |
# File 'lib/bosh_cli_plugin_aws/vpc_destroyer.rb', line 3 def initialize(ui, config) @ui = ui @credentials = config['aws'] end |
Instance Method Details
#delete_all ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bosh_cli_plugin_aws/vpc_destroyer.rb', line 8 def delete_all vpc_ids = ec2.vpcs.map(&:id) if vpc_ids.empty? @ui.say('No VPCs found') return end @ui.say("THIS IS A VERY DESTRUCTIVE OPERATION AND IT CANNOT BE UNDONE!\n".make_red) @ui.say("VPCs:\n\t#{vpc_ids.join("\n\t")}") return unless @ui.confirmed?('Are you sure you want to delete all VPCs?') = [] vpc_ids.each do |vpc_id| vpc = Bosh::AwsCliPlugin::VPC.find(ec2, vpc_id) if vpc.instances_count > 0 raise "#{vpc.instances_count} instance(s) running in #{vpc.vpc_id} - delete them first" end next unless @ui.confirmed?("Do NOT delete your default VPC. Are you sure you want to delete #{vpc_id}") << vpc. vpc.delete_network_interfaces vpc.delete_security_groups ec2.delete_internet_gateways(ec2.internet_gateway_ids) vpc.delete_subnets vpc.delete_route_tables vpc.delete_vpc end .uniq(&:id).map(&:delete) end |