Murat Parlakisik | 66fde4d | 2016-09-22 13:28:13 -0700 | [diff] [blame^] | 1 | # models.py - vSGW Models |
| 2 | |
| 3 | SERVICE_NAME = 'vsgw' |
| 4 | SERVICE_NAME_VERBOSE = 'Virtual SGW Service' |
| 5 | SERVICE_NAME_VERBOSE_PLURAL = 'Virtual SGW Services' |
| 6 | TENANT_NAME_VERBOSE = 'Virtual SGW Tenant' |
| 7 | TENANT_NAME_VERBOSE_PLURAL = 'Virtual SGW Tenants' |
| 8 | |
| 9 | class VSGWService(Service): |
| 10 | |
| 11 | KIND = SERVICE_NAME |
| 12 | |
| 13 | class Meta: |
| 14 | app_label = SERVICE_NAME |
| 15 | verbose_name = SERVICE_NAME_VERBOSE |
| 16 | |
| 17 | service_message = models.CharField(max_length=254, help_text="Service Message to Display") |
| 18 | |
| 19 | class VSGWTenant(TenantWithContainer): |
| 20 | |
| 21 | KIND = SERVICE_NAME |
| 22 | |
| 23 | class Meta: |
| 24 | verbose_name = TENANT_NAME_VERBOSE |
| 25 | |
| 26 | tenant_message = models.CharField(max_length=254, help_text="Tenant Message to Display") |
| 27 | |
| 28 | def __init__(self, *args, **kwargs): |
| 29 | vsgw_service = VSGWService.get_service_objects().all() |
| 30 | if vsgw_service: |
| 31 | self._meta.get_field('provider_service').default = vsgw_service[0].id |
| 32 | super(ExampleTenant, self).__init__(*args, **kwargs) |
| 33 | |
| 34 | def save(self, *args, **kwargs): |
| 35 | super(VSGWTenant, self).save(*args, **kwargs) |
| 36 | model_policy_exampletenant(self.pk) |
| 37 | |
| 38 | def delete(self, *args, **kwargs): |
| 39 | self.cleanup_container() |
| 40 | super(VSGWTenant, self).delete(*args, **kwargs) |
| 41 | |
| 42 | |
| 43 | def model_policy_exampletenant(pk): |
| 44 | with transaction.atomic(): |
| 45 | tenant = VSGWTenant.objects.select_for_update().filter(pk=pk) |
| 46 | if not tenant: |
| 47 | return |
| 48 | tenant = tenant[0] |
| 49 | tenant.manage_container() |