Commit dcf38ab6 by carpoon

extend export and import tasks

extend export and import tasks with identity and mode
add new export method to datastore
parent 0505e140
...@@ -513,16 +513,19 @@ class Disk(TimeStampedModel): ...@@ -513,16 +513,19 @@ class Disk(TimeStampedModel):
return disk return disk
@classmethod @classmethod
def import_disk(cls, user, name, download_link, port, task): def import_disk(cls, task, user, name, download_link, port, store_identity_file, store_ssh_mode):
params = {'name': name, params = {'name': name,
'type': 'qcow2-norm'} 'type': 'qcow2-norm'}
disk = cls.__create(user=user, params=params) datastore = DataStore.objects.filter(name='default').get().name
disk = cls.__create(user=user, datastore=datastore, params=params)
queue_name = disk.get_remote_queue_name('storage', priority='slow') queue_name = disk.get_remote_queue_name('storage', priority='slow')
remote = storage_tasks.import_disk.apply_async( remote = storage_tasks.import_disk.apply_async(
kwargs={ kwargs={
"disk_desc": disk.get_disk_desc(), "disk_desc": disk.get_disk_desc(),
"url": download_link, "url": download_link,
"port": port "port": port,
"store_identity_file": store_identity_file,
"store_ssh_mode": store_ssh_mode,
}, },
queue=queue_name queue=queue_name
) )
...@@ -533,14 +536,27 @@ class Disk(TimeStampedModel): ...@@ -533,14 +536,27 @@ class Disk(TimeStampedModel):
disk.save() disk.save()
return disk return disk
def export(self, disk_format, upload_link, port, task): def export_disk(self, task, disk_format, upload_link, port, store_identity_file, store_ssh_mode):
queue_name = self.get_remote_queue_name('storage', priority='slow') queue_name = self.get_remote_queue_name('storage', priority='slow')
remote = storage_tasks.export_disk.apply_async( remote = storage_tasks.export_disk.apply_async(
kwargs={ kwargs={
"disk_desc": self.get_disk_desc(), "disk_desc": self.get_disk_desc(),
"disk_format": disk_format, "disk_format": disk_format,
"upload_link": upload_link, "upload_link": upload_link,
"port": port "port": port,
"store_identity_file": store_identity_file,
"store_ssh_mode": store_ssh_mode,
},
queue=queue_name)
return self._run_abortable_task(remote, task)
def export_disk_to_datastore(self, task, disk_format, datastore):
queue_name = self.get_remote_queue_name('storage', priority='slow')
remote = storage_tasks.export_disk_to_datastore.apply_async(
kwargs={
"disk_desc": self.get_disk_desc(),
"disk_format": disk_format,
"datastore": datastore,
}, },
queue=queue_name) queue=queue_name)
return self._run_abortable_task(remote, task) return self._run_abortable_task(remote, task)
......
...@@ -47,12 +47,17 @@ def download(disk_desc, url, resize): ...@@ -47,12 +47,17 @@ def download(disk_desc, url, resize):
@celery.task(name='storagedriver.import_disk') @celery.task(name='storagedriver.import_disk')
def import_disk(disk_desc, url, port): def import_disk(disk_desc, url, port, identity, mode):
pass pass
@celery.task(name='storagedriver.export_disk') @celery.task(name='storagedriver.export_disk')
def export_disk(disk_desc, disk_format, url, port): def export_disk(disk_desc, disk_format, url, port, identity, mode):
pass
@celery.task(name='storagedriver.export_disk_to_datastore')
def export_disk_to_datastore(disk_desc, disk_format, datastore):
pass pass
......
...@@ -49,6 +49,7 @@ from manager.scheduler import SchedulerError ...@@ -49,6 +49,7 @@ from manager.scheduler import SchedulerError
from monitor.client import Client from monitor.client import Client
from storage.models import Disk from storage.models import Disk
from storage.tasks import storage_tasks from storage.tasks import storage_tasks
from storage.models import DataStore
from .models import ( from .models import (
Instance, InstanceActivity, InstanceTemplate, Interface, Node, Instance, InstanceActivity, InstanceTemplate, Interface, Node,
NodeActivity, pwgen NodeActivity, pwgen
...@@ -57,6 +58,7 @@ from .tasks import agent_tasks, vm_tasks ...@@ -57,6 +58,7 @@ from .tasks import agent_tasks, vm_tasks
from .tasks.local_tasks import ( from .tasks.local_tasks import (
abortable_async_instance_operation, abortable_async_node_operation, abortable_async_instance_operation, abortable_async_node_operation,
) )
from django.conf import settings
try: try:
# Python 2: "unicode" is built-in # Python 2: "unicode" is built-in
...@@ -387,9 +389,6 @@ class DownloadDiskOperation(InstanceOperation): ...@@ -387,9 +389,6 @@ class DownloadDiskOperation(InstanceOperation):
"is: '%(checksum)s' (id: %(disk_id)s)."), url=url, checksum=disk.checksum, disk_id=str(disk.id)) "is: '%(checksum)s' (id: %(disk_id)s)."), url=url, checksum=disk.checksum, disk_id=str(disk.id))
@register_operation @register_operation
class ImportDiskOperation(InstanceOperation): class ImportDiskOperation(InstanceOperation):
id = 'import_disk' id = 'import_disk'
...@@ -412,7 +411,8 @@ class ImportDiskOperation(InstanceOperation): ...@@ -412,7 +411,8 @@ class ImportDiskOperation(InstanceOperation):
def _operation(self, user, name, disk_path, task): def _operation(self, user, name, disk_path, task):
store = Store(user) store = Store(user)
download_link, port = store.request_ssh_download(disk_path) download_link, port = store.request_ssh_download(disk_path)
disk = Disk.import_disk(user, name, download_link, port, task) ogging.debug(settings)
disk = Disk.import_disk(task, user, name, download_link, port, settings.STORE_IDENTITY_FILE, settings.STORE_SSH_MODE)
self.instance.disks.add(disk) self.instance.disks.add(disk)
...@@ -433,11 +433,17 @@ class ExportDiskOperation(InstanceOperation): ...@@ -433,11 +433,17 @@ class ExportDiskOperation(InstanceOperation):
except NoStoreException: except NoStoreException:
raise PermissionDenied raise PermissionDenied
def _operation(self, user, disk, exported_name, disk_format, task): def _operation(self, user, disk, exported_name, disk_format, export_target, task):
if export_target == "user_store":
store = Store(user) store = Store(user)
upload_link, port = store.request_ssh_upload() upload_link, port = store.request_ssh_upload()
file_name = disk.export(disk_format, upload_link, port, task) file_name = disk.export_disk(task, disk_format, upload_link, port, settings.STORE_IDENTITY_FILE, settings.STORE_SSH_MODE)
store.ssh_upload_finished(file_name, exported_name + '.' + disk_format) store.ssh_upload_finished(file_name, exported_name + '.' + disk_format)
elif export_target == "datastore":
datastore = DataStore.objects.filter(name=settings.EXPORT_DATASTORE).get()
disk.export_disk_to_datastore(task, disk_format, datastore.path)
else:
raise Exception("Invalid export target")
@register_operation @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