modules/mu/cleanup.rb in cloud-mu-3.1.6 vs modules/mu/cleanup.rb in cloud-mu-3.2.0
- old
+ new
@@ -28,10 +28,12 @@
@deploy_id = nil
@noop = false
@onlycloud = false
@skipcloud = false
+ # Resource types, in the order in which we generally have to clean them up
+ # to disentangle them from one another.
TYPES_IN_ORDER = ["Collection", "Endpoint", "Function", "ServerPool", "ContainerCluster", "SearchDomain", "Server", "MsgQueue", "Database", "CacheCluster", "StoragePool", "LoadBalancer", "NoSQLDB", "FirewallRule", "Alarm", "Notifier", "Log", "VPC", "Role", "Group", "User", "Bucket", "DNSZone", "Collection"]
# Purge all resources associated with a deployment.
# @param deploy_id [String]: The identifier of the deployment to remove (typically seen in the MU-ID tag on a resource).
# @param noop [Boolean]: Do not delete resources, merely list what would be deleted.
@@ -118,11 +120,11 @@
}
}
}
creds.each_pair { |provider, credsets_inner|
- cloudclass = Object.const_get("MU").const_get("Cloud").const_get(provider)
+ cloudclass = MU::Cloud.cloudClass(provider)
credsets_inner.keys.each { |c|
cloudclass.cleanDeploy(MU.deploy_id, credentials: c, noop: @noop)
}
}
end
@@ -156,11 +158,11 @@
end
def self.listUsedCredentials(credsets)
creds = {}
MU::Cloud.availableClouds.each { |cloud|
- cloudclass = Object.const_get("MU").const_get("Cloud").const_get(cloud)
+ cloudclass = MU::Cloud.cloudClass(cloud)
if $MU_CFG[cloud.downcase] and $MU_CFG[cloud.downcase].size > 0
creds[cloud] ||= {}
cloudclass.listCredentials.each { |credset|
next if credsets and credsets.size > 0 and !credsets.include?(credset)
next if @credsused and @credsused.size > 0 and !@credsused.include?(credset)
@@ -177,11 +179,11 @@
creds
end
private_class_method :listUsedCredentials
def self.cleanCloud(cloud, habitats, regions, credsets)
- cloudclass = Object.const_get("MU").const_get("Cloud").const_get(cloud)
+ cloudclass = MU::Cloud.cloudClass(cloud)
credsets.each_pair { |credset, acct_regions|
next if @credsused and !@credsused.include?(credset)
global_vs_region_semaphore = Mutex.new
global_done = {}
regionthreads = []
@@ -210,12 +212,12 @@
end
private_class_method :cleanCloud
def self.cleanRegion(cloud, credset, region, global_vs_region_semaphore, global_done, habitats)
had_failures = false
- cloudclass = Object.const_get("MU").const_get("Cloud").const_get(cloud)
- habitatclass = Object.const_get("MU").const_get("Cloud").const_get(cloud).const_get("Habitat")
+ cloudclass = MU::Cloud.cloudClass(cloud)
+ habitatclass = MU::Cloud.resourceClass(cloud, "Habitat")
projects = []
if habitats
projects = habitats
else
@@ -224,11 +226,11 @@
$MU_CFG[cloud.downcase][credset]["project"]
# XXX GCP credential schema needs an array for projects
projects << $MU_CFG[cloud.downcase][credset]["project"]
end
begin
- projects.concat(cloudclass.listHabitats(credset))
+ projects.concat(cloudclass.listHabitats(credset, use_cache: false))
rescue NoMethodError
end
end
if projects == []
@@ -278,12 +280,11 @@
}
TYPES_IN_ORDER.each { |t|
begin
skipme = false
global_vs_region_semaphore.synchronize {
- MU::Cloud.loadCloudType(cloud, t)
- if Object.const_get("MU").const_get("Cloud").const_get(cloud).const_get(t).isGlobal?
+ if MU::Cloud.resourceClass(cloud, t).isGlobal?
global_done[habitat] ||= []
if !global_done[habitat].include?(t)
global_done[habitat] << t
flags['global'] = true
else
@@ -293,11 +294,11 @@
}
next if skipme
rescue MU::Cloud::MuDefunctHabitat, MU::Cloud::MuCloudResourceNotImplemented
next
rescue MU::MuError, NoMethodError => e
- MU.log "While checking mu/clouds/#{cloud.downcase}/#{cloudclass.cfg_name} for global-ness in cleanup: "+e.message, MU::WARN
+ MU.log "While checking mu/providers/#{cloud.downcase}/#{cloudclass.cfg_name} for global-ness in cleanup: "+e.message, MU::WARN
next
rescue ::Aws::EC2::Errors::AuthFailure, ::Google::Apis::ClientError => e
MU.log e.message+" in "+region, MU::ERR
next
end
@@ -321,24 +322,24 @@
# @param flags [Hash]:
# @param region [String]:
def self.call_cleanup(type, credset, provider, flags, region)
if @mommacat.nil? or @mommacat.numKittens(types: [type]) > 0
if @mommacat
+
found = @mommacat.findLitterMate(type: type, return_all: true, credentials: credset)
- flags['known'] ||= []
- if found.is_a?(Array)
- found.each { |k|
- flags['known'] << k.cloud_id
- }
- elsif found and found.is_a?(Hash)
- flags['known'] << found['cloud_id']
- elsif found
- flags['known'] << found.cloud_id
+
+ if found
+ flags['known'] = if found.is_a?(Array)
+ found.map { |k| k.cloud_id }
+ elsif found.is_a?(Hash)
+ found.each_value.map { |k| k.cloud_id }
+ else
+ [found.cloud_id]
+ end
end
end
- resclass = Object.const_get("MU").const_get("Cloud").const_get(type)
- resclass.cleanup(
+ MU::Cloud.loadBaseType(type).cleanup(
noop: @noop,
ignoremaster: @ignoremaster,
region: region,
cloud: provider,
flags: flags,