remove file and delete service_message in synchronizer.

Change-Id: I58349df77e1ff4fb973e341f508cbad7f3eff0f9
diff --git a/xos/admin.py b/xos/admin.py
index 5ecf1b4..8dc98d9 100644
--- a/xos/admin.py
+++ b/xos/admin.py
@@ -14,7 +14,7 @@
         fields = '__all__'
 
     def __init__(self, *args, **kwargs):
-        super(VSgwServiceForm, self).__init__(*args, **kwargs)
+        super(VSGWServiceForm, self).__init__(*args, **kwargs)
 
         if self.instance:
             self.fields['service_message'].initial = self.instance.service_message
@@ -28,7 +28,7 @@
     model = VSGWService
     verbose_name = SERVICE_NAME_VERBOSE
     verbose_name_plural = SERVICE_NAME_VERBOSE_PLURAL
-    form = VSgwServiceForm
+    form = VSGWServiceForm
     inlines = [SliceInline]
 
     list_display = ('backend_status_icon', 'name', 'service_message', 'enabled')
@@ -68,7 +68,7 @@
     creator = forms.ModelChoiceField(queryset=User.objects.all())
 
     def __init__(self, *args, **kwargs):
-        super(ExampleTenantForm, self).__init__(*args, **kwargs)
+        super(VSGWTenantForm, self).__init__(*args, **kwargs)
 
         self.fields['kind'].widget.attrs['readonly'] = True
         self.fields['kind'].initial = SERVICE_NAME
@@ -112,4 +112,4 @@
     def get_queryset(self, request):
         return VSGWTenant.get_tenant_objects_by_user(request.user)
 
-admin.site.register(VSGWTenant, VSGWTenantAdmin)
\ No newline at end of file
+admin.site.register(VSGWTenant, VSGWTenantAdmin)
diff --git a/xos/models.py b/xos/models.py
index 39dfa7f..b06b72f 100644
--- a/xos/models.py
+++ b/xos/models.py
@@ -1,5 +1,10 @@
 # models.py -  vSGW Models
 
+from core.models import Service, TenantWithContainer
+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'
@@ -11,11 +16,10 @@
     KIND = SERVICE_NAME
 
     class Meta:
+        proxy = True
         app_label = SERVICE_NAME
         verbose_name = SERVICE_NAME_VERBOSE
 
-    service_message = models.CharField(max_length=254, help_text="Service Message to Display")
-
 class VSGWTenant(TenantWithContainer):
 
     KIND = SERVICE_NAME
@@ -29,21 +33,20 @@
         vsgw_service = VSGWService.get_service_objects().all()
         if vsgw_service:
             self._meta.get_field('provider_service').default = vsgw_service[0].id
-        super(ExampleTenant, self).__init__(*args, **kwargs)
+        super(VSGWTenant, self).__init__(*args, **kwargs)
 
     def save(self, *args, **kwargs):
         super(VSGWTenant, self).save(*args, **kwargs)
-        model_policy_exampletenant(self.pk)
+        model_policy_vsgwtenant(self.pk)
 
     def delete(self, *args, **kwargs):
         self.cleanup_container()
         super(VSGWTenant, self).delete(*args, **kwargs)
 
-
-def model_policy_exampletenant(pk):
+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()
\ No newline at end of file
+        tenant.manage_container()
diff --git a/xos/synchronizer/manifest b/xos/synchronizer/manifest
deleted file mode 100644
index ecf2f26..0000000
--- a/xos/synchronizer/manifest
+++ /dev/null
@@ -1,10 +0,0 @@
-manifest
-steps/sync_vsgwtenant.py
-steps/roles/install_apache/tasks/main.yml
-steps/roles/create_index/templates/index.html.j2
-steps/roles/create_index/tasks/main.yml
-steps/vsgwtenant_playbook.yaml
-vsgwservice-synchronizer.py
-model-deps
-run.sh
-vsgservice_config
diff --git a/xos/synchronizer/run.sh b/xos/synchronizer/run.sh
deleted file mode 100755
index da12ee3..0000000
--- a/xos/synchronizer/run.sh
+++ /dev/null
@@ -1,2 +0,0 @@
-export XOS_DIR=/opt/xos
-python vsgwservice-synchronizer.py  -C $XOS_DIR/synchronizers/vsgw/vsgwservice_config
diff --git a/xos/synchronizer/steps/exampletenant_playbook.yaml b/xos/synchronizer/steps/exampletenant_playbook.yaml
deleted file mode 100644
index 9ec8937..0000000
--- a/xos/synchronizer/steps/exampletenant_playbook.yaml
+++ /dev/null
@@ -1,16 +0,0 @@
----
-# vsgwtenant_playbook
-
-- hosts: "{{ instance_name }}"
-  connection: ssh
-  user: ubuntu
-  sudo: yes
-  gather_facts: no
-  vars:
-    - tenant_message: "{{ tenant_message }}"
-    - service_message: "{{ service_message }}"
-
-  roles:
-    - install_apache
-    - create_index
-
diff --git a/xos/synchronizer/steps/roles/create_index/tasks/main.yml b/xos/synchronizer/steps/roles/create_index/tasks/main.yml
deleted file mode 100644
index 91c6029..0000000
--- a/xos/synchronizer/steps/roles/create_index/tasks/main.yml
+++ /dev/null
@@ -1,7 +0,0 @@
----
-
-- name: Write index.html file to apache document root
-  template:
-    src=index.html.j2
-    dest=/var/www/html/index.html
-
diff --git a/xos/synchronizer/steps/roles/create_index/templates/index.html.j2 b/xos/synchronizer/steps/roles/create_index/templates/index.html.j2
deleted file mode 100644
index 9c3e8fc..0000000
--- a/xos/synchronizer/steps/roles/create_index/templates/index.html.j2
+++ /dev/null
@@ -1,4 +0,0 @@
-VSGWService
- Service Message: "{{ service_message }}"
- Tenant Message: "{{ tenant_message }}"
-
diff --git a/xos/synchronizer/steps/roles/install_apache/tasks/main.yml b/xos/synchronizer/steps/roles/install_apache/tasks/main.yml
deleted file mode 100644
index d9a155c..0000000
--- a/xos/synchronizer/steps/roles/install_apache/tasks/main.yml
+++ /dev/null
@@ -1,7 +0,0 @@
----
-
-- name: Install apache using apt
-  apt:
-    name=apache2
-    update_cache=yes
-
diff --git a/xos/synchronizer/steps/sync_vsgw.py b/xos/synchronizer/steps/sync_vsgw.py
new file mode 100644
index 0000000..ddc06e9
--- /dev/null
+++ b/xos/synchronizer/steps/sync_vsgw.py
@@ -0,0 +1,40 @@
+import os
+import sys
+from django.db.models import Q, F
+from services.vsgw.models import VSGWService, VSGWTenant
+from synchronizers.base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
+
+parentdir = os.path.join(os.path.dirname(__file__), "..")
+sys.path.insert(0, parentdir)
+
+class SyncVSGWTenant(SyncInstanceUsingAnsible):
+
+    provides = [VSGWTenant]
+
+    observes = VSGWTenant
+
+    requested_interval = 0
+
+    template_name = "sync_vsgw.yaml"
+
+    service_key_name = "/opt/xos/synchronizers/vsgw/vsgw_private_key"
+
+    def __init__(self, *args, **kwargs):
+        super(SyncVSGWTenant, self).__init__(*args, **kwargs)
+
+    def fetch_pending(self, deleted):
+
+        if (not deleted):
+            objs = VSGWTenant.get_tenant_objects().filter(
+                Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False))
+        else:
+            # If this is a deletion we get all of the deleted tenants..
+            objs = VSGWTenant.get_deleted_tenant_objects()
+
+        return objs
+
+    def get_extra_attributes(self, o):
+        fields = {}
+        fields['tenant_message'] = o.tenant_message
+        return fields
+
diff --git a/xos/synchronizer/steps/sync_vsgw.yaml b/xos/synchronizer/steps/sync_vsgw.yaml
new file mode 100644
index 0000000..8cd59b7
--- /dev/null
+++ b/xos/synchronizer/steps/sync_vsgw.yaml
@@ -0,0 +1,27 @@
+---
+- hosts: {{ instance_name }}
+  connection: ssh
+  user: ubuntu
+  sudo: yes
+  gather_facts: no
+  tasks:
+
+  vars:
+    - tenant_message: "{{ tenant_message }}"
+  
+#  - name: Write message
+#    shell: echo "{{ tenant_message }}" > /var/tmp/index.html
+#
+#  - name: setup s1u interface config
+#    shell: ./start_3gpp_int.sh eth1 {{ s1u_sgw_tag }} {{ s1u_sgw_ip }}/24
+#
+#  - name: setup s11 interface config
+#    shell: ./start_3gpp_int.sh eth2 {{ s11_sgw_tag }} {{ s11_sgw_ip }}/24
+#
+#  - name: setup s5s8 interface config
+#    shell: ./start_3gpp_int.sh eth3 {{ s5s8_sgw_tag }} {{ s5s8_sgw_ip }}/24
+  
+#  roles:
+#    - install_apache
+#    - create_index
+
diff --git a/xos/synchronizer/steps/sync_vsgwtenant.py b/xos/synchronizer/steps/sync_vsgwtenant.py
deleted file mode 100644
index 38f9969..0000000
--- a/xos/synchronizer/steps/sync_vsgwtenant.py
+++ /dev/null
@@ -1,55 +0,0 @@
-import os
-import sys
-from django.db.models import Q, F
-from services.vsgwservice.models import VSGWService, VSGWTenant
-from synchronizers.base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
-
-parentdir = os.path.join(os.path.dirname(__file__), "..")
-sys.path.insert(0, parentdir)
-
-class SyncVSGWTenant(SyncInstanceUsingAnsible):
-
-    provides = [VSGWTenant]
-
-    observes = VSGWTenant
-
-    requested_interval = 0
-
-    template_name = "vsgwtenant_playbook.yaml"
-
-    service_key_name = "/opt/xos/synchronizers/vsgwservice/vsgwservice_private_key"
-
-    def __init__(self, *args, **kwargs):
-        super(SyncVSGWTenant, self).__init__(*args, **kwargs)
-
-    def fetch_pending(self, deleted):
-
-        if (not deleted):
-            objs = VSGWTenant.get_tenant_objects().filter(
-                Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False))
-        else:
-            # If this is a deletion we get all of the deleted tenants..
-            objs = VSGWTenant.get_deleted_tenant_objects()
-
-        return objs
-
-    def get_exampleservice(self, o):
-        if not o.provider_service:
-            return None
-
-        vsgwservice = VSGWService.get_service_objects().filter(id=o.provider_service.id)
-
-        if not vsgwservice:
-            return None
-
-        return vsgwservice[0]
-
-    # Gets the attributes that are used by the Ansible template but are not
-    # part of the set of default attributes.
-    def get_extra_attributes(self, o):
-        fields = {}
-        fields['tenant_message'] = o.tenant_message
-        vsgwservice = self.get_vsgwservice(o)
-        fields['service_message'] = vsgwservice.service_message
-        return fields
-
diff --git a/xos/synchronizer/vsgwservice-synchronizer.py b/xos/synchronizer/vsgw-synchronizer.py
similarity index 100%
rename from xos/synchronizer/vsgwservice-synchronizer.py
rename to xos/synchronizer/vsgw-synchronizer.py
diff --git a/xos/synchronizer/vsgw_config b/xos/synchronizer/vsgw_config
new file mode 100644
index 0000000..58eaf9a
--- /dev/null
+++ b/xos/synchronizer/vsgw_config
@@ -0,0 +1,28 @@
+# Required by XOS
+[db]
+name=xos
+user=postgres
+password=password
+host=localhost
+port=5432
+
+# Required by XOS
+[api]
+nova_enabled=True
+
+# Sets options for the synchronizer
+[observer]
+name=vsgw
+dependency_graph=/opt/xos/synchronizers/vsgw/model-deps
+steps_dir=/opt/xos/synchronizers/vsgw/steps
+sys_dir=/opt/xos/synchronizers/vsgw/sys
+logfile=/var/log/xos_backend.log
+pretend=False
+backoff_disabled=True
+save_ansible_output=True
+proxy_ssh=True
+proxy_ssh_key=/root/setup/id_rsa
+proxy_ssh_user=root
+enable_watchers=True
+[networking]
+use_vtn=True
diff --git a/xos/synchronizer/vsgwservice_config b/xos/synchronizer/vsgwservice_config
deleted file mode 100644
index 47c9354..0000000
--- a/xos/synchronizer/vsgwservice_config
+++ /dev/null
@@ -1,24 +0,0 @@
-# Required by XOS
-[db]
-name=xos
-user=postgres
-password=password
-host=localhost
-port=5432
-
-# Required by XOS
-[api]
-nova_enabled=True
-
-# Sets options for the synchronizer
-[observer]
-name=vsgwservice
-dependency_graph=/opt/xos/synchronizers/vsgwservice/model-deps
-steps_dir=/opt/xos/synchronizers/vsgwservice/steps
-sys_dir=/opt/xos/synchronizers/vsgwservice/sys
-logfile=/var/log/xos_backend.log
-pretend=False
-backoff_disabled=True
-save_ansible_output=True
-proxy_ssh=False
-
diff --git a/xos/templates/VSGWAdmin.html b/xos/templates/VSGWAdmin.html
new file mode 100644
index 0000000..7a41370
--- /dev/null
+++ b/xos/templates/VSGWAdmin.html
@@ -0,0 +1,10 @@
+<!-- Template used to for the button leading to the HelloWorldTenantComplete form. -->
+<div class = "left-nav">
+  <ul>
+    <li>
+      <a href="/admin/mcordservice/vsgwcomponent/">
+        vSGW Service Components
+      </a>
+    </li>
+  </ul>
+</div>
diff --git a/xos/tosca/resources/vsgwservice.py b/xos/tosca/resources/vsgwservice.py
index 6289ffd..02c9037 100644
--- a/xos/tosca/resources/vsgwservice.py
+++ b/xos/tosca/resources/vsgwservice.py
@@ -1,15 +1,6 @@
-import os
-import pdb
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-import pdb
-
-from core.models import Service,User,CoarseTenant
-from services.vsgwservice.models import VSGWService
-
+from services.vsgw.models import VSGWService
 from xosresource import XOSResource
+from service import XOSService
 
 class XOSVSGWService(XOSResource):
     provides = "tosca.nodes.VSGWService"
diff --git a/xos/tosca/resources/vsgwtenant.py b/xos/tosca/resources/vsgwtenant.py
index 29ea5f6..ecf6051 100644
--- a/xos/tosca/resources/vsgwtenant.py
+++ b/xos/tosca/resources/vsgwtenant.py
@@ -1,17 +1,8 @@
-import importlib
-import os
-import pdb
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-from core.models import Tenant, Service
-from services.vsgwservice.models import *
-
+from services.vsgw.models import *
 from xosresource import XOSResource
 
 class XOSVSGWTenant(XOSResource):
-    provides = "tosca.nodes.ExampleTenant"
+    provides = "tosca.nodes.VSGWTenant"
     xos_model = VSGWTenant
     name_field = "service_specific_id"
     copyin_props = ("tenant_message",)
@@ -20,9 +11,9 @@
         args = super(XOSVSGWTenant, self).get_xos_args()
 
         # ExampleTenant must always have a provider_service
-        provider_name = self.get_requirement("tosca.relationships.TenantOfService", throw_exception=True)
+        provider_name = self.get_requirement("tosca.relationships.MemberOfService", throw_exception=throw_exception)
         if provider_name:
-            args["provider_service"] = self.get_xos_object(Service, throw_exception=True, name=provider_name)
+            args["provider_service"] = self.get_xos_object(VSGWService, throw_exception=throw_exception, name=provider_name)
 
         return args
 
diff --git a/xos/vSGW-onboard.yaml b/xos/vSGW-onboard.yaml
index de66ae8..01d8786 100644
--- a/xos/vSGW-onboard.yaml
+++ b/xos/vSGW-onboard.yaml
@@ -7,7 +7,7 @@
 
 topology_template:
   node_templates:
-    VSGWservice:
+    servicecontroller#vsgw:
       type: tosca.nodes.ServiceController
       properties:
           base_url: file:///opt/xos_services/vSGW/xos/
@@ -15,12 +15,13 @@
           # base_url is non-null.
           models: models.py
           admin: admin.py
+          admin_template: templates/VSGWAdmin.html
           synchronizer: synchronizer/manifest
           synchronizer_run: vsgw-synchronizer.py
-          tosca_custom_types: vsgw.yaml
-          tosca_resource: tosca/resources/vsgwservice.py, tosca/resources/vsgwtenant.py
-          rest_service: api/service/vsgwservice.py
-          rest_tenant: api/tenant/vsgwtenant.py
-          private_key: file:///opt/xos/key_import/vsgw_rsa
-          public_key: file:///opt/xos/key_import/vsgw_rsa.pub
+          #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
+          private_key: file:///opt/xos/key_import/vSGW_rsa
+          public_key: file:///opt/xos/key_import/vSGW_rsa.pub
 
diff --git a/xos/vsgwservice.yaml b/xos/vsgw.yaml
similarity index 98%
rename from xos/vsgwservice.yaml
rename to xos/vsgw.yaml
index e8223fc..f6ad712 100644
--- a/xos/vsgwservice.yaml
+++ b/xos/vsgw.yaml
@@ -11,15 +11,11 @@
 
 # Subscriber
 
-
-
-
-
 node_types:
     tosca.nodes.VSGWService:
         derived_from: tosca.nodes.Root
         description: >
-            Example Service
+            vSGW Service
         capabilities:
             scalable:
                 type: tosca.capabilities.Scalable