modules/mu/clouds/google/folder.rb in cloud-mu-3.1.3 vs modules/mu/clouds/google/folder.rb in cloud-mu-3.1.4
- old
+ new
@@ -46,11 +46,11 @@
parent = MU::Cloud::Google::Folder.resolveParent(@config['parent'], credentials: @config['credentials'])
folder_obj = MU::Cloud::Google.folder(:Folder).new(params)
MU.log "Creating folder #{name_string} under #{parent}", details: folder_obj
- resp = MU::Cloud::Google.folder(credentials: @config['credentials']).create_folder(folder_obj, parent: parent)
+ MU::Cloud::Google.folder(credentials: @config['credentials']).create_folder(folder_obj, parent: parent)
# Wait for list_folders output to be consistent (for the folder we
# just created to show up)
retries = 0
begin
@@ -123,14 +123,16 @@
end
nil
end
+ @cached_cloud_desc = nil
# Return the cloud descriptor for the Folder
# @return [Google::Apis::Core::Hashable]
- def cloud_desc
- @cached_cloud_desc ||= MU::Cloud::Google::Folder.find(cloud_id: @cloud_id, credentials: @config['credentials']).values.first
+ def cloud_desc(use_cache: true)
+ return @cached_cloud_desc if @cached_cloud_desc and use_cache
+ @cached_cloud_desc = MU::Cloud::Google::Folder.find(cloud_id: @cloud_id, credentials: @config['credentials']).values.first
@habitat_id ||= @cached_cloud_desc.parent.sub(/^(folders|organizations)\//, "")
@cached_cloud_desc
end
# Return the metadata for this folders's configuration
@@ -158,11 +160,16 @@
# Remove all Google projects associated with the currently loaded deployment. Try to, anyway.
# @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
# @return [void]
- def self.cleanup(noop: false, ignoremaster: false, credentials: nil, flags: {}, region: MU.myRegion)
+ def self.cleanup(noop: false, ignoremaster: false, credentials: nil, flags: {})
+ 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.log "Placeholder: Google Folder artifacts do not support labels, so ignoremaster cleanup flag has no effect", MU::DEBUG, details: filter
# We can't label GCP folders, and their names are too short to encode
# Mu deploy IDs, so all we can do is rely on flags['known'] passed in
# from cleanup, which relies on our metadata to know what's ours.
#noop = true
if flags and flags['known']
@@ -291,11 +298,11 @@
end
# Reverse-map our cloud description into a runnable config hash.
# We assume that any values we have in +@config+ are placeholders, and
# calculate our own accordingly based on what's live in the cloud.
- def toKitten(rootparent: nil, billing: nil, habitats: nil)
+ def toKitten(**args)
bok = {
"cloud" => "Google",
"credentials" => @config['credentials']
}
@@ -308,24 +315,24 @@
id: cloud_desc.parent,
cloud: "Google",
credentials: @config['credentials'],
type: "folders"
)
- elsif rootparent
+ elsif args[:rootparent]
bok['parent'] = {
- 'id' => rootparent.is_a?(String) ? rootparent : rootparent.cloud_desc.name
+ 'id' => args[:rootparent].is_a?(String) ? args[:rootparent] : args[:rootparent].cloud_desc.name
}
else
bok['parent'] = { 'id' => cloud_desc.parent }
end
bok
end
# Cloud-specific configuration properties.
- # @param config [MU::Config]: The calling MU::Config object
+ # @param _config [MU::Config]: The calling MU::Config object
# @return [Array<Array,Hash>]: List of required fields, and json-schema Hash of cloud-specific configuration parameters for this resource
- def self.schema(config)
+ def self.schema(_config)
toplevel_required = []
schema = {
"display_name" => {
"type" => "string",
"description" => "The +display_name+ field of this folder, specified only if we want it to be something other than the automatically-generated string derived from the +name+ field.",