Skip to content

Commit

Permalink
Print the clusters names that the resources are associated with
Browse files Browse the repository at this point in the history
  • Loading branch information
oharan2 committed Jun 20, 2024
1 parent c432bcb commit f6dc711
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
15 changes: 10 additions & 5 deletions cloudwash/providers/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,22 @@ def dry_ocps():
resources=instances,
):
dry_data["OCPS"]["delete"].extend(cluster_resources)
dry_data["OCPS"]["clusters"].extend([cluster_name])
else:
# For resources with no associated EC2 Instances, identify as leftovers
dry_data["OCPS"]["delete"].extend(
filter_resources_by_time_modified(
time_threshold, resources=cluster_resources
)
filtered_leftovers = filter_resources_by_time_modified(
time_threshold, resources=cluster_resources
)
if filtered_leftovers:
dry_data["OCPS"]["delete"].extend(filtered_leftovers)
# Print cluster_name only if it's resources are deletable
dry_data["OCPS"]["clusters"].extend([cluster_name])

# Sort resources by type
dry_data["OCPS"]["delete"] = sorted(
dry_data["OCPS"]["delete"], key=lambda x: x.resource_type
)
return dry_data["OCPS"]["delete"]
return dry_data["OCPS"]

# Remove / Stop VMs
def remove_vms(avms):
Expand Down Expand Up @@ -183,6 +186,8 @@ def remove_stacks(stacks):
if kwargs["ocps"] or kwargs["_all"]:
# Differentiate between the cleanup region and the Resource Explorer client region
ocp_client_region = settings.aws.criteria.ocps.ocp_client_region
dry_data["OCPS"]["clusters"] = []

with compute_client(
"aws", aws_region=ocp_client_region
) as resource_explorer_client:
Expand Down
7 changes: 4 additions & 3 deletions cloudwash/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def echo_dry(dry_data=None) -> None:
]
for ocp in dry_data["OCPS"]["delete"]
}
ocp_clusters = dry_data["OCPS"]["clusters"]
deletable_resources = dry_data["RESOURCES"]["delete"]
deletable_stacks = dry_data["STACKS"]["delete"] if "STACKS" in dry_data else None
if deletable_vms or stopable_vms or skipped_vms:
Expand All @@ -61,7 +62,7 @@ def echo_dry(dry_data=None) -> None:
if deletable_pips:
logger.info(f"PIPs:\n\tDeletable: {deletable_pips}")
if deletable_ocps:
logger.info(f"OCPs:\n\tDeletable: {deletable_ocps}")
logger.info(f"OCPs:\n\tDeletable: {deletable_ocps}\n\tClusters: {ocp_clusters}")
if deletable_resources:
logger.info(f"RESOURCEs:\n\tDeletable: {deletable_resources}")
if deletable_stacks:
Expand All @@ -76,6 +77,7 @@ def echo_dry(dry_data=None) -> None:
deletable_resources,
deletable_stacks,
deletable_images,
deletable_ocps,
]
):
logger.info("\nNo resources are eligible for cleanup!")
Expand Down Expand Up @@ -172,7 +174,7 @@ def calculate_time_threshold(time_ref=""):

# Time Ref is Optional; if empty, time_threshold will be set as "now"
time_threshold = dateparser.parse(f"now-{time_ref}-UTC")
logger.info(
logger.debug(
f"\nAssociated OCP resources are filtered by last creation time of: {time_threshold}"
)
return time_threshold
Expand All @@ -187,7 +189,6 @@ def filter_resources_by_time_modified(
:param datetime time_threshold: Time filtering criteria
:param list resources: List of resources to be filtered out
:return: list of resources that last modified before time threshold
:Example:
Expand Down

0 comments on commit f6dc711

Please sign in to comment.