Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add rake task to delete all organizations

  • Loading branch information...
commit 0fbf18c7fa6783a50eb91c7c287da0db7ffd1510 1 parent 99d0b5d
Maria Shaldibina and Mark Rushakoff authored
Showing with 91 additions and 0 deletions.
  1. +5 −0 Rakefile
  2. +86 −0 tools/scripts/yeti-hunter.rb
View
5 Rakefile
@@ -161,6 +161,11 @@ task :sync_assets do
RakeHelper.sync_assets
end
+desc "delete yeti-like organizations"
+task :delete_orgs do
+ sh "./tools/scripts/yeti-hunter.rb"
+end
+
desc 'run core tests for verifying that an installation meets minimal Cloud Foundry compatibility requirements'
RSpec::Core::RakeTask.new(:core) do |t|
t.rspec_opts = '--tag cfcore'
View
86 tools/scripts/yeti-hunter.rb
@@ -0,0 +1,86 @@
+#!/usr/bin/env ruby
+require "rubygems"
+require "cfoundry"
+
+client = CFoundry::Client.new(ENV["VCAP_BVT_TARGET"])
+client.login(ENV["VCAP_BVT_ADMIN_USER"], ENV["VCAP_BVT_ADMIN_USER_PASSWD"])
+
+puts "Going hunting..."
+
+all_orgs = client.organizations
+useless_orgs = all_orgs.select do |org|
+ org.name =~ /(^org(anization)?-|yeti_test_org)/
+end
+
+puts "Targets acquired:"
+useless_orgs.each do |org|
+ puts " #{org.name}"
+end
+
+puts ""
+puts "Nuke'em?"
+print "> "
+ans = gets
+
+unless ans.downcase.start_with?("y")
+ puts "ABORT"
+ exit(1)
+end
+
+routes = client.routes
+
+useless_orgs.each do |org|
+ puts "Killing #{org.name}..."
+
+ begin
+ org.delete!
+ rescue CFoundry::InvalidRequest
+ begin
+ org.domains.each do |domain|
+ next unless domain.owning_organization == org
+
+ puts " Clearing domain #{domain.name} first..."
+ domain.delete!
+ puts " OK"
+ end
+
+ org.spaces.each do |space|
+ puts " Clearing space #{space.name} first..."
+
+ begin
+ space.delete!
+ rescue CFoundry::InvalidRequest
+ puts " Clearing the space's contents first..."
+
+ routes.select { |r| r.space == space }.each(&:delete!)
+
+ space.apps.each do |app|
+ puts " Deleting app #{app.name}..."
+ app.delete!
+ puts " OK"
+ end
+
+ space.service_instances.each do |svc|
+ puts " Deleting service instance #{svc.name}..."
+ svc.delete!
+ puts " OK"
+ end
+
+ space.delete!
+ puts " OK"
+ end
+
+ puts " OK"
+ end
+
+ org.delete!
+
+ puts "OK"
+ rescue CFoundry::InvalidRequest
+ puts "FAILED"
+ next
+ end
+ end
+end
+
+puts "the deed is done"
Please sign in to comment.
Something went wrong with that request. Please try again.