refactor vSGW cord-3.0

Change-Id: I72a19da1803d8e9dd9d7c9e848011aa28ef4d619
diff --git a/xos/admin.py b/xos/admin.py
deleted file mode 100644
index e3434ce..0000000
--- a/xos/admin.py
+++ /dev/null
@@ -1,118 +0,0 @@
-# admin.py - VSGW Django Admin
-
-from core.admin import ReadOnlyAwareAdmin, SliceInline
-from core.middleware import get_request
-from core.models import User
-from django import forms
-from django.contrib import admin
-# from services.vsgw.models import *
-from synchronizers.new_base.modelaccessor import *
-
-class VSGWServiceForm(forms.ModelForm):
-
-    class Meta:
-        model = VSGWService
-        fields = '__all__'
-
-    def __init__(self, *args, **kwargs):
-        super(VSGWServiceForm, self).__init__(*args, **kwargs)
-
-        if self.instance:
-            self.fields['service_message'].initial = self.instance.service_message
-
-    def save(self, commit=True):
-        self.instance.service_message = self.cleaned_data.get('service_message')
-        return super(VSGWServiceForm, self).save(commit=commit)
-
-class VSGWServiceAdmin(ReadOnlyAwareAdmin):
-
-    model = VSGWService
-    verbose_name = "VSGW Service"
-    verbose_name_plural = "VSGW Service"
-    form = VSGWServiceForm
-    inlines = [SliceInline]
-
-    list_display = ('backend_status_icon', 'name', 'service_message', 'enabled')
-    list_display_links = ('backend_status_icon', 'name', 'service_message' )
-
-    fieldsets = [(None, {
-        'fields': ['backend_status_text', 'name', 'enabled', 'versionNumber', 'service_message', 'description',],
-        'classes':['suit-tab suit-tab-general',],
-        })]
-
-    readonly_fields = ('backend_status_text', )
-    user_readonly_fields = ['name', 'enabled', 'versionNumber', 'description',]
-
-    extracontext_registered_admins = True
-
-    suit_form_tabs = (
-        ('general', 'Example Service Details', ),
-        ('slices', 'Slices',),
-        )
-
-    suit_form_includes = ((
-        'top',
-        'administration'),
-        )
-
-    def get_queryset(self, request):
-        return ExampleService.get_service_objects_by_user(request.user)
-
-admin.site.register(VSGWService, VSGWServiceAdmin)
-
-class VSGWTenantForm(forms.ModelForm):
-
-    class Meta:
-        model = VSGWTenant
-        fields = '__all__'
-
-    creator = forms.ModelChoiceField(queryset=User.objects.all())
-
-    def __init__(self, *args, **kwargs):
-        super(VSGWTenantForm, self).__init__(*args, **kwargs)
-
-        self.fields['kind'].widget.attrs['readonly'] = True
-        self.fields['kind'].initial = SERVICE_NAME
-
-        self.fields['provider_service'].queryset = VSGWService.get_service_objects().all()
-
-        if self.instance:
-            self.fields['creator'].initial = self.instance.creator
-            self.fields['tenant_message'].initial = self.instance.tenant_message
-            self.fields['image_name'].initial = self.instance.image_name
-
-        if (not self.instance) or (not self.instance.pk):
-            self.fields['creator'].initial = get_request().user
-            if VSGWService.get_service_objects().exists():
-                self.fields['provider_service'].initial = VSGWService.get_service_objects().all()[0]
-
-    def save(self, commit=True):
-        self.instance.creator = self.cleaned_data.get('creator')
-        self.instance.tenant_message = self.cleaned_data.get('tenant_message')
-        self.instance.image_name = self.cleaned_data.get('image_name')
-        return super(VSGWTenantForm, self).save(commit=commit)
-
-
-class VSGWTenantAdmin(ReadOnlyAwareAdmin):
-
-    verbose_name = "VSGW Component"
-    verbose_name_plural = "VSGW Component"
-
-    list_display = ('id', 'backend_status_icon', 'instance', 'tenant_message', 'image_name')
-    list_display_links = ('backend_status_icon', 'instance', 'tenant_message', 'id', 'image_name')
-
-    fieldsets = [(None, {
-        'fields': ['backend_status_text', 'kind', 'provider_service', 'instance', 'creator', 'tenant_message', 'image_name'],
-        'classes': ['suit-tab suit-tab-general'],
-        })]
-
-    readonly_fields = ('backend_status_text', 'instance',)
-
-    form = VSGWTenantForm
-
-    suit_form_tabs = (('general', 'Details'),)
-
-    def get_queryset(self, request):
-        return VSGWTenant.get_tenant_objects_by_user(request.user)
-
-admin.site.register(VSGWTenant, VSGWTenantAdmin)
diff --git a/xos/header.py b/xos/header.py
deleted file mode 100644
index 3e067b7..0000000
--- a/xos/header.py
+++ /dev/null
@@ -1,16 +0,0 @@
-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
-
diff --git a/xos/models.py b/xos/models.py
index c465d96..ffa3407 100644
--- a/xos/models.py
+++ b/xos/models.py
@@ -2,6 +2,22 @@
 from models_decl import VSGWService_decl
 from models_decl import VSGWTenant_decl
 
+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
+
 class VSGWService(VSGWService_decl):
    class Meta:
         proxy = True 
diff --git a/xos/synchronizer/run.sh b/xos/synchronizer/run.sh
deleted file mode 100644
index 9d64fa9..0000000
--- a/xos/synchronizer/run.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-# Runs the XOS observer using vsgw_config
-export XOS_DIR=/opt/xos
-python vsgw-synchronizer.py  -C $XOS_DIR/synchronizers/vsgw/vsgw_config
diff --git a/xos/synchronizer/steps/sync_vsgw.yaml b/xos/synchronizer/steps/sync_vsgw.yaml
deleted file mode 100644
index 997e0cb..0000000
--- a/xos/synchronizer/steps/sync_vsgw.yaml
+++ /dev/null
@@ -1,27 +0,0 @@
----
-- hosts: {{ instance_name }}
-  connection: ssh
-  user: ubuntu
-  become: 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_vsgw.py b/xos/synchronizer/steps/sync_vsgwtenant.py
similarity index 82%
rename from xos/synchronizer/steps/sync_vsgw.py
rename to xos/synchronizer/steps/sync_vsgwtenant.py
index 552bdc1..4d7e3b4 100644
--- a/xos/synchronizer/steps/sync_vsgw.py
+++ b/xos/synchronizer/steps/sync_vsgwtenant.py
@@ -1,7 +1,6 @@
 import os
 import sys
 from django.db.models import Q, F
-# from services.vsgw.models import VSGWService, VSGWTenant
 from synchronizers.new_base.modelaccessor import *
 from synchronizers.new_base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
 
@@ -16,9 +15,9 @@
 
     requested_interval = 0
 
-    template_name = "sync_vsgw.yaml"
+    template_name = "vsgwtenant_playbook.yaml"
 
-    service_key_name = "/opt/xos/synchronizers/vsgw/vsgw_private_key"
+    service_key_name = "/opt/xos/configurations/mcord/mcord_private_key"
 
     def __init__(self, *args, **kwargs):
         super(SyncVSGWTenant, self).__init__(*args, **kwargs)
@@ -37,6 +36,5 @@
     def get_extra_attributes(self, o):
         fields = {}
         fields['tenant_message'] = o.tenant_message
-        fields['image_name'] = o.image_name
         return fields
 
diff --git a/xos/synchronizer/steps/vsgwtenant_playbook.yaml b/xos/synchronizer/steps/vsgwtenant_playbook.yaml
new file mode 100644
index 0000000..ede8674
--- /dev/null
+++ b/xos/synchronizer/steps/vsgwtenant_playbook.yaml
@@ -0,0 +1,11 @@
+---
+- hosts: {{ instance_name }}
+  connection: ssh
+  user: ubuntu
+  become: yes
+  gather_facts: no
+  tasks:
+
+  vars:
+    - tenant_message: "{{ tenant_message }}"
+  
diff --git a/xos/synchronizer/vsgw-synchronizer.py b/xos/synchronizer/vsgw-synchronizer.py
old mode 100644
new mode 100755
diff --git a/xos/synchronizer/vsgw_config b/xos/synchronizer/vsgw_config
deleted file mode 100644
index 02d3fb0..0000000
--- a/xos/synchronizer/vsgw_config
+++ /dev/null
@@ -1,28 +0,0 @@
-# Required by XOS
-[db]
-name=xos
-user=postgres
-password=password
-host=xos_db
-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/templates/VSGWAdmin.html b/xos/templates/VSGWAdmin.html
deleted file mode 100644
index 7a41370..0000000
--- a/xos/templates/VSGWAdmin.html
+++ /dev/null
@@ -1,10 +0,0 @@
-<!-- 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/custom_types/vsgw.m4 b/xos/tosca/custom_types/vsgw.m4
index 1ff75dd..45c35e4 100644
--- a/xos/tosca/custom_types/vsgw.m4
+++ b/xos/tosca/custom_types/vsgw.m4
@@ -15,9 +15,6 @@
         properties:
             xos_base_props
             xos_base_service_props
-            service_message:
-                type: string
-                required: false
 
     tosca.nodes.VSGWTenant:
         derived_from: tosca.nodes.Root
diff --git a/xos/tosca/custom_types/vsgw.yaml b/xos/tosca/custom_types/vsgw.yaml
index 5d6cb16..c4da998 100644
--- a/xos/tosca/custom_types/vsgw.yaml
+++ b/xos/tosca/custom_types/vsgw.yaml
@@ -78,9 +78,6 @@
                 type: string
                 required: false
                 description: Version number of Service.
-            service_message:
-                type: string
-                required: false
 
     tosca.nodes.VSGWTenant:
         derived_from: tosca.nodes.Root
diff --git a/xos/tosca/resources/vsgwservice.py b/xos/tosca/resources/vsgwservice.py
index c3a9414..3826425 100644
--- a/xos/tosca/resources/vsgwservice.py
+++ b/xos/tosca/resources/vsgwservice.py
@@ -1,30 +1,9 @@
 # from services.vsgw.models import VSGWService
-from xosresource import XOSResource
-from synchronizers.new_base.modelaccessor import *
 from service import XOSService
+from services.vsgw.models import VSGWService
 
-class XOSVSGWService(XOSResource):
+class XOSVSGWService(XOSService):
     provides = "tosca.nodes.VSGWService"
     xos_model = VSGWService
-    copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "private_key_fn", "versionNumber", "service_message"]
-
-    def postprocess(self, obj):
-        for provider_service_name in self.get_requirements("tosca.relationships.TenantOfService"):
-            provider_service = self.get_xos_object(VSGWService, name=provider_service_name)
-
-            existing_tenancy = CoarseTenant.get_tenant_objects().filter(provider_service = provider_service, subscriber_service = obj)
-            if existing_tenancy:
-                self.info("Tenancy relationship from %s to %s already exists" % (str(obj), str(provider_service)))
-            else:
-                tenancy = CoarseTenant(provider_service = provider_service,
-                                       subscriber_service = obj)
-                tenancy.save()
-
-                self.info("Created Tenancy relationship  from %s to %s" % (str(obj), str(provider_service)))
-
-    def can_delete(self, obj):
-        if obj.slices.exists():
-            self.info("Service %s has active slices; skipping delete" % obj.name)
-            return False
-        return super(XOSVSGWService, self).can_delete(obj)
+    copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "private_key_fn", "versionNumber"]
 
diff --git a/xos/tosca/resources/vsgwtenant.py b/xos/tosca/resources/vsgwtenant.py
index 48984fe..5f6c3bb 100644
--- a/xos/tosca/resources/vsgwtenant.py
+++ b/xos/tosca/resources/vsgwtenant.py
@@ -1,20 +1,20 @@
-# from services.vsgw.models import *
-from synchronizers.new_base.modelaccessor import *
 from xosresource import XOSResource
+from core.models import Service, Tenant
+from services.vsgw.models import VSGWTenant
 
 class XOSVSGWTenant(XOSResource):
     provides = "tosca.nodes.VSGWTenant"
     xos_model = VSGWTenant
     name_field = "service_specific_id"
-    copyin_props = ("tenant_message", "image_name")
+    copyin_props = ("tenant_message",)
 
     def get_xos_args(self, throw_exception=True):
         args = super(XOSVSGWTenant, self).get_xos_args()
 
         # ExampleTenant must always have a provider_service
-        provider_name = self.get_requirement("tosca.relationships.MemberOfService", throw_exception=throw_exception)
+        provider_name = self.get_requirement("tosca.relationships.TenantOfService", throw_exception=throw_exception)
         if provider_name:
-            args["provider_service"] = self.get_xos_object(VSGWService, throw_exception=throw_exception, name=provider_name)
+            args["provider_service"] = self.get_xos_object(Service, throw_exception=throw_exception, name=provider_name)
 
         return args
 
diff --git a/xos/vsgw-onboard.yaml b/xos/vsgw-onboard.yaml
index b9f9941..549a6fc 100644
--- a/xos/vsgw-onboard.yaml
+++ b/xos/vsgw-onboard.yaml
@@ -14,14 +14,10 @@
           # The following will concatenate with base_url automatically, if
           # base_url is non-null.
           xproto: ./
-          admin: admin.py
-          admin_template: templates/VSGWAdmin.html
           synchronizer: synchronizer/manifest
           synchronizer_run: vsgw-synchronizer.py
           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
           private_key: file:///opt/xos/key_import/mcord_rsa
           public_key: file:///opt/xos/key_import/mcord_rsa.pub
 
diff --git a/xos/vsgw.xproto b/xos/vsgw.xproto
index 6b6b1c7..cefcc3a 100644
--- a/xos/vsgw.xproto
+++ b/xos/vsgw.xproto
@@ -1,15 +1,16 @@
-option name = "vsgw";
+option name = "vSGW";
+option verbose_name = "Virtual Serving Gateway";
 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];
+    option name = "VSGWService";
+    option verbose_name = "Virtual Serving Gateway Service";
 }
 
 message VSGWTenant (TenantWithContainer){
-     option name = "vsgwtenant";
-     option verbose_name = "VSGW Tenant";
+     option name = "VSGWTenant";
+     option verbose_name = "Virtual Serving Gateway Tenant";
      required string tenant_message = 1 [help_text = "Tenant Message to Display", max_length = 254, null = False, db_index = False, blank = False];
 }