[MCORD-183] Fix instance creation from UI

Change-Id: I4f5db09aa17e96819f797a7bf68706ec7f683d43
diff --git a/xos/header.py b/xos/header.py
index c59db86..3e067b7 100644
--- a/xos/header.py
+++ b/xos/header.py
@@ -14,10 +14,3 @@
 from django.contrib.contenttypes.models import ContentType
 from django.contrib.contenttypes.fields import GenericForeignKey
 
-MCORD_KIND = 'RAN'
-
-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'
\ No newline at end of file
diff --git a/xos/models.py b/xos/models.py
new file mode 100644
index 0000000..c465d96
--- /dev/null
+++ b/xos/models.py
@@ -0,0 +1,41 @@
+from core.models.plcorebase import *
+from models_decl import VSGWService_decl
+from models_decl import VSGWTenant_decl
+
+class VSGWService(VSGWService_decl):
+   class Meta:
+        proxy = True 
+
+class VSGWTenant(VSGWTenant_decl):
+   class Meta:
+        proxy = True 
+        
+   def __init__(self, *args, **kwargs):
+       vsgwservice = VSGWService.get_service_objects().all()
+       if vsgwservice:
+           self._meta.get_field(
+                   "provider_service").default = vsgwservice[0].id
+       super(VSGWTenant, self).__init__(*args, **kwargs)
+
+   def save(self, *args, **kwargs):
+       super(VSGWTenant, 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_vsgwtenant(self.pk)
+
+   def delete(self, *args, **kwargs):
+       # Delete the instance that was created for this tenant
+       self.cleanup_container()
+       super(VSGWTenant, self).delete(*args, **kwargs)
+
+def model_policy_vsgwtenant(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 = VSGWTenant.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/vsgw.xproto b/xos/vsgw.xproto
index 23033fd..6b6b1c7 100644
--- a/xos/vsgw.xproto
+++ b/xos/vsgw.xproto
@@ -2,12 +2,12 @@
 option app_label = "vsgw";
 option verbose_name = "vSGW Service";
 option kind = "vEPC";
+option legacy = "True";
 
 message VSGWService (Service){
     required string service_message = 1 [help_text = "Service Message to Display", max_length = 254, null = False, db_index = False, blank = False];
 }
 
-
 message VSGWTenant (TenantWithContainer){
      option name = "vsgwtenant";
      option verbose_name = "VSGW Tenant";