Commit 1d313f3d by Szeberényi Imre

fured fix

parent cccc1d5d
...@@ -6,6 +6,7 @@ CELERY_TASK_RESULT_EXPIRES = 300 ...@@ -6,6 +6,7 @@ CELERY_TASK_RESULT_EXPIRES = 300
#CELERY_ACCEPT_CONTENT = ['pickle', 'json', 'msgpack', 'yaml'] #CELERY_ACCEPT_CONTENT = ['pickle', 'json', 'msgpack', 'yaml']
CELERY_ACCEPT_CONTENT = ['json', 'pickle_v2', 'pickle'] CELERY_ACCEPT_CONTENT = ['json', 'pickle_v2', 'pickle']
CELERY_TASK_SERIALIZER = 'json' CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'pickle_v2' CELERY_RESULT_SERIALIZER = 'pickle'
#CELERY_RESULT_SERIALIZER = 'pickle_v2'
CELERY_STORE_ERRORS_EVEN_IF_IGNORED = True CELERY_STORE_ERRORS_EVEN_IF_IGNORED = True
...@@ -19,7 +19,7 @@ re_qemu_img = re.compile(r'(file format: (?P<format>(qcow2|raw))|' ...@@ -19,7 +19,7 @@ re_qemu_img = re.compile(r'(file format: (?P<format>(qcow2|raw))|'
r'virtual size: \w+ \((?P<size>[0-9]+) bytes\)|' r'virtual size: \w+ \((?P<size>[0-9]+) bytes\)|'
r'backing file: \S+ \(actual path: (?P<base>\S+)\))$') r'backing file: \S+ \(actual path: (?P<base>\S+)\))$')
maximum_size = float(os.getenv("DOWNLOAD_MAX_SIZE", 1024 * 1024 * 1024 * 10)) maximum_size = float(os.getenv("DOWNLOAD_MAX_SIZE", 1024 * 1024 * 1024 * 100))
class AbortException(Exception): class AbortException(Exception):
...@@ -27,7 +27,8 @@ class AbortException(Exception): ...@@ -27,7 +27,8 @@ class AbortException(Exception):
class FileTooBig(Exception): class FileTooBig(Exception):
pass def __init__(self):
super(Exception, self).__init__('max size is: %s GB' % (maximum_size / (1024*1024*1024)))
class Disk(object): class Disk(object):
...@@ -36,7 +37,7 @@ class Disk(object): ...@@ -36,7 +37,7 @@ class Disk(object):
TYPES, CREATE_TYPES, SNAPSHOT_TYPES are hand managed restrictions. TYPES, CREATE_TYPES, SNAPSHOT_TYPES are hand managed restrictions.
""" """
TYPES = ['snapshot', 'normal'] TYPES = ['snapshot', 'normal']
FORMATS = ['qcow2', 'raw', 'iso'] FORMATS = ['qcow2', 'raw', 'iso', 'qcow']
CREATE_FORMATS = ['qcow2', 'raw'] CREATE_FORMATS = ['qcow2', 'raw']
def __init__(self, dir, name, format, type, size, def __init__(self, dir, name, format, type, size,
...@@ -268,6 +269,7 @@ class Disk(object): ...@@ -268,6 +269,7 @@ class Disk(object):
def import_disk(self, task, url, port=22): def import_disk(self, task, url, port=22):
downloaded_file = os.path.join(self.dir, re.split('[:/]', url)[-1]) downloaded_file = os.path.join(self.dir, re.split('[:/]', url)[-1])
cmdline = ['scp', '-B', '-P', str(port), url, downloaded_file] cmdline = ['scp', '-B', '-P', str(port), url, downloaded_file]
logger.info("Import of disk from %s " % url)
proc = subprocess.Popen(cmdline) proc = subprocess.Popen(cmdline)
try: try:
...@@ -287,7 +289,7 @@ class Disk(object): ...@@ -287,7 +289,7 @@ class Disk(object):
else: else:
cmdline = ['ionice', '-c', 'idle', cmdline = ['ionice', '-c', 'idle',
'qemu-img', 'convert', 'qemu-img', 'convert',
'-m', '4', '-O', 'qcow2', '-m', '2', '-O', 'qcow2',
downloaded_file, downloaded_file,
self.get_path()] self.get_path()]
subprocess.check_output(cmdline) subprocess.check_output(cmdline)
......
...@@ -15,12 +15,13 @@ trash_directory = "trash" ...@@ -15,12 +15,13 @@ trash_directory = "trash"
def list(dir): def list(dir):
return [d.get_desc() for d in Disk.list(dir)] return [d.get_desc() for d in Disk.list(dir)]
def _list_files(datastore):
@celery.task()
def list_files(datastore):
return [l for l in listdir(datastore) if return [l for l in listdir(datastore) if
path.isfile(path.join(datastore, l))] path.isfile(path.join(datastore, l))]
@celery.task()
def list_files(datastore):
return _list_files(datastore)
@celery.task() @celery.task()
def create(disk_desc): def create(disk_desc):
...@@ -119,15 +120,15 @@ def get_storage_stat(path): ...@@ -119,15 +120,15 @@ def get_storage_stat(path):
@celery.task() @celery.task()
def get_file_statistics(datastore): def get_file_statistics(datastore):
disks = [Disk.get(datastore, name).get_desc() disks = [Disk.get(datastore, name).get_desc()
for name in listdir(datastore) for name in _list_files(datastore)
if not name.endswith((".dump", "trash", "found", "mnt", "download", "pub", ))] if not name.endswith((".dump", ))]
dumps = [{'name': name, dumps = [{'name': name,
'size': path.getsize(path.join(datastore, name))} 'size': path.getsize(path.join(datastore, name))}
for name in listdir(datastore) if name.endswith(".dump")] for name in _list_files(datastore) if name.endswith(".dump")]
trash = [{'name': name, trash = [{'name': name,
'size': path.getsize(path.join(datastore, trash_directory, 'size': path.getsize(path.join(datastore, trash_directory,
name))} name))}
for name in listdir(path.join(datastore, trash_directory))] for name in _list_files(path.join(datastore, trash_directory))]
return { return {
'dumps': dumps, 'dumps': dumps,
'trash': trash, 'trash': trash,
......
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