Commit 4c1a75d2 by Szeberényi Imre

Merge branch 'webhook-iac' into 'master'

Webhook iac

See merge request !21
parents aa2237b4 3d3c1adb
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
......
...@@ -104,12 +104,11 @@ chpasswd: ...@@ -104,12 +104,11 @@ chpasswd:
""".strip() """.strip()
CI_NETWORK_CONFIG_DEF = """ CI_NETWORK_CONFIG_DEF = """
network: version: 2
version: 2 ethernets:
ethernets:
ens3: ens3:
match: match:
macaddress: {{ net.mac }} macaddress: '{{ net.mac }}'
addresses: addresses:
- {{ net.ipv4 }}/{{ net.mask4 }} - {{ net.ipv4 }}/{{ net.mask4 }}
gateway4: {{ net.gateway4 }} gateway4: {{ net.gateway4 }}
...@@ -319,13 +318,13 @@ class NetTemplate: ...@@ -319,13 +318,13 @@ class NetTemplate:
self.name = str(net.vlan.name) self.name = str(net.vlan.name)
self.gateway4 = str(net.vlan.network4).split("/")[0] self.gateway4 = str(net.vlan.network4).split("/")[0]
self.mask4 = str(net.vlan.network4).split("/")[1] self.mask4 = str(net.vlan.network4).split("/")[1]
self.mac = str(net.host.mac) self.mac = str(net.host.mac).lower()
def __init__(self, instance): def __init__(self, instance):
self.vlans = list(NetTemplate.Host(net) for net in instance.interface_set.all() if net.host) self.vlans = list(NetTemplate.Host(net) for net in instance.interface_set.all() if net.host)
self.ipv4 = str(instance.ipv4) self.ipv4 = str(instance.ipv4)
self.ipv6 = str(instance.ipv6) self.ipv6 = str(instance.ipv6)
self.mac = str(instance.mac) self.mac = str(instance.mac).lower()
if instance.primary_host: if instance.primary_host:
addr = str(instance.primary_host.vlan.network4).split("/") addr = str(instance.primary_host.vlan.network4).split("/")
self.gateway4 = addr[0] self.gateway4 = addr[0]
...@@ -501,7 +500,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin, ...@@ -501,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