def test_resolve_regions(self): self.assertEqual( org.resolve_regions(['us-west-2']), ['us-west-2']) self.assertEqual( org.resolve_regions([]), ('us-east-1', 'us-west-2'))
def test_resolve_regions(self): self.assertEqual( org.resolve_regions(['us-west-2']), ['us-west-2']) self.assertEqual( org.resolve_regions([]), ('us-east-1', 'us-west-2'))
def test_resolve_regions(self): account = { "name": "dev", "account_id": "112233445566", "role": "arn:aws:iam:112233445566::/role/foobar" } self.assertEqual(org.resolve_regions(['us-west-2'], account), ['us-west-2']) self.assertEqual(org.resolve_regions([], account), ('us-east-1', 'us-west-2'))
def tag_org(config, db, region, creator_tag, user_suffix, dryrun, accounts, tags, debug, verbose, type): """Tag an orgs resources """ accounts_config, custodian_config, executor = org_init(config, use=None, debug=debug, verbose=verbose, accounts=accounts or None, tags=tags, policies=None, resource=None, policy_tags=None) load_resources() stats = {} total = 0 start_exec = time.time() with executor(max_workers=WORKER_COUNT) as w: futures = {} for a in accounts_config['accounts']: for r in resolve_regions(region or a.get('regions', ())): futures[w.submit(tag_org_account, a, r, db, creator_tag, user_suffix, dryrun, type)] = (a, r) for f in as_completed(futures): a, region = futures[f] if f.exception(): log.warning( "error account:%s id:%s region:%s error:%s" % (a['name'], a['account_id'], region, f.exception())) continue result = f.result() if result: stats[(a['name'], region)] = (a, result) print(("auto tag complete account:%s id:%s region:%s \n %s" % (a['name'], a['account_id'], region, "\n ".join([ " {}: {}".format(k, v) for k, v in result.items() if v and not k.endswith('not-found') ]))).strip()) total += sum( [v for k, v in result.items() if not k.endswith('not-found')]) print("Total resources tagged: %d in %0.2f" % total, time.time() - start_exec) return stats
def test_resolve_regions_comma_separated(self): self.assertEqual( org.resolve_regions([ 'us-west-2,eu-west-1,us-east-1,us-west-2', 'eu-west-1,us-east-2,us-east-1' ], None), ['us-west-2', 'eu-west-1', 'us-east-1', 'us-east-2'])