Commit abd0f554 by Máhonfai Bálint

Add percentage progress and abort to export disk operation

parent 35fec9da
Pipeline #1388 passed with stage
in 0 seconds
......@@ -824,7 +824,7 @@ class VmCreateDiskForm(OperationForm):
class VmDiskExportForm(OperationForm):
format = forms.ChoiceField(
disk_format = forms.ChoiceField(
choices=Disk.EXPORT_FORMATS,
label=_('Format'))
......@@ -850,7 +850,7 @@ class VmDiskExportForm(OperationForm):
HTML(_("<label>Disk:</label> %s") % escape(self.disk)),
css_class="form-group",
),
Field('disk'), Field('format')
Field('disk'), Field('disk_format')
)
return helper
......
......@@ -497,13 +497,20 @@ class Disk(TimeStampedModel):
disk.save()
return disk
def export(self, format, upload_link, timeout=3600):
def export(self, disk_format, upload_link, task):
exported_name = self.name if self.name != '' else self.filename
queue_name = self.get_remote_queue_name('storage', priority='slow')
storage_tasks.export.apply_async(
args=[self.get_disk_desc(), format, exported_name, upload_link],
queue=queue_name).get(timeout=timeout)
remote = storage_tasks.export_disk.apply_async(
kwargs={
"disk_desc": self.get_disk_desc(),
"disk_format": disk_format,
"exported_name": exported_name,
"upload_link": upload_link,
"task": task.request.id
},
queue=queue_name)
self._run_abortable_task(remote, task)
def destroy(self, user=None, task_uuid=None):
if self.destroyed:
......
......@@ -43,8 +43,8 @@ def import_disk(disk_desc, url):
pass
@celery.task(name='storagedriver.export')
def export(disk_desc, format):
@celery.task(name='storagedriver.export_disk')
def export_disk(disk_desc, format):
pass
......
......@@ -376,6 +376,8 @@ class ExportDiskOperation(InstanceOperation):
id = 'export_disk'
name = _('export disk')
description = _('Export disk to the selected format.')
abortable = True
has_percentage = True
required_perms = ('storage.export_disk',)
accept_states = ('STOPPED',)
async_queue = 'localhost.man.slow'
......@@ -387,10 +389,10 @@ class ExportDiskOperation(InstanceOperation):
except NoStoreException:
raise PermissionDenied
def _operation(self, user, disk, format):
def _operation(self, user, disk, disk_format, task):
store = Store(user)
upload_link = store.request_upload('/')
disk.export(format, upload_link)
disk.export(disk_format, upload_link, task)
@register_operation
......
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