| # models.py - vSGW Models |
| |
| from core.models import Service, TenantWithContainer |
| from django.db import models, transaction |
| |
| MCORD_KIND = 'EPC' |
| |
| SERVICE_NAME = 'vsgw' |
| SERVICE_NAME_VERBOSE = 'Virtual SGW Service' |
| SERVICE_NAME_VERBOSE_PLURAL = 'Virtual SGW Services' |
| TENANT_NAME_VERBOSE = 'Virtual SGW Tenant' |
| TENANT_NAME_VERBOSE_PLURAL = 'Virtual SGW Tenants' |
| |
| class VSGWService(Service): |
| |
| KIND = SERVICE_NAME |
| |
| class Meta: |
| proxy = True |
| app_label = SERVICE_NAME |
| verbose_name = SERVICE_NAME_VERBOSE |
| |
| class VSGWTenant(TenantWithContainer): |
| |
| KIND = SERVICE_NAME |
| |
| class Meta: |
| verbose_name = TENANT_NAME_VERBOSE |
| |
| tenant_message = models.CharField(max_length=254, help_text="Tenant Message to Display") |
| |
| def __init__(self, *args, **kwargs): |
| vsgw_service = VSGWService.get_service_objects().all() |
| if vsgw_service: |
| self._meta.get_field('provider_service').default = vsgw_service[0].id |
| super(VSGWTenant, self).__init__(*args, **kwargs) |
| |
| def save(self, *args, **kwargs): |
| super(VSGWTenant, self).save(*args, **kwargs) |
| model_policy_vsgwtenant(self.pk) |
| |
| def delete(self, *args, **kwargs): |
| self.cleanup_container() |
| super(VSGWTenant, self).delete(*args, **kwargs) |
| |
| def model_policy_vsgwtenant(pk): |
| with transaction.atomic(): |
| tenant = VSGWTenant.objects.select_for_update().filter(pk=pk) |
| if not tenant: |
| return |
| tenant = tenant[0] |
| tenant.manage_container() |