Commit 3d3c1adb by Karsa Zoltán István

resize via download

parent 3cb1a197
from typing_extensions import Required
from rest_framework.renderers import JSONRenderer from rest_framework.renderers import JSONRenderer
from rest_framework import serializers from rest_framework import serializers
from django.contrib.auth.models import Group, User from django.contrib.auth.models import Group, User
...@@ -161,6 +162,10 @@ class ResizeDiskSerializer(serializers.Serializer): ...@@ -161,6 +162,10 @@ class ResizeDiskSerializer(serializers.Serializer):
class DownloadDiskSerializer(serializers.Serializer): class DownloadDiskSerializer(serializers.Serializer):
url = serializers.CharField(max_length=500) url = serializers.CharField(max_length=500)
name = serializers.CharField(max_length=100) name = serializers.CharField(max_length=100)
resize = serializers.CharField(max_length=30, required=False, allow_blank=True, default=None)
class Meta:
extra_kwargs = {'resize': {'required': False, 'allow_blank': True, 'allow_empty': True }}
class CreateTemplateSerializer(serializers.Serializer): class CreateTemplateSerializer(serializers.Serializer):
name = serializers.CharField(max_length=100) name = serializers.CharField(max_length=100)
......
...@@ -152,8 +152,11 @@ class DownloadPersistentDiskREST(APIView): ...@@ -152,8 +152,11 @@ class DownloadPersistentDiskREST(APIView):
if serializer.is_valid(): if serializer.is_valid():
disk_url = str(data['url']) disk_url = str(data['url'])
disk_name = str(data['name']) disk_name = str(data['name'])
resize = None
if 'resize' in data:
resize = str(data['resize'])
store_act = StorageActivity.create(code_suffix="download_disk", user=request.user) store_act = StorageActivity.create(code_suffix="download_disk", user=request.user)
abortable_async_downloaddisk_operation.apply_async(args=(store_act.id, disk_url, disk_name), queue='localhost.man.slow') abortable_async_downloaddisk_operation.apply_async(args=(store_act.id, disk_url, disk_name, resize), queue='localhost.man.slow')
serializer = StorageActivitySerializer(store_act, many=False) serializer = StorageActivitySerializer(store_act, many=False)
return JsonResponse(serializer.data, status=201) return JsonResponse(serializer.data, status=201)
return JsonResponse(serializer.errors, status=400) return JsonResponse(serializer.errors, status=400)
......
...@@ -469,7 +469,7 @@ class Disk(TimeStampedModel): ...@@ -469,7 +469,7 @@ class Disk(TimeStampedModel):
return disk return disk
@classmethod @classmethod
def download(cls, url, task, user=None, **params): def download(cls, url, task, user=None, resize = None, **params):
"""Create disk object and download data from url synchronusly. """Create disk object and download data from url synchronusly.
:param url: image url to download. :param url: image url to download.
...@@ -491,7 +491,7 @@ class Disk(TimeStampedModel): ...@@ -491,7 +491,7 @@ class Disk(TimeStampedModel):
queue_name = disk.get_remote_queue_name('storage', priority='slow') queue_name = disk.get_remote_queue_name('storage', priority='slow')
remote = storage_tasks.download.apply_async( remote = storage_tasks.download.apply_async(
kwargs={'url': url, 'parent_id': task.request.id, kwargs={'url': url, 'parent_id': task.request.id,
'disk': disk.get_disk_desc()}, 'disk': disk.get_disk_desc(), 'resize': resize },
queue=queue_name) queue=queue_name)
result = cls._run_abortable_task(remote, task) result = cls._run_abortable_task(remote, task)
disk.size = result['size'] disk.size = result['size']
......
...@@ -37,9 +37,12 @@ def create(disk_desc): ...@@ -37,9 +37,12 @@ def create(disk_desc):
def create_ci_disk(disk_desc, meta_data, user_data, network_data): def create_ci_disk(disk_desc, meta_data, user_data, network_data):
pass pass
@celery.task(name='storagedriver.resizeqemu')
def resizeqemu(disk_desc, newsize):
pass
@celery.task(name='storagedriver.download') @celery.task(name='storagedriver.download')
def download(disk_desc, url): def download(disk_desc, url, resize):
pass pass
......
...@@ -500,7 +500,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin, ...@@ -500,7 +500,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
if self.hookurl: if self.hookurl:
logger.info("notify remote host (callhookurl): " + str(self.hookurl)) logger.info("notify remote host (callhookurl): " + str(self.hookurl))
try: try:
req.post(url=str(self.hookurl)) req.post(url=str(self.hookurl, json={ id: self.id }))
except: except:
logger.info("Error when call hookurl: " + str(self.hookurl)) logger.info("Error when call hookurl: " + str(self.hookurl))
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License along # You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>. # with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from ctypes import resize
from datetime import timezone from datetime import timezone
from celery.contrib.abortable import AbortableTask from celery.contrib.abortable import AbortableTask
from common.models import ActivityModel from common.models import ActivityModel
...@@ -59,12 +60,12 @@ def abortable_async_node_operation(task, operation_id, node_pk, activity_pk, ...@@ -59,12 +60,12 @@ def abortable_async_node_operation(task, operation_id, node_pk, activity_pk,
@celery.task(base=AbortableTask, bind=True) @celery.task(base=AbortableTask, bind=True)
def abortable_async_downloaddisk_operation(task, activity_pk, url, name): def abortable_async_downloaddisk_operation(task, activity_pk, url, name, resize):
activity = StorageActivity.objects.get(pk=activity_pk) activity = StorageActivity.objects.get(pk=activity_pk)
activity.task_uuid = task.request.id activity.task_uuid = task.request.id
activity.save() activity.save()
disk = Disk.download(url=url, name=name, task=task) disk = Disk.download(url=url, name=name, task=task, resize=resize)
disk.dev_num = 'g' disk.dev_num = 'g'
disk.full_clean() disk.full_clean()
disk.save() disk.save()
......
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