2021-08-09 07:43:11 +00:00
|
|
|
import json
|
2021-07-19 14:36:10 +00:00
|
|
|
from matrixhosting.models import VMInstance
|
|
|
|
from uncloud_pay.models import Order
|
|
|
|
from django.db.models.signals import post_save
|
|
|
|
from django.dispatch import receiver
|
|
|
|
|
|
|
|
@receiver(post_save, sender=Order)
|
|
|
|
def create_instance(sender, instance, created, **kwargs):
|
2021-08-09 07:43:11 +00:00
|
|
|
if not created:
|
|
|
|
return
|
2021-07-19 14:36:10 +00:00
|
|
|
machine = VMInstance.objects.filter(order=instance).first()
|
|
|
|
if not machine:
|
2021-08-09 07:43:11 +00:00
|
|
|
order_config = json.loads(instance.config)
|
|
|
|
instance_config = {'cpuCores': order_config['cores'], 'ram': order_config['memory'], 'storage': order_config['storage'],
|
|
|
|
'matrixDomain': order_config['matrix_domain'], 'homeserverDomain': order_config['homeserver_domain'],
|
|
|
|
'webClientDomain': order_config['webclient_domain'], 'isOpenRegistration': order_config['is_open_registration']}
|
|
|
|
VMInstance.objects.create(owner=instance.owner, order=instance, vm_name=order_config['homeserver_domain'],
|
|
|
|
homeserver_domain=order_config['homeserver_domain'],webclient_domain=order_config['webclient_domain'],
|
|
|
|
config=instance_config)
|