in aws_resource_scan.py [0:0]
def acquire_listing(verbose, what):
"""Acquire resource listing.
Given a service, region and operation execute the operation,
serialize and save the result and
return a tuple of strings describing the result.
Args:
verbose: verbose mode flag.
what: service, region, operation.
Returns:
result listing.
"""
service, region, operation = what
start_time = time.time()
try:
if verbose > 1:
print(what, 'starting request...')
listing = RawListing.acquire(service, region, operation)
listing_file = FilteredListing(listing, './', None)
duration = time.time() - start_time
if verbose > 1:
print(what, '...request successful')
print('timing [success]:', duration, what)
resource_count = listing_file.resource_total_count
if listing_file.input.error == result_error:
return ResultListing(listing, result_error,
'Error(Error during processing of resources)')
if resource_count > 0:
listing.add_to_dictionary()
return ResultListing(listing, result_something,
', '.join(listing_file.resource_types))
else:
return ResultListing(listing, result_nothing,
', '.join(listing_file.resource_types))
except Exception as exc: # pylint:disable=broad-except
duration = time.time() - start_time
if verbose > 1:
print(what, '...exception:', exc)
print('timing [failure]:', duration, what)
if verbose > 2:
traceback.print_exc()
result_type = (result_no_access if 'AccessDeniedException'
in str(exc) else result_error)
if (service == 'ec2' and operation == 'DescribeInstances'):
logging.error(exc)
ignored_err = reference_aws.RESULT_IGNORE_ERRORS.get(
service, {}).get(operation)
if ignored_err is not None:
if not isinstance(ignored_err, list):
ignored_err = list(ignored_err)
for ignored_str_err in ignored_err:
if ignored_str_err in str(exc):
result_type = result_nothing
for not_available_string in not_available_strings:
if not_available_string in str(exc):
result_type = result_nothing
listing = RawListing(service, region, operation, {}, result_type)
return ResultListing(listing, result_type, repr(exc))