Commit 3746c537 by Czémán Arnold

Make shorter some functions

parent 8cf3e80b
...@@ -15,11 +15,8 @@ trash_directory = "trash" ...@@ -15,11 +15,8 @@ trash_directory = "trash"
@celery.task() @celery.task()
def list(data_store_type, dir): def list(data_store_type, dir):
cls = CephDisk if data_store_type == "ceph_block" else Disk
if data_store_type == "ceph_block": return [d.get_desc() for d in cls.list(dir)]
return [d.get_desc() for d in CephDisk.list(dir)]
return [d.get_desc() for d in Disk.list(dir)]
@celery.task() @celery.task()
...@@ -36,12 +33,8 @@ def list_files(data_store_type, dir): ...@@ -36,12 +33,8 @@ def list_files(data_store_type, dir):
@celery.task() @celery.task()
def create(disk_desc): def create(disk_desc):
disk = None cls = CephDisk if disk_desc["data_store_type"] == "ceph_block" else Disk
if disk_desc["data_store_type"] == "ceph_block": disk = cls.deserialize(disk_desc)
disk = CephDisk.deserialize(disk_desc)
else:
disk = Disk.deserialize(disk_desc)
disk.create() disk.create()
...@@ -52,12 +45,8 @@ class download(AbortableTask): ...@@ -52,12 +45,8 @@ class download(AbortableTask):
disk_desc = kwargs['disk'] disk_desc = kwargs['disk']
url = kwargs['url'] url = kwargs['url']
parent_id = kwargs.get("parent_id", None) parent_id = kwargs.get("parent_id", None)
disk = None c = CephDisk if disk_desc["data_store_type"] == "ceph_block" else Disk
if disk_desc["data_store_type"] == "ceph_block": disk = c.deserialize(disk_desc)
disk = CephDisk.deserialize(disk_desc)
else:
disk = Disk.deserialize(disk_desc)
disk.download(self, url, parent_id) disk.download(self, url, parent_id)
return {'size': disk.size, return {'size': disk.size,
'type': disk.format, 'type': disk.format,
...@@ -66,12 +55,8 @@ class download(AbortableTask): ...@@ -66,12 +55,8 @@ class download(AbortableTask):
@celery.task() @celery.task()
def delete(disk_desc): def delete(disk_desc):
disk = None cls = CephDisk if disk_desc["data_store_type"] == "ceph_block" else Disk
if disk_desc["data_store_type"] == "ceph_block": disk = cls.deserialize(disk_desc)
disk = CephDisk.deserialize(disk_desc)
else:
disk = Disk.deserialize(disk_desc)
disk.delete() disk.delete()
...@@ -90,12 +75,8 @@ def delete_dump(data_store_type, dir, filename): ...@@ -90,12 +75,8 @@ def delete_dump(data_store_type, dir, filename):
@celery.task() @celery.task()
def snapshot(disk_desc): def snapshot(disk_desc):
disk = None cls = CephDisk if disk_desc["data_store_type"] == "ceph_block" else Disk
if disk_desc["data_store_type"] == "ceph_block": disk = cls.deserialize(disk_desc)
disk = CephDisk.deserialize(disk_desc)
else:
disk = Disk.deserialize(disk_desc)
disk.snapshot() disk.snapshot()
...@@ -106,16 +87,9 @@ class merge(AbortableTask): ...@@ -106,16 +87,9 @@ class merge(AbortableTask):
old_json = kwargs['old_json'] old_json = kwargs['old_json']
new_json = kwargs['new_json'] new_json = kwargs['new_json']
parent_id = kwargs.get("parent_id", None) parent_id = kwargs.get("parent_id", None)
cls = CephDisk if old_json["data_store_type"] == "ceph_block" else Disk
disk = None disk = cls.deserialize(old_json)
new_disk = None new_disk = cls.deserialize(new_json)
if old_json["data_store_type"] == "ceph_block":
disk = CephDisk.deserialize(old_json)
new_disk = CephDisk.deserialize(new_json)
else:
disk = Disk.deserialize(old_json)
new_disk = Disk.deserialize(new_json)
disk.merge(self, new_disk, parent_id=parent_id) disk.merge(self, new_disk, parent_id=parent_id)
...@@ -155,7 +129,7 @@ def get_storage_stat(data_store_type, path): ...@@ -155,7 +129,7 @@ def get_storage_stat(data_store_type, path):
@celery.task @celery.task
def is_exists(data_store_type, path, disk_name): def exists(data_store_type, path, disk_name):
''' Recover named disk from the trash directory. ''' Recover named disk from the trash directory.
''' '''
if data_store_type == "ceph_block": if data_store_type == "ceph_block":
......
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