[MCORD-183] Fix instance creation bug from UI
Change-Id: I163b93a080995cb04f552ced02c9692a60527a50
diff --git a/xos/header.py b/xos/header.py
index 5a7f4bc..20a9153 100644
--- a/xos/header.py
+++ b/xos/header.py
@@ -1,11 +1,3 @@
-# models.py - vBBU Models
-
from core.models import Service, TenantWithContainer
from django.db import transaction
from django.db.models import *
-
-SERVICE_NAME = 'vbbuservice'
-SERVICE_NAME_VERBOSE = 'vBBU Service'
-SERVICE_NAME_VERBOSE_PLURAL = 'vBBU Services'
-TENANT_NAME_VERBOSE = 'vBBU Tenant'
-TENANT_NAME_VERBOSE_PLURAL = 'vBBU Tenants'
diff --git a/xos/models.py b/xos/models.py
new file mode 100644
index 0000000..3169185
--- /dev/null
+++ b/xos/models.py
@@ -0,0 +1,40 @@
+from core.models.plcorebase import *
+from models_decl import VBBUService_decl
+from models_decl import VBBUTenant_decl
+
+class VBBUService(VBBUService_decl):
+ class Meta:
+ proxy = True
+
+class VBBUTenant(VBBUTenant_decl):
+ class Meta:
+ proxy = True
+
+ def __init__(self, *args, **kwargs):
+ vbbuservice = VBBUService.get_service_objects().all()
+ if vbbuservice:
+ self._meta.get_field(
+ "provider_service").default = vbbuservice[0].id
+ super(VBBUTenant, self).__init__(*args, **kwargs)
+
+ def save(self, *args, **kwargs):
+ super(VBBUTenant, self).save(*args, **kwargs)
+ # This call needs to happen so that an instance is created for this
+ # tenant is created in the slice. One instance is created per tenant.
+ model_policy_vbbutenant(self.pk)
+
+ def delete(self, *args, **kwargs):
+ # Delete the instance that was created for this tenant
+ self.cleanup_container()
+ super(VBBUTenant, self).delete(*args, **kwargs)
+
+def model_policy_vbbutenant(pk):
+ # This section of code is atomic to prevent race conditions
+ with transaction.atomic():
+ # We find all of the tenants that are waiting to update
+ tenant = VBBUTenant.objects.select_for_update().filter(pk=pk)
+ if not tenant:
+ return
+ # Since this code is atomic it is safe to always use the first tenant
+ tenant = tenant[0]
+ tenant.manage_container()
diff --git a/xos/vbbu.xproto b/xos/vbbu.xproto
index 6fd9049..2a30222 100644
--- a/xos/vbbu.xproto
+++ b/xos/vbbu.xproto
@@ -2,12 +2,12 @@
option app_label = "vbbu";
option verbose_name = "vBBU Service";
option kind = "vRAN";
+option legacy = "True";
message VBBUService (Service){
required string service_message = 1 [help_text = "Service Message to Display", max_length = 254, null = False, db_index = False, blank = False];
}
-
message VBBUTenant (TenantWithContainer){
option name = "vbbutenant";
option verbose_name = "vBBU Tenant";