blob: b06b72fd302a30db1810f03be17d790b03e8519b [file] [log] [blame]
Murat Parlakisik66fde4d2016-09-22 13:28:13 -07001# models.py - vSGW Models
2
JianHaoce45e042017-01-16 11:06:29 +00003from core.models import Service, TenantWithContainer
4from django.db import models, transaction
5
6MCORD_KIND = 'EPC'
7
Murat Parlakisik66fde4d2016-09-22 13:28:13 -07008SERVICE_NAME = 'vsgw'
9SERVICE_NAME_VERBOSE = 'Virtual SGW Service'
10SERVICE_NAME_VERBOSE_PLURAL = 'Virtual SGW Services'
11TENANT_NAME_VERBOSE = 'Virtual SGW Tenant'
12TENANT_NAME_VERBOSE_PLURAL = 'Virtual SGW Tenants'
13
14class VSGWService(Service):
15
16 KIND = SERVICE_NAME
17
18 class Meta:
JianHaoce45e042017-01-16 11:06:29 +000019 proxy = True
Murat Parlakisik66fde4d2016-09-22 13:28:13 -070020 app_label = SERVICE_NAME
21 verbose_name = SERVICE_NAME_VERBOSE
22
Murat Parlakisik66fde4d2016-09-22 13:28:13 -070023class VSGWTenant(TenantWithContainer):
24
25 KIND = SERVICE_NAME
26
27 class Meta:
28 verbose_name = TENANT_NAME_VERBOSE
29
30 tenant_message = models.CharField(max_length=254, help_text="Tenant Message to Display")
31
32 def __init__(self, *args, **kwargs):
33 vsgw_service = VSGWService.get_service_objects().all()
34 if vsgw_service:
35 self._meta.get_field('provider_service').default = vsgw_service[0].id
JianHaoce45e042017-01-16 11:06:29 +000036 super(VSGWTenant, self).__init__(*args, **kwargs)
Murat Parlakisik66fde4d2016-09-22 13:28:13 -070037
38 def save(self, *args, **kwargs):
39 super(VSGWTenant, self).save(*args, **kwargs)
JianHaoce45e042017-01-16 11:06:29 +000040 model_policy_vsgwtenant(self.pk)
Murat Parlakisik66fde4d2016-09-22 13:28:13 -070041
42 def delete(self, *args, **kwargs):
43 self.cleanup_container()
44 super(VSGWTenant, self).delete(*args, **kwargs)
45
JianHaoce45e042017-01-16 11:06:29 +000046def model_policy_vsgwtenant(pk):
Murat Parlakisik66fde4d2016-09-22 13:28:13 -070047 with transaction.atomic():
48 tenant = VSGWTenant.objects.select_for_update().filter(pk=pk)
49 if not tenant:
50 return
51 tenant = tenant[0]
JianHaoce45e042017-01-16 11:06:29 +000052 tenant.manage_container()