-
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.
Merge pull request #126 from jyejare/unified_cleanup_funcs
Unified/Simplified Cloud Provider Cleanup and Resource Types
- Loading branch information
Showing
7 changed files
with
172 additions
and
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from cloudwash.entities.resources.discs import CleanAWSDiscs | ||
from cloudwash.entities.resources.discs import CleanAzureDiscs | ||
from cloudwash.entities.resources.vms import CleanAWSVms | ||
from cloudwash.entities.resources.vms import CleanAzureVMs | ||
|
||
|
||
class providerCleanup: | ||
def __init__(self, client): | ||
self.client = client | ||
|
||
@property | ||
def vms(self): | ||
providerclass = self.__class__.__name__ | ||
if 'Azure' in providerclass: | ||
return CleanAzureVMs(client=self.client) | ||
elif 'AWS' in providerclass: | ||
return CleanAWSVms(client=self.client) | ||
|
||
@property | ||
def discs(self): | ||
providerclass = self.__class__.__name__ | ||
if 'Azure' in providerclass: | ||
return CleanAzureDiscs(client=self.client) | ||
elif 'AWS' in providerclass: | ||
return CleanAWSDiscs(client=self.client) | ||
|
||
|
||
class AzureCleanup(providerCleanup): | ||
def __init__(self, client): | ||
self.client = client | ||
super().__init__(client) | ||
|
||
|
||
class AWSCleanup(providerCleanup): | ||
def __init__(self, client): | ||
self.client = client | ||
super().__init__(client) |
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,51 @@ | ||
from cloudwash.config import settings | ||
from cloudwash.entities.resources.base import DiscsCleanup | ||
from cloudwash.logger import logger | ||
from cloudwash.utils import dry_data | ||
|
||
|
||
class CleanDiscs(DiscsCleanup): | ||
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['DISCS']['delete'] = self._delete | ||
|
||
def list(self): | ||
pass | ||
|
||
def remove(self): | ||
pass | ||
|
||
def cleanup(self): | ||
if not settings.dry_run: | ||
self.remove() | ||
|
||
|
||
class CleanAWSDiscs(CleanDiscs): | ||
def list(self): | ||
if settings.aws.criteria.disc.unassigned: | ||
rdiscs = self.client.get_all_unattached_volumes() | ||
rdiscs = [rdisc["VolumeId"] for rdisc in rdiscs] | ||
self._delete.extend(rdiscs) | ||
self._set_dry() | ||
|
||
def remove(self): | ||
self.client.remove_all_unused_volumes() | ||
logger.info(f"Removed Discs: \n{self._delete}") | ||
|
||
|
||
class CleanAzureDiscs(CleanDiscs): | ||
def list(self): | ||
if settings.aws.criteria.disc.unassigned: | ||
rdiscs = self.client.list_free_discs() | ||
self._delete.extend(rdiscs) | ||
self._set_dry() | ||
|
||
def remove(self): | ||
self.client.remove_discs_by_search() | ||
logger.info(f"Removed Discs: \n{self._delete}") |
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