Commit b15a5b61 by Karsa Zoltán István

setup datastore for disk download

parent 9bc075e4
...@@ -158,6 +158,7 @@ class VlanSerializer(serializers.ModelSerializer): ...@@ -158,6 +158,7 @@ class VlanSerializer(serializers.ModelSerializer):
class CreateDiskSerializer(serializers.Serializer): class CreateDiskSerializer(serializers.Serializer):
size = serializers.CharField(max_length=50) size = serializers.CharField(max_length=50)
name = serializers.CharField(max_length=100) name = serializers.CharField(max_length=100)
datastore = serializers.CharField(max_length=40, required=False, allow_blank=True, default=None)
class ResizeDiskSerializer(serializers.Serializer): class ResizeDiskSerializer(serializers.Serializer):
...@@ -168,6 +169,7 @@ class DownloadDiskSerializer(serializers.Serializer): ...@@ -168,6 +169,7 @@ 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) resize = serializers.CharField(max_length=30, required=False, allow_blank=True, default=None)
datastore = serializers.CharField(max_length=40, required=False, allow_blank=True, default=None)
class Meta: class Meta:
extra_kwargs = {'resize': {'required': False, 'allow_blank': True, 'allow_empty': True }} extra_kwargs = {'resize': {'required': False, 'allow_blank': True, 'allow_empty': True }}
......
...@@ -133,7 +133,10 @@ class CreatePersistentDiskREST(APIView): ...@@ -133,7 +133,10 @@ class CreatePersistentDiskREST(APIView):
if serializer.is_valid(): if serializer.is_valid():
disk_size = str(size_util(str(data['size']))) disk_size = str(size_util(str(data['size'])))
disk_name = str(data['name']) disk_name = str(data['name'])
disk = Disk.create(size=disk_size, name=disk_name, type="qcow2-norm") datastore = 'default'
if 'datastore' in data:
datastore = data['datastore']
disk = Disk.create(size=disk_size, name=disk_name, type="qcow2-norm", datastore=datastore)
disk.full_clean() disk.full_clean()
disk.dev_num = 'f' disk.dev_num = 'f'
disk.save() disk.save()
...@@ -155,8 +158,12 @@ class DownloadPersistentDiskREST(APIView): ...@@ -155,8 +158,12 @@ class DownloadPersistentDiskREST(APIView):
resize = None resize = None
if 'resize' in data: if 'resize' in data:
resize = str(data['resize']) resize = str(data['resize'])
datastore = 'default'
if 'datastore' in data:
datastore = data['datastore']
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, resize), queue='localhost.man.slow') abortable_async_downloaddisk_operation.apply_async(
args=(store_act.id, disk_url, disk_name, resize, datastore), 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)
......
...@@ -453,7 +453,7 @@ class Disk(TimeStampedModel): ...@@ -453,7 +453,7 @@ class Disk(TimeStampedModel):
params.setdefault('name', 'ci-disk') params.setdefault('name', 'ci-disk')
params.setdefault('type', 'raw-ro') params.setdefault('type', 'raw-ro')
params.setdefault('size', None) params.setdefault('size', None)
disk = cls.__create(params=params, user=user) disk = cls.__create(params=params, user=user, datastore='default')
queue_name = disk.get_remote_queue_name('storage', priority="fast") queue_name = disk.get_remote_queue_name('storage', priority="fast")
disk_desc = disk.get_disk_desc() disk_desc = disk.get_disk_desc()
result = storage_tasks.create_ci_disk.apply_async(args=[disk_desc, meta_data, user_data, network_data], result = storage_tasks.create_ci_disk.apply_async(args=[disk_desc, meta_data, user_data, network_data],
......
...@@ -60,12 +60,12 @@ def abortable_async_node_operation(task, operation_id, node_pk, activity_pk, ...@@ -60,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, resize): def abortable_async_downloaddisk_operation(task, activity_pk, url, name, resize, datastore):
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, resize=resize) disk = Disk.download(url=url, name=name, task=task, resize=resize, datastore=datastore)
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