modules/mu/clouds/google/server.rb in cloud-mu-3.1.5 vs modules/mu/clouds/google/server.rb in cloud-mu-3.1.6
- old
+ new
@@ -1014,11 +1014,10 @@
win_admin_password = @groomer.getSecret(
vault: @config['windows_auth_vault']['vault'],
item: @config['windows_auth_vault']['item'],
field: @config["windows_auth_vault"]["password_field"]
)
-MU.log "RETURNINATING FROM CACHE", MU::WARN, details: win_admin_password
return win_admin_password if win_admin_password
rescue MU::Groomer::MuNoSuchSecret, MU::Groomer::RunError
end
end
@@ -1274,47 +1273,50 @@
# @param noop [Boolean]: If true, will only print what would be done
# @param ignoremaster [Boolean]: If true, will remove resources not flagged as originating from this Mu server
# @param region [String]: The cloud provider region
# @return [void]
def self.cleanup(noop: false, ignoremaster: false, region: MU.curRegion, credentials: nil, flags: {})
- flags["project"] ||= MU::Cloud::Google.defaultProject(credentials)
- return if !MU::Cloud::Google::Habitat.isLive?(flags["project"], credentials)
+ flags["habitat"] ||= MU::Cloud::Google.defaultProject(credentials)
+ return if !MU::Cloud::Google::Habitat.isLive?(flags["habitat"], credentials)
# XXX make damn sure MU.deploy_id is set
filter = %Q{(labels.mu-id = "#{MU.deploy_id.downcase}")}
if !ignoremaster and MU.mu_public_ip
filter += %Q{ AND (labels.mu-master-ip = "#{MU.mu_public_ip.gsub(/\./, "_")}")}
end
MU::Cloud::Google.listAZs(region).each { |az|
disks = []
resp = MU::Cloud::Google.compute(credentials: credentials).list_instances(
- flags["project"],
+ flags["habitat"],
az,
filter: filter
)
if !resp.items.nil? and resp.items.size > 0
resp.items.each { |instance|
- saname = instance.tags.items.first.gsub(/[^a-z]/, "") # XXX this nonsense again
MU.log "Terminating instance #{instance.name}"
if !instance.disks.nil? and instance.disks.size > 0
instance.disks.each { |disk|
disks << disk if !disk.auto_delete
}
end
MU::Cloud::Google.compute(credentials: credentials).delete_instance(
- flags["project"],
+ flags["habitat"],
az,
instance.name
) if !noop
- MU.log "Removing service account #{saname}"
- begin
- MU::Cloud::Google.iam(credentials: credentials).delete_project_service_account(
- "projects/#{flags["project"]}/serviceAccounts/#{saname}@#{flags["project"]}.iam.gserviceaccount.com"
- ) if !noop
- rescue ::Google::Apis::ClientError => e
- raise e if !e.message.match(/^notFound: /)
+ if instance.service_accounts
+ instance.service_accounts.each { |sa|
+ MU.log "Removing service account #{sa.email}"
+ begin
+ MU::Cloud::Google.iam(credentials: credentials).delete_project_service_account(
+ "projects/#{flags["habitat"]}/serviceAccounts/#{sa.email}"
+ ) if !noop
+ rescue ::Google::Apis::ClientError => e
+ raise e if !e.message.match(/^notFound: /)
+ end
+ }
end
# XXX wait-loop on pending?
# pp deletia
}
end
@@ -1323,10 +1325,10 @@
# XXX make sure we don't miss anything that got created with dumb flags
end
# XXX honor snapshotting
MU::Cloud::Google.compute(credentials: credentials).delete(
"disk",
- flags["project"],
+ flags["habitat"],
az,
noop
) if !noop
}
end