[MCORD-183] Fix instance creation bug from UI

Change-Id: I0f8ab2cf15d08874ead0e83b1e518cc31ce71c2f
diff --git a/xos/header.py b/xos/header.py
index 4a699d2..2e60747 100644
--- a/xos/header.py
+++ b/xos/header.py
@@ -13,9 +13,3 @@
 from xos.config import Config
 from django.contrib.contenttypes.models import ContentType
 from django.contrib.contenttypes.fields import GenericForeignKey
-
-MCORD_KIND = "vEPC"
-SERVICE_NAME_VERBOSE = 'Virtual Home Subscriber Server Service'
-SERVICE_NAME_VERBOSE_PLURAL = 'Virtual Home Suscriber Server Services'
-TENANT_NAME_VERBOSE = 'Virtual Home Subscriber Server Tenant'
-TENANT_NAME_VERBOSE_PLURAL = 'Virtual Home Subscriber Server Tenants'
diff --git a/xos/models.py b/xos/models.py
new file mode 100644
index 0000000..d30acce
--- /dev/null
+++ b/xos/models.py
@@ -0,0 +1,40 @@
+from core.models.plcorebase import *
+from models_decl import VHSSService_decl
+from models_decl import VHSSTenant_decl
+
+class VHSSService(VHSSService_decl):
+   class Meta:
+        proxy = True 
+
+class VHSSTenant(VHSSTenant_decl):
+   class Meta:
+        proxy = True 
+
+   def __init__(self, *args, **kwargs):
+       vhssservice = VHSSService.get_service_objects().all()
+       if vhssservice:
+           self._meta.get_field(
+                   "provider_service").default = vhssservice[0].id
+       super(VHSSTenant, self).__init__(*args, **kwargs)
+
+   def save(self, *args, **kwargs):
+       super(VHSSTenant, 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_vhsstenant(self.pk)
+
+   def delete(self, *args, **kwargs):
+       # Delete the instance that was created for this tenant
+       self.cleanup_container()
+       super(VHSSTenant, self).delete(*args, **kwargs)
+
+def model_policy_vhsstenant(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 = VHSSTenant.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/vhss.xproto b/xos/vhss.xproto
index 165802e..740bc27 100644
--- a/xos/vhss.xproto
+++ b/xos/vhss.xproto
@@ -1,6 +1,7 @@
 option name = "vHSS";
 option verbose_name = "Virtual Home Subscriber Server";
 option kind = "vEPC";
+option legacy = "True";
 
 message VHSSService (Service){
      option name = "VHSSService";
@@ -8,7 +9,6 @@
      required string service_message = 1 [help_text = "Service Message to Display", max_length = 254, null = False, db_index = False, blank = False];
 }
 
-
 message VHSSTenant (TenantWithContainer){
      option name = "VHSSTenant";
      option verbose_name = "Virtual Home Subscriber Server Tenant";