-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Develop: Rebase for OCP resource cleanup on AWS
- Loading branch information
Showing
9 changed files
with
232 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,6 @@ repos: | |
hooks: | ||
- id: black | ||
- repo: https://github.com/pycqa/flake8 | ||
rev: 3.9.2 | ||
rev: 7.1.0 | ||
hooks: | ||
- id: flake8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
aws_data = ['VMS', 'NICS', 'DISCS', 'PIPS', 'RESOURCES', 'STACKS'] | ||
aws_data = ['VMS', 'NICS', 'DISCS', 'PIPS', 'RESOURCES', 'STACKS', 'OCPS'] | ||
azure_data = ['VMS', 'NICS', 'DISCS', 'IMAGES', 'PIPS', 'RESOURCES'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from cloudwash.config import settings | ||
from cloudwash.entities.resources.base import OCPsCleanup | ||
from cloudwash.utils import calculate_time_threshold | ||
from cloudwash.utils import dry_data | ||
from cloudwash.utils import filter_resources_by_time_modified | ||
from cloudwash.utils import group_ocps_by_cluster | ||
from cloudwash.utils import OCP_TAG_SUBSTR | ||
|
||
|
||
class CleanOCPs(OCPsCleanup): | ||
def __init__(self, client): | ||
self.client = client | ||
self._delete = [] | ||
self.list() | ||
|
||
def _set_dry(self): | ||
# VMsContainer = namedtuple('VMsCotainer', ['delete', 'stop', 'skip']) | ||
# return VMsContainer(self._delete, self._stop, self._skip) | ||
dry_data['OCPS']['delete'] = self._delete | ||
|
||
def list(self): | ||
pass | ||
|
||
def remove(self): | ||
pass | ||
|
||
def cleanup(self): | ||
if not settings.dry_run: | ||
self.remove() | ||
|
||
|
||
class CleanAWSOcps(CleanOCPs): | ||
def list(self): | ||
time_threshold = calculate_time_threshold(time_ref=settings.aws.criteria.ocps.sla) | ||
|
||
query = " ".join([f"tag.key:{OCP_TAG_SUBSTR}*", f"region:{self.client.cleaning_region}"]) | ||
resources = self.client.list_resources(query=query) | ||
|
||
# Prepare resources to be filtered before deletion | ||
cluster_map = group_ocps_by_cluster(resources=resources) | ||
for cluster_name in cluster_map.keys(): | ||
cluster_resources = cluster_map[cluster_name].get("Resources") | ||
instances = cluster_map[cluster_name].get("Instances") | ||
|
||
if instances: | ||
# For resources with associated EC2 Instances, filter by Instances SLA | ||
if not filter_resources_by_time_modified( | ||
time_threshold, | ||
resources=instances, | ||
): | ||
self._delete.extend(cluster_resources) | ||
else: | ||
# For resources with no associated EC2 Instances, identify as leftovers | ||
self._delete.extend( | ||
filter_resources_by_time_modified(time_threshold, resources=cluster_resources) | ||
) | ||
|
||
# Sort resources by type | ||
self._delete = sorted(self._delete, key=lambda x: x.resource_type) | ||
self._set_dry() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters