Murat Parlakisik | 66fde4d | 2016-09-22 13:28:13 -0700 | [diff] [blame] | 1 | # models.py - vSGW Models |
| 2 | |
JianHao | ce45e04 | 2017-01-16 11:06:29 +0000 | [diff] [blame^] | 3 | from core.models import Service, TenantWithContainer |
| 4 | from django.db import models, transaction |
| 5 | |
| 6 | MCORD_KIND = 'EPC' |
| 7 | |
Murat Parlakisik | 66fde4d | 2016-09-22 13:28:13 -0700 | [diff] [blame] | 8 | SERVICE_NAME = 'vsgw' |
| 9 | SERVICE_NAME_VERBOSE = 'Virtual SGW Service' |
| 10 | SERVICE_NAME_VERBOSE_PLURAL = 'Virtual SGW Services' |
| 11 | TENANT_NAME_VERBOSE = 'Virtual SGW Tenant' |
| 12 | TENANT_NAME_VERBOSE_PLURAL = 'Virtual SGW Tenants' |
| 13 | |
| 14 | class VSGWService(Service): |
| 15 | |
| 16 | KIND = SERVICE_NAME |
| 17 | |
| 18 | class Meta: |
JianHao | ce45e04 | 2017-01-16 11:06:29 +0000 | [diff] [blame^] | 19 | proxy = True |
Murat Parlakisik | 66fde4d | 2016-09-22 13:28:13 -0700 | [diff] [blame] | 20 | app_label = SERVICE_NAME |
| 21 | verbose_name = SERVICE_NAME_VERBOSE |
| 22 | |
Murat Parlakisik | 66fde4d | 2016-09-22 13:28:13 -0700 | [diff] [blame] | 23 | class 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 |
JianHao | ce45e04 | 2017-01-16 11:06:29 +0000 | [diff] [blame^] | 36 | super(VSGWTenant, self).__init__(*args, **kwargs) |
Murat Parlakisik | 66fde4d | 2016-09-22 13:28:13 -0700 | [diff] [blame] | 37 | |
| 38 | def save(self, *args, **kwargs): |
| 39 | super(VSGWTenant, self).save(*args, **kwargs) |
JianHao | ce45e04 | 2017-01-16 11:06:29 +0000 | [diff] [blame^] | 40 | model_policy_vsgwtenant(self.pk) |
Murat Parlakisik | 66fde4d | 2016-09-22 13:28:13 -0700 | [diff] [blame] | 41 | |
| 42 | def delete(self, *args, **kwargs): |
| 43 | self.cleanup_container() |
| 44 | super(VSGWTenant, self).delete(*args, **kwargs) |
| 45 | |
JianHao | ce45e04 | 2017-01-16 11:06:29 +0000 | [diff] [blame^] | 46 | def model_policy_vsgwtenant(pk): |
Murat Parlakisik | 66fde4d | 2016-09-22 13:28:13 -0700 | [diff] [blame] | 47 | with transaction.atomic(): |
| 48 | tenant = VSGWTenant.objects.select_for_update().filter(pk=pk) |
| 49 | if not tenant: |
| 50 | return |
| 51 | tenant = tenant[0] |
JianHao | ce45e04 | 2017-01-16 11:06:29 +0000 | [diff] [blame^] | 52 | tenant.manage_container() |