Commit 63268de5 by Máhonfai Bálint

Fixes to import and export

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