blob: 0c185e69152dd222a49e3041112168832649d24f [file] [log] [blame]
Saleil Bhat45419542017-01-06 15:25:57 -08001# models.py - ExampleService Models
2
3from core.models import Service, TenantWithContainer
4from django.db import models, transaction
5
6
7MCORD_KIND = "EPC" #added from vBBU
8
9#these macros are currently not used, names hard-coded manually
10SERVICE_NAME = 'vmme'
11SERVICE_NAME_VERBOSE = 'VMME Service'
12SERVICE_NAME_VERBOSE_PLURAL = 'VMME Services'
13TENANT_NAME_VERBOSE = 'VMME Service Tenant'
14TENANT_NAME_VERBOSE_PLURAL = 'VMME Service Tenants'
15
16class VMMEService(Service):
17
18 KIND = MCORD_KIND
19
20 class Meta:
21 proxy = True
22 app_label = "vmme"
23 verbose_name = "VMME Service"
24
25class 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
49def 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