Skip to content

Commit

Permalink
Minor changes to remove redundant names in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
msajidmansoori12 committed Sep 28, 2024
1 parent fbde185 commit b988f63
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions cloudwash/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def echo_dry(dry_data=None) -> None:
:param dict dry_data: The deletable resources dry data of a Compute Resource,
it follows the format of module scoped `dry_data` variable in this module
"""

logger.info("\n=========== DRY SUMMARY ============\n")
resource_data = {
"provider": dry_data.get('PROVIDER'),
Expand All @@ -53,21 +53,31 @@ def echo_dry(dry_data=None) -> None:
"deletable_resources": dry_data["RESOURCES"]["delete"],
"deletable_stacks": dry_data["STACKS"]["delete"] if "STACKS" in dry_data else None,
}
if any(value for key, value in resource_data.items() if key != 'provider'):
logger.info("Resources eligible for cleanup:")
for key, value in resource_data.items():
if value and key != "provider":
logger.info(
f"{key.replace('_', ' ').title()}:\n\t{key.split('_')[0].title()}: {value}"
)

#Group the same resource type under the same section for logging
grouped_resources = {}
for key , value in resource_data.items():
if key!='provider' and value:
suffix = key.split('_')[1].upper()
action = key.split('_')[0].title()

if suffix not in grouped_resources.keys():
grouped_resources[suffix] = {}
grouped_resources[suffix][action] = value

if any(value for key, value in resource_data.items() if key != 'provider'):
for suffix,actions in grouped_resources.items():
logger.info(f"{suffix}:")
for action, value in actions.items():
logger.info(f"\t{action}: {value}")
logger.info("\n====================================\n")

create_html(**resource_data)
else:
logger.info("\nNo resources are eligible for cleanup!\n")



def create_html(**kwargs):
'''Creates a html based report file with deletable resources.'''
doc = dominate.document(title="Cloud resources page")
Expand Down

0 comments on commit b988f63

Please sign in to comment.