Commit 31bb2f5c by Karsa Zoltán István

webhook for system operations

parent 2ca1821d
......@@ -89,11 +89,13 @@ class InstanceSerializer(serializers.ModelSerializer):
model = Instance
fields = ['id', 'name', 'description', 'status', 'owner', 'access_method', 'boot_menu', 'pw', 'is_base',
'lease', 'raw_data', 'cloud_init', 'ci_meta_data', 'ci_user_data', 'system', 'req_traits', 'interface_set',
'has_agent', 'num_cores', 'ram_size', 'max_ram_size', 'arch', 'priority', 'disks', 'node', 'ipv4addr', 'ipv6addr', 'vlans']
'has_agent', 'num_cores', 'ram_size', 'max_ram_size', 'arch', 'priority', 'disks', 'node', 'ipv4addr', 'ipv6addr', 'vlans'
'hookurl']
extra_kwargs = {
'disks': {'required': False, 'allow_empty': True,},
'req_traits': {'required': False, 'allow_empty': True,},
'interface_set': {'required': False, 'allow_empty': True,}
'interface_set': {'required': False, 'allow_empty': True,},
'hookurl': {'required': False, 'allow_empty': True,}
}
......
# Generated by Django 3.2.3 on 2022-10-04 09:53
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('vm', '0010_auto_20220914_1532'),
]
operations = [
migrations.AddField(
model_name='instance',
name='hookurl',
field=models.CharField(blank=True, help_text='If expiration due, call remote url.', max_length=250, verbose_name='hookurl'),
),
]
......@@ -23,6 +23,7 @@ from functools import partial
from importlib import import_module
from ipaddress import ip_interface
from logging import getLogger
from urllib import request
from warnings import warn
from xml.dom.minidom import Text
......@@ -325,6 +326,8 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
)
name = CharField(blank=True, max_length=100, verbose_name=_('name'),
help_text=_("Human readable name of instance."))
hookurl = CharField(blank=True, max_length=250, verbose_name=_('hookurl'),
help_text=_("If expiration due, call remote url."))
description = TextField(blank=True, verbose_name=_('description'))
template = ForeignKey(InstanceTemplate, blank=True, null=True,
related_name='instance_set', on_delete=SET_NULL,
......@@ -454,6 +457,11 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
yaml.dump(yaml.load(data, Loader=yaml.Loader))
return True
def callhookurl(self):
import requests as req
if self.hookurl:
req.get(url=self.hookurl)
def _update_status(self):
"""Set the proper status of the instance to Instance.status.
"""
......
......@@ -616,6 +616,8 @@ class DestroyOperation(InstanceOperation):
self.instance.destroyed_at = timezone.now()
self.instance.save()
if system:
self.instance.callhookurl()
@register_operation
class DeleteVmOperation(SubOperationMixin, RemoteInstanceOperation):
......@@ -1027,6 +1029,8 @@ class SleepOperation(InstanceOperation):
self.instance.shutdown_net()
self.instance._suspend_vm(parent_activity=activity)
self.instance.yield_node()
if system:
self.instance.callhookurl()
@register_operation
class SuspendVmOperation(SubOperationMixin, RemoteInstanceOperation):
......
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