Add vsgw service to service list, for cord-3.0

Change-Id: Ic15f70b1cb83775d45be9659217f62298cd682ae
diff --git a/xos/admin.py b/xos/admin.py
index a7b9850..dffee2e 100644
--- a/xos/admin.py
+++ b/xos/admin.py
@@ -5,7 +5,8 @@
 from core.models import User
 from django import forms
 from django.contrib import admin
-from services.vsgw.models import *
+# from services.vsgw.models import *
+from synchronizers.new_base.modelaccessor import *
 
 class VSGWServiceForm(forms.ModelForm):
 
diff --git a/xos/header.py b/xos/header.py
new file mode 100644
index 0000000..c59db86
--- /dev/null
+++ b/xos/header.py
@@ -0,0 +1,23 @@
+from django.db import models
+from core.models import Service, PlCoreBase, Slice, Instance, Tenant, TenantWithContainer, Node, Image, User, Flavor, NetworkParameter, NetworkParameterType, Port, AddressPool
+from core.models.plcorebase import StrippedCharField
+import os
+from django.db import models, transaction
+from django.forms.models import model_to_dict
+from django.db.models import *
+from operator import itemgetter, attrgetter, methodcaller
+from core.models import Tag
+from core.models.service import LeastLoadedNodeScheduler
+import traceback
+from xos.exceptions import *
+from xos.config import Config
+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
deleted file mode 100644
index e4f75a5..0000000
--- a/xos/models.py
+++ /dev/null
@@ -1,61 +0,0 @@
-# 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()
diff --git a/xos/synchronizer/run-from-api.sh b/xos/synchronizer/run-from-api.sh
old mode 100644
new mode 100755
index 5cb8831..bcbc374
--- a/xos/synchronizer/run-from-api.sh
+++ b/xos/synchronizer/run-from-api.sh
@@ -1 +1,2 @@
-python vsgw-synchronizer.py
\ No newline at end of file
+export XOS_DIR=/opt/xos
+python vsgw-synchronizer.py  -C $XOS_DIR/synchronizers/vsgw/vsgw_from_api_config
\ No newline at end of file
diff --git a/xos/synchronizer/vsgw_from_api_config b/xos/synchronizer/vsgw_from_api_config
index 2fbd561..d0f23fd 100644
--- a/xos/synchronizer/vsgw_from_api_config
+++ b/xos/synchronizer/vsgw_from_api_config
@@ -4,6 +4,17 @@
 dependency_graph=/opt/xos/synchronizers/vsgw/model-deps
 steps_dir=/opt/xos/synchronizers/vsgw/steps
 sys_dir=/opt/xos/synchronizers/vsgw/sys
-accessor:
-  username: xosadmin@opencord.org
-  password: "@/opt/xos/services/vmme/credentials/xosadmin@opencord.org"
\ No newline at end of file
+#logfile=/var/log/xos_backend.log
+log_file=console
+log_level=debug
+pretend=False
+backoff_disabled=True
+save_ansible_output=True
+proxy_ssh=True
+proxy_ssh_key=/opt/cord_profile/node_key
+proxy_ssh_user=root
+accessor_kind=api
+accessor_password=@/opt/xos/services/vsgw/credentials/xosadmin@opencord.org
+
+[networking]
+use_vtn=True
\ No newline at end of file
diff --git a/xos/macros.m4 b/xos/tosca/custom_types/macros.m4
similarity index 100%
rename from xos/macros.m4
rename to xos/tosca/custom_types/macros.m4
diff --git a/xos/tosca/custom_types/vsgw.m4 b/xos/tosca/custom_types/vsgw.m4
new file mode 100644
index 0000000..9deb54b
--- /dev/null
+++ b/xos/tosca/custom_types/vsgw.m4
@@ -0,0 +1,18 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+# compile this with "m4 vbbu.m4 > vsgw.yaml"
+
+# include macros
+include(macros.m4)
+
+node_types:
+    tosca.nodes.VSGWService:
+        derived_from: tosca.nodes.Root
+        description: >
+            VSGW Service
+        capabilities:
+            xos_base_service_caps
+        properties:
+            xos_base_props
+            xos_base_service_props
+
diff --git a/xos/vsgw.yaml b/xos/tosca/custom_types/vsgw.yaml
similarity index 100%
rename from xos/vsgw.yaml
rename to xos/tosca/custom_types/vsgw.yaml
diff --git a/xos/tosca/resources/vsgwservice.py b/xos/tosca/resources/vsgwservice.py
index 02c9037..c3a9414 100644
--- a/xos/tosca/resources/vsgwservice.py
+++ b/xos/tosca/resources/vsgwservice.py
@@ -1,5 +1,6 @@
-from services.vsgw.models import VSGWService
+# from services.vsgw.models import VSGWService
 from xosresource import XOSResource
+from synchronizers.new_base.modelaccessor import *
 from service import XOSService
 
 class XOSVSGWService(XOSResource):
diff --git a/xos/tosca/resources/vsgwtenant.py b/xos/tosca/resources/vsgwtenant.py
index f53048a..48984fe 100644
--- a/xos/tosca/resources/vsgwtenant.py
+++ b/xos/tosca/resources/vsgwtenant.py
@@ -1,4 +1,5 @@
-from services.vsgw.models import *
+# from services.vsgw.models import *
+from synchronizers.new_base.modelaccessor import *
 from xosresource import XOSResource
 
 class XOSVSGWTenant(XOSResource):
diff --git a/xos/vsgw-onboard.yaml b/xos/vsgw-onboard.yaml
index 4354f8d..b9f9941 100644
--- a/xos/vsgw-onboard.yaml
+++ b/xos/vsgw-onboard.yaml
@@ -13,12 +13,12 @@
           base_url: file:///opt/xos_services/vsgw/xos/
           # The following will concatenate with base_url automatically, if
           # base_url is non-null.
-          models: models.py
+          xproto: ./
           admin: admin.py
           admin_template: templates/VSGWAdmin.html
           synchronizer: synchronizer/manifest
           synchronizer_run: vsgw-synchronizer.py
-          #tosca_custom_types: vsgw.yaml
+          tosca_custom_types: tosca/custom_types/vsgw.yaml
           tosca_resource: tosca/resources/vsgwtenant.py, tosca/resources/vsgwservice.py
           #rest_service: api/service/vsgwservice.py
           #rest_tenant: api/tenant/vsgwtenant.py
diff --git a/xos/vsgw.xproto b/xos/vsgw.xproto
new file mode 100644
index 0000000..23033fd
--- /dev/null
+++ b/xos/vsgw.xproto
@@ -0,0 +1,15 @@
+option name = "vsgw";
+option app_label = "vsgw";
+option verbose_name = "vSGW Service";
+option kind = "vEPC";
+
+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";
+     required string tenant_message = 1 [help_text = "Tenant Message to Display", max_length = 254, null = False, db_index = False, blank = False];
+}