removing volume on deleting user

This commit is contained in:
makram89 2022-01-30 22:27:42 +01:00
parent 098564e333
commit 238247a5d5
2 changed files with 20 additions and 0 deletions

View File

@ -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)

View File

@ -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