From 238247a5d549a07c0d4ad01be630cb7d23aee07b Mon Sep 17 00:00:00 2001 From: makram89 Date: Sun, 30 Jan 2022 22:27:42 +0100 Subject: [PATCH] removing volume on deleting user --- MUOR/MUOR/DockerManager.py | 8 ++++++++ MUOR/MUOR/signals.py | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/MUOR/MUOR/DockerManager.py b/MUOR/MUOR/DockerManager.py index 02ec139f9..4a8c942ae 100644 --- a/MUOR/MUOR/DockerManager.py +++ b/MUOR/MUOR/DockerManager.py @@ -27,3 +27,11 @@ class DockerManager: container = self.client.containers.get(container_id) container.stop() container.remove() + + def remove_volume(self, volume_id): + + volume = self.client.volumes.get(volume_id) + + if volume is not None: + volume.remove(force=True) + diff --git a/MUOR/MUOR/signals.py b/MUOR/MUOR/signals.py index a2e424835..eaac0d823 100644 --- a/MUOR/MUOR/signals.py +++ b/MUOR/MUOR/signals.py @@ -75,3 +75,15 @@ def close_session(sender, instance, **kwargs): except Session.DoesNotExist: pass NGINXConfigurator.refresh_config(get_sessions_data()) + + +@receiver(pre_delete, sender=Profile) +def clean_up_volume(sender, instance, **kwargs): + try: + volume_id = instance.volume + + docker_manager = DockerManager() + docker_manager.remove_volume(volume_id) + + except : + pass