blob: e49a93fd4a092ca376f044f24d768f8688f0efa1 [file] [log] [blame]
Saleil Bhat45419542017-01-06 15:25:57 -08001# models.py - ExampleService Models
2
Saleil Bhatf57ebfd2017-01-21 23:10:09 -08003from core.models import Service, TenantWithContainer, Image
Saleil Bhat45419542017-01-06 15:25:57 -08004from 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")
Saleil Bhatf57ebfd2017-01-21 23:10:09 -080032 image_name = models.CharField(max_length=254, help_text="Name of VM image")
Saleil Bhat45419542017-01-06 15:25:57 -080033
Saleil Bhat45419542017-01-06 15:25:57 -080034 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
Saleil Bhatf57ebfd2017-01-21 23:10:09 -080048 @property
49 def image(self):
50 img = self.image_name.strip()
51 if img.lower() != "default":
52 return Image.objects.get(name=img)
53 else:
54 return super(VMMETenant, self).image
55
56
Saleil Bhat45419542017-01-06 15:25:57 -080057
58def model_policy_vmmetenant(pk):
59 with transaction.atomic():
60 tenant = VMMETenant.objects.select_for_update().filter(pk=pk)
61 if not tenant:
62 return
63 tenant = tenant[0]
64 tenant.manage_container()
65