Commit 1f100fd4 by Guba Sándor

storage: fixed garbage_collector to check child_disks before delete

parent e80ebd16
......@@ -10,6 +10,7 @@ from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from model_utils.models import TimeStampedModel
from sizefield.models import FileSizeField
from datetime import timedelta
from acl.models import AclBase
from .tasks import local_tasks, remote_tasks
......@@ -45,6 +46,11 @@ class DataStore(Model):
raise WorkerNotFound()
def get_deletable_disks(self):
return [disk.filename for disk in
destroyed__isnull=False) if disk.is_deletable()]
class Disk(AclBase, TimeStampedModel):
......@@ -126,6 +132,23 @@ class Disk(AclBase, TimeStampedModel):
'raw-rw': 'vd',
def is_deletable(self):
"""Returns True if no child and disk is destroyed."""
time_before = - timedelta(days=1)
if self.destroyed > time_before or self.has_active_child():
return False
return True
def has_active_child(self):
"""Returns True if disk have iactive childs."""
time_before = - timedelta(days=1)
for child in self.derivatives.all():
if child.destroyed > time_before or None:
return True
return False
def is_in_use(self):
"""Returns True if disc is attached to an active VM else False"""
return any([i.state != 'STOPPED' for i in self.instance_set.all()])
from storage.models import DataStore
import os
from django.utils import timezone
from datetime import timedelta
from manager.mancelery import celery
import logging
from storage.tasks import remote_tasks
......@@ -20,10 +18,8 @@ def garbage_collector(timeout=15):
:type timeoit: int
for ds in DataStore.objects.all():
time_before = - timedelta(days=1)
file_list = os.listdir(ds.path)
disk_list = [disk.filename for disk in
disk_list = ds.get_deletable_disks()
queue_name = ds.get_remote_queue_name('storage')
for i in set(file_list).intersection(disk_list):"Image: %s at Datastore: %s moved to trash folder." %
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment