blob: e4f75a5f20df6af4b0369de5c84e2aac9fe52340 [file] [log] [blame]
# models.py - vSGW Models
from core.models import Service, TenantWithContainer, Image
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")
image_name = models.CharField(max_length=254, help_text="Name of VM image")
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)
@property
def image(self):
img = self.image_name.strip()
if img.lower() != "default":
return Image.objects.get(name=img)
else:
return super(VSGWTenant, self).image
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()