-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
441 additions
and
196 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
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
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
25 changes: 25 additions & 0 deletions
25
cloud_governance/policy/abstract_policies/cleanup/abstract_unattached_volume.py
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,25 @@ | ||
from abc import ABC | ||
|
||
|
||
class AbstractUnattachedVolumes(ABC): | ||
|
||
RESOURCE_ACTION = 'Delete' | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
def _unattached_volume(self): | ||
""" | ||
This method returns the unattached available volumes | ||
:return: | ||
:rtype: | ||
""" | ||
raise NotImplementedError("This method not yet implemented") | ||
|
||
def run(self): | ||
""" | ||
This method starts the unattached volume operations | ||
:return: | ||
:rtype: | ||
""" | ||
return self._unattached_volume() |
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,49 @@ | ||
|
||
|
||
from cloud_governance.common.helpers.aws.aws_policy_operations import AWSPolicyOperations | ||
from cloud_governance.common.utils.utils import Utils | ||
from cloud_governance.policy.abstract_policies.cleanup.abstract_unattached_volume import AbstractUnattachedVolumes | ||
|
||
|
||
class UnattachedVolume(AbstractUnattachedVolumes, AWSPolicyOperations): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
def _unattached_volume(self): | ||
""" | ||
This method returns the list of unattached volumes | ||
:return: | ||
:rtype: | ||
""" | ||
unattached_volumes = [] | ||
available_volumes = self._get_all_volumes() | ||
for volume in available_volumes: | ||
tags = volume.get('Tags', []) | ||
resource_id = volume.get('VolumeId') | ||
cleanup_result = False | ||
if Utils.equal_ignore_case(volume.get('State'), 'available'): | ||
cleanup_days = self.get_clean_up_days_count(tags=tags) | ||
cleanup_result = self.verify_and_delete_resource(resource_id=resource_id, tags=tags, | ||
clean_up_days=cleanup_days) | ||
resource_data = self._get_es_schema(resource_id=resource_id, | ||
user=self.get_tag_name_from_tags(tags=tags, tag_name='User'), | ||
skip_policy=self.get_skip_policy_value(tags=tags), | ||
cleanup_days=cleanup_days, dry_run=self._dry_run, | ||
name=self.get_tag_name_from_tags(tags=tags, tag_name='Name'), | ||
region=self._region, | ||
cleanup_result=str(cleanup_result), | ||
resource_action=self.RESOURCE_ACTION, | ||
cloud_name=self._cloud_name, | ||
resource_type=volume.get('VolumeType', ''), | ||
resource_state=volume.get('State') if not cleanup_result else "Deleted", | ||
volume_size=f"{volume.get('Size')} GB" | ||
) | ||
unattached_volumes.append(resource_data) | ||
else: | ||
cleanup_days = 0 | ||
if not cleanup_result: | ||
self.update_resource_day_count_tag(resource_id=resource_id, cleanup_days=cleanup_days, tags=tags) | ||
|
||
return unattached_volumes | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.