modules/mu/mommacat.rb in cloud-mu-2.0.4 vs modules/mu/mommacat.rb in cloud-mu-2.1.0beta

- old
+ new

@@ -1056,11 +1056,12 @@ tag_key: nil, tag_value: nil, allow_multi: false, calling_deploy: MU.mommacat, flags: {}, - dummy_ok: false + dummy_ok: false, + debug: false ) return nil if cloud == "CloudFormation" and !cloud_id.nil? begin deploy_id = deploy_id.to_s if deploy_id.class.to_s == "MU::Config::Tail" name = name.to_s if name.class.to_s == "MU::Config::Tail" @@ -1092,12 +1093,14 @@ # We can extract a deploy_id from mu_name if we don't have one already if !deploy_id and mu_name deploy_id = mu_name.sub(/^(\w+-\w+-\d{10}-[A-Z]{2})-/, '\1') end end - MU.log "Called findStray with cloud: #{cloud}, type: #{type}, deploy_id: #{deploy_id}, calling_deploy: #{calling_deploy.deploy_id if !calling_deploy.nil?}, name: #{name}, cloud_id: #{cloud_id}, tag_key: #{tag_key}, tag_value: #{tag_value}, credentials: #{credentials}", MU::DEBUG, details: flags + loglevel = debug ? MU::NOTICE : MU::DEBUG + MU.log "findStray(cloud: #{cloud}, type: #{type}, deploy_id: #{deploy_id}, calling_deploy: #{calling_deploy.deploy_id if !calling_deploy.nil?}, name: #{name}, cloud_id: #{cloud_id}, tag_key: #{tag_key}, tag_value: #{tag_value}, credentials: #{credentials})", loglevel, details: flags + # See if the thing we're looking for is a member of the deploy that's # asking after it. if !deploy_id.nil? and !calling_deploy.nil? and flags.empty? and calling_deploy.deploy_id == deploy_id and (!name.nil? or !mu_name.nil?) handle = calling_deploy.findLitterMate(type: type, name: name, mu_name: mu_name, cloud_id: cloud_id, credentials: credentials) @@ -1108,20 +1111,23 @@ # Search our other deploys for matching resources if (deploy_id or name or mu_name or cloud_id)# and flags.empty? mu_descs = MU::MommaCat.getResourceMetadata(cfg_plural, name: name, deploy_id: deploy_id, mu_name: mu_name) mu_descs.each_pair { |deploy_id, matches| + MU.log "findStray: #{deploy_id} had #{matches.size.to_s} initial matches", loglevel next if matches.nil? or matches.size == 0 momma = MU::MommaCat.getLitter(deploy_id) straykitten = nil + # If we found exactly one match in this deploy, use its metadata to # guess at resource names we weren't told. if matches.size == 1 and name.nil? and mu_name.nil? if cloud_id.nil? straykitten = momma.findLitterMate(type: type, name: matches.first["name"], cloud_id: matches.first["cloud_id"], credentials: credentials) else + MU.log "findStray: attempting to narrow down with cloud_id #{cloud_id}", loglevel straykitten = momma.findLitterMate(type: type, name: matches.first["name"], cloud_id: cloud_id, credentials: credentials) end # elsif !flags.nil? and !flags.empty? # XXX eh, maybe later # # see if we can narrow it down further with some flags # filtered = [] @@ -1139,10 +1145,15 @@ straykitten = momma.findLitterMate(type: type, name: name, mu_name: mu_name, cloud_id: cloud_id, credentials: credentials) end next if straykitten.nil? + if straykitten.cloud_id.nil? + MU.log "findStray: kitten #{straykitten.mu_name} came back with nil cloud_id", MU::WARN + next + end + kittens[straykitten.cloud_id] = straykitten # Peace out if we found the exact resource we want if cloud_id and straykitten.cloud_id == cloud_id return [straykitten] @@ -1152,10 +1163,11 @@ elsif credentials and credlist.size == 1 and straykitten.credentials == credentials return [straykitten] end } + # if !mu_descs.nil? and mu_descs.size > 0 and !deploy_id.nil? and !deploy_id.empty? and !mu_descs.first.empty? # MU.log "I found descriptions that might match #{resourceclass.cfg_plural} name: #{name}, deploy_id: #{deploy_id}, mu_name: #{mu_name}, but couldn't isolate my target kitten", MU::WARN, details: caller # puts File.read(deploy_dir(deploy_id)+"/deployment.json") # end @@ -1169,11 +1181,13 @@ end end matches = [] + found_the_thing = false credlist.each { |creds| + break if found_the_thing if cloud_id or (tag_key and tag_value) or !flags.empty? regions = [] begin if region regions << region @@ -1191,10 +1205,11 @@ cloud_descs = {} regions.each { |r| cloud_descs[r] = resourceclass.find(cloud_id: cloud_id, region: r, tag_key: tag_key, tag_value: tag_value, flags: flags, credentials: creds) # Stop if you found the thing if cloud_id and cloud_descs[r] and !cloud_descs[r].empty? + found_the_thing = true break end } regions.each { |r| next if cloud_descs[r].nil? @@ -1208,10 +1223,10 @@ end # If we don't have a MU::Cloud object, manufacture a dummy one. # Give it a fake name if we have to and have decided that's ok. if (name.nil? or name.empty?) if !dummy_ok - MU.log "Found cloud provider data for #{cloud} #{type} #{kitten_cloud_id}, but without a name I can't manufacture a proper #{type} object to return", MU::DEBUG, details: caller + MU.log "Found cloud provider data for #{cloud} #{type} #{kitten_cloud_id}, but without a name I can't manufacture a proper #{type} object to return", loglevel, details: caller next else if !mu_name.nil? name = mu_name elsif !tag_value.nil?