Saleil Bhat | 1c5593d | 2017-01-06 15:25:57 -0800 | [diff] [blame] | 1 | # models.py - ExampleService Models |
| 2 | |
| 3 | from core.models import Service, TenantWithContainer |
| 4 | from django.db import models, transaction |
| 5 | |
| 6 | |
| 7 | MCORD_KIND = "EPC" #added from vBBU |
| 8 | |
| 9 | #these macros are currently not used, names hard-coded manually |
| 10 | SERVICE_NAME = 'vmme' |
| 11 | SERVICE_NAME_VERBOSE = 'VMME Service' |
| 12 | SERVICE_NAME_VERBOSE_PLURAL = 'VMME Services' |
| 13 | TENANT_NAME_VERBOSE = 'VMME Service Tenant' |
| 14 | TENANT_NAME_VERBOSE_PLURAL = 'VMME Service Tenants' |
| 15 | |
| 16 | class VMMEService(Service): |
| 17 | |
| 18 | KIND = MCORD_KIND |
| 19 | |
| 20 | class Meta: |
| 21 | proxy = True |
| 22 | app_label = "vmme" |
| 23 | verbose_name = "VMME Service" |
| 24 | |
| 25 | class VMMETenant(TenantWithContainer): |
| 26 | |
| 27 | KIND = 'vmme' |
| 28 | class Meta: |
| 29 | verbose_name = "VMME Service Tenant" |
| 30 | |
| 31 | tenant_message = models.CharField(max_length=254, help_text="vMME message") |
| 32 | |
| 33 | #default_attributes = {"tenant_message": "New vMME Component"} will this work? |
| 34 | def __init__(self, *args, **kwargs): |
| 35 | vmme_services = VMMEService.get_service_objects().all() |
| 36 | if vmme_services: |
| 37 | self._meta.get_field('provider_service').default = vmme_services[0].id |
| 38 | super(VMMETenant, self).__init__(*args, **kwargs) |
| 39 | |
| 40 | def save(self, *args, **kwargs): |
| 41 | super(VMMETenant, self).save(*args, **kwargs) |
| 42 | model_policy_vmmetenant(self.pk) #defined below |
| 43 | |
| 44 | def delete(self, *args, **kwargs): |
| 45 | self.cleanup_container() |
| 46 | super(VMMETenant, self).delete(*args, **kwargs) |
| 47 | |
| 48 | |
| 49 | def model_policy_vmmetenant(pk): |
| 50 | with transaction.atomic(): |
| 51 | tenant = VMMETenant.objects.select_for_update().filter(pk=pk) |
| 52 | if not tenant: |
| 53 | return |
| 54 | tenant = tenant[0] |
| 55 | tenant.manage_container() |
| 56 | |