Commit 5d42a07f by Máhonfai Bálint

Don't convert imported image if it is already qcow2

parent 349cb3f5
import shutil
import json import json
import os import os
import subprocess import subprocess
...@@ -270,16 +272,23 @@ class Disk(object): ...@@ -270,16 +272,23 @@ class Disk(object):
r = requests.get(url, stream=True) r = requests.get(url, stream=True)
downloaded_file = os.path.join(self.dir, url.split('/')[-1]) downloaded_file = os.path.join(self.dir, url.split('/')[-1])
with open(downloaded_file, 'wb') as f: with open(downloaded_file, 'wb') as f:
f.write(r.content) for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)
cmdline = ['qemu-img', with magic.Magic() as m:
'convert', ftype = m.id_filename(downloaded_file)
'-O', 'qcow2',
downloaded_file, if 'qcow' in ftype.lower():
self.get_path()] shutil.move(downloaded_file, self.get_path())
subprocess.check_output(cmdline) else:
cmdline = ['qemu-img',
'convert',
'-O', 'qcow2',
downloaded_file,
self.get_path()]
subprocess.check_output(cmdline)
os.unlink(downloaded_file) os.unlink(downloaded_file)
if not self.check_valid_image(): if not self.check_valid_image():
os.unlink(self.get_path()) os.unlink(self.get_path())
......
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