Commit 63268de5 by Máhonfai Bálint

Fixes to import and export

parent 5ae07b2a
......@@ -266,19 +266,16 @@ class Disk(object):
raise Exception("Invalid file format. Only qcow and "
"iso files are allowed. Image from: %s" % url)
def import_disk(self, task, url, port=None):
def import_disk(self, task, url, port=22):
downloaded_file = os.path.join(self.dir, re.split('[:/]', url)[-1])
cmdline = ['scp', '-B']
if port is not None:
cmdline.extend(['-P', str(port)])
cmdline.extend([downloaded_file, url])
cmdline = ['scp', '-B', '-P', str(port), url, downloaded_file]
proc = subprocess.Popen(cmdline)
try:
while proc.poll() is None:
if task.is_aborted():
raise AbortException()
sleep(1)
sleep(2)
if task.is_aborted():
raise AbortException()
......@@ -317,7 +314,7 @@ class Disk(object):
self.size = Disk.get(self.dir, self.name).size
def export(self, task, disk_format, upload_link, port=None):
def export(self, task, disk_format, upload_link, port=22):
exported_path = self.get_path() + '.' + disk_format
cmdline = ['ionice', '-c', 'idle',
'qemu-img', 'convert']
......@@ -328,17 +325,14 @@ class Disk(object):
exported_path])
subprocess.check_output(cmdline)
cmdline = ['scp', '-B']
if port is not None:
cmdline.extend(['-P', str(port)])
cmdline.extend([exported_path, upload_link])
cmdline = ['scp', '-B', '-P', str(port), exported_path, upload_link]
proc = subprocess.Popen(cmdline)
try:
while proc.poll() is None:
if task.is_aborted():
raise AbortException()
sleep(1)
sleep(2)
except AbortException:
proc.terminate()
logger.info("Export of disk %s aborted" % self.name)
......
......@@ -48,10 +48,7 @@ class import_disk(AbortableTask):
def run(self, **kwargs):
disk_desc = kwargs["disk_desc"]
url = kwargs["url"]
if "port" in kwargs:
port = kwargs["port"]
else:
port = None
port = kwargs["port"]
disk = Disk.deserialize(disk_desc)
disk.import_disk(self, url, port)
return {
......@@ -67,10 +64,7 @@ class export_disk(AbortableTask):
disk_desc = kwargs["disk_desc"]
disk_format = kwargs["disk_format"]
upload_link = kwargs["upload_link"]
if "port" in kwargs:
port = kwargs["port"]
else:
port = None
port = kwargs["port"]
disk = Disk.deserialize(disk_desc)
return disk.export(self, disk_format, upload_link, port)
......
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