-
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.
Cloudwash supporting Containers cleanup
- Loading branch information
Showing
10 changed files
with
174 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
aws_data = ['VMS', 'NICS', 'DISCS', 'PIPS', 'RESOURCES', 'STACKS'] | ||
azure_data = ['VMS', 'NICS', 'DISCS', 'IMAGES', 'PIPS', 'RESOURCES'] | ||
gce_data = ['VMS', 'NICS', 'DISCS'] | ||
container_data = ['CONTAINERS'] |
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 ContainerCleanup | ||
from cloudwash.logger import logger | ||
from cloudwash.utils import dry_data | ||
from cloudwash.utils import total_running_time | ||
|
||
|
||
class CleanContainers(ContainerCleanup): | ||
def __init__(self, client): | ||
self.client = client | ||
self._delete = [] | ||
self._stop = [] | ||
self._skip = [] | ||
self.list() | ||
|
||
def _set_dry(self): | ||
dry_data['CONTAINERS']['delete'] = self._delete | ||
dry_data['CONTAINERS']['stop'] = self._stop | ||
dry_data['CONTAINERS']['skip'] = self._skip | ||
|
||
def list(self): | ||
pass | ||
|
||
def stop(self): | ||
for container in self._stop: | ||
self.client.get_container(key=container).stop() | ||
logger.info(f"Stopped Podman Containers: \n{self._stop}") | ||
|
||
def remove(self): | ||
for container in self._delete: | ||
self.client.get_container(key=container).delete(force=True) | ||
logger.info(f"Removed Podman Containers: \n{self._delete}") | ||
|
||
def skip(self): | ||
logger.info(f"Skipped VMs: \n{self._skip}") | ||
|
||
def cleanup(self): | ||
if not settings.dry_run: | ||
self.remove() | ||
self.stop() | ||
self.skip() | ||
|
||
|
||
class CleanPodmanContainers(CleanContainers): | ||
def list(self): | ||
|
||
for container in self.client.containers: | ||
if container.name in settings.podman.exceptions.container.skip_list: | ||
self._skip.append(container.name) | ||
continue | ||
elif total_running_time(container).minutes >= settings.podman.criteria.container.sla: | ||
|
||
if container.name in settings.podman.exceptions.container.stop_list: | ||
self._stop.append(container.name) | ||
continue | ||
|
||
elif container.name.startswith(settings.podman.criteria.container.name_prefix): | ||
self._delete.append(container.name) | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"""Azure CR Cleanup Utilities""" | ||
from cloudwash.client import compute_client | ||
from cloudwash.constants import container_data as data | ||
from cloudwash.entities.providers import PodmanCleanup | ||
from cloudwash.utils import dry_data | ||
from cloudwash.utils import echo_dry | ||
|
||
|
||
def cleanup(**kwargs): | ||
is_dry_run = kwargs.get("dry_run", False) | ||
for items in data: | ||
dry_data[items]['delete'] = [] | ||
with compute_client("podman") as podman_client: | ||
podmancleanup = PodmanCleanup(client=podman_client) | ||
# Actual Cleaning and dry execution | ||
if kwargs["containers"]: | ||
podmancleanup.containers.cleanup() | ||
if is_dry_run: | ||
echo_dry(dry_data) |
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