add missed functions of PGW service

Change-Id: Ib89ba5f369736d9a939fb7b8028916ac186a4ef9
diff --git a/xos/admin.py b/xos/admin.py
index 55d6a56..9055b3b 100644
--- a/xos/admin.py
+++ b/xos/admin.py
@@ -4,7 +4,19 @@
 from core.models import User
 from django import forms
 from django.contrib import admin
-from services.vpgwc.models import VPGWCService, VPGWCComponent, MCORD_KIND
+from services.vpgwc.models import VPGWCService, VPGWCTenant, MCORD_KIND
+
+class VPGWCServiceForm(forms.ModelForm):
+
+    class Meta:
+        model = VPGWCService
+        fields = '__all__'
+
+    def __init__(self, *args, **kwargs):
+        super(VPGWCServiceForm, self).__init__(*args, **kwargs)
+
+    def save(self, commit=True):
+        return super(VPGWCServiceForm, self).save(commit=commit)
 
 # The class to provide an admin interface on the web for the service.
 # We do only configuration here and don't change any logic because the logic
@@ -14,6 +26,10 @@
     model = VPGWCService
     verbose_name = "vPGWC Service"
     verbose_name_plural = "vPGWC Services"
+    # Inlines are used to denote other models that can be edited on the same
+    # form as this one. In this case the service form also allows changes
+    # to slices.
+    inlines = [SliceInline]
 
     # Setting list_display creates columns on the admin page, each value here
     # is a column, the column is populated for every instance of the model.
@@ -38,11 +54,6 @@
     # Denotes the fields that are readonly and cannot be changed.
     readonly_fields = ('backend_status_text', )
 
-    # Inlines are used to denote other models that can be edited on the same
-    # form as this one. In this case the service form also allows changes
-    # to slices.
-    inlines = [SliceInline]
-
     extracontext_registered_admins = True
 
     # Denotes the fields that can be changed by an admin but not be all users
@@ -72,7 +83,11 @@
 # service because tenants vary more than services and there isn't a common form.
 # This allows us to change the python behavior for the admin form to save extra
 # fields and control defaults.
-class VPGWCComponentForm(forms.ModelForm):
+class VPGWCTenantForm(forms.ModelForm):
+
+    class Meta:
+        model = VPGWCTenant
+        fields = '__all__'
     # Defines a field for the creator of this service. It is a dropdown which
     # is populated with all of the users.
     creator = forms.ModelChoiceField(queryset=User.objects.all())
@@ -80,9 +95,10 @@
     display_message = forms.CharField(required=False)
 
     def __init__(self, *args, **kwargs):
-        super(VPGWCComponentForm, self).__init__(*args, **kwargs)
+        super(VPGWCTenantForm, self).__init__(*args, **kwargs)
         # Set the kind field to readonly
         self.fields['kind'].widget.attrs['readonly'] = True
+        self.fields['kind'].initial = "vpgwc"
         # Define the logic for obtaining the objects for the provider_service
         # dropdown of the tenant form.
         self.fields[
@@ -101,7 +117,6 @@
             self.fields['creator'].initial = get_request().user
             if VPGWCService.get_service_objects().exists():
                 self.fields["provider_service"].initial = VPGWCService.get_service_objects().all()[0]
-
     # This function describes what happens when the save button is pressed on
     # the tenant form. In this case we set the values for the instance that were
     # entered.
@@ -109,33 +124,30 @@
         self.instance.creator = self.cleaned_data.get("creator")
         self.instance.display_message = self.cleaned_data.get(
             "display_message")
-        return super(VPGWCComponentForm, self).save(commit=commit)
-
-    class Meta:
-        model = VPGWCComponent
-        fields = '__all__'
+        return super(VPGWCTenantForm, self).save(commit=commit)
 
 
 # Define the admin form for the tenant. This uses a similar structure as the
 # service but uses HelloWorldTenantCompleteForm to change the python behavior.
-class VPGWCComponentAdmin(ReadOnlyAwareAdmin):
-    verbose_name = "vPGWC Component"
-    verbose_name_plural = "vPGWC Components"
+class VPGWCTenantAdmin(ReadOnlyAwareAdmin):
+    verbose_name = "vPGWC Service Tenant"
+    verbose_name_plural = "vPGWC Service Tenants"
+    form = VPGWCTenantForm
+
     list_display = ('id', 'backend_status_icon', 'instance', 'display_message')
-    list_display_links = ('backend_status_icon', 'instance', 'display_message',
-                          'id')
+    list_display_links = ('backend_status_icon', 'instance', 'display_message', 'id')
     fieldsets = [(None, {'fields': ['backend_status_text', 'kind',
                                     'provider_service', 'instance', 'creator',
                                     'display_message'],
                          'classes': ['suit-tab suit-tab-general']})]
     readonly_fields = ('backend_status_text', 'instance',)
-    form = VPGWCComponentForm
+
 
     suit_form_tabs = (('general', 'Details'),)
 
     def queryset(self, request):
-        return VPGWCComponent.get_tenant_objects_by_user(request.user)
+        return VPGWCTenant.get_tenant_objects_by_user(request.user)
 
 # Associate the admin forms with the models.
 admin.site.register(VPGWCService, VPGWCServiceAdmin)
-admin.site.register(VPGWCComponent, VPGWCComponentAdmin)
+admin.site.register(VPGWCTenant, VPGWCTenantAdmin)
diff --git a/xos/models.py b/xos/models.py
index 102e3e3..9b4aa0f 100644
--- a/xos/models.py
+++ b/xos/models.py
@@ -1,4 +1,3 @@
-from django.db import models
 from core.models import Service, PlCoreBase, Slice, Instance, Tenant, TenantWithContainer, Node, Image, User, Flavor, Subscriber, NetworkParameter, NetworkParameterType, AddressPool, Port
 from core.models.plcorebase import StrippedCharField
 import os
@@ -14,11 +13,13 @@
 from sets import Set
 from xos.config import Config
 
-MCORD_KIND = "RAN" # This should be changed later I did it fo demo
+MCORD_KIND = "EPC"
+SERVICE_NAME_VERBOSE = 'VPGWC Service'
+SERVICE_NAME_VERBOSE_PLURAL = 'VPGWC Services'
+TENANT_NAME_VERBOSE = 'VPGWC Service Tenant'
+TENANT_NAME_VERBOSE_PLURAL = 'VPGWC Service Tenants'
+
 MCORD_USE_VTN = getattr(Config(), "networking_use_vtn", False)
-VBBU_KIND = "RAN"
-VSGW_KIND = "vSGW"
-VPGWC_KIND = "RAN"
 vbbu_net_types = ("s1u", "s1mme", "rru")
 vpgwc_net_types = ("s5s8")
 # The class to represent the service. Most of the service logic is given for us
@@ -40,18 +41,18 @@
 # This is the class to represent the tenant. Most of the logic is given to use
 # in TenantWithContainer, however there is some configuration and logic that
 # we need to define for this example.
-class VPGWCComponent(TenantWithContainer):
+class VPGWCTenant(TenantWithContainer):
 
+
+    # The kind of the service is used on forms to differentiate this service
+    # from the other services.
+    KIND = MCORD_KIND
     class Meta:
         # Same as a above, HelloWorldTenantComplete is represented as a
         # TenantWithContainer, but we change the python behavior.
         proxy = True
         verbose_name = "VPGWC Service Component"
 
-    # The kind of the service is used on forms to differentiate this service
-    # from the other services.
-    KIND = VPGWC_KIND
-
     # Ansible requires that the sync_attributes field contain nat_ip and nat_mac
     # these will be used to determine where to SSH to for ansible.
     # Getters must be defined for every attribute specified here.
@@ -61,19 +62,20 @@
     # the fields are.
     default_attributes = {"display_message": "New vPGWC Component", "s5s8_pgw_tag": "300"}
     def __init__(self, *args, **kwargs):
-        mcord_services = VPGWCService.get_service_objects().all()
+        pgwc_services = VPGWCService.get_service_objects().all()
         # When the tenant is created the default service in the form is set
         # to be the first created HelloWorldServiceComplete
-        if mcord_services:
+        if pgwc_services:
             self._meta.get_field(
-                "provider_service").default = mcord_services[0].id
-        super(VPGWCComponent, self).__init__(*args, **kwargs)
+                "provider_service").default = pgwc_services[0].id
+        super(VPGWCTenant, self).__init__(*args, **kwargs)
 
     def can_update(self, user):
         #Allow creation of this model instances for non-admin users also
         return True
 
     def save(self, *args, **kwargs):
+        '''
         if not self.creator:
             if not getattr(self, "caller", None):
                 # caller must be set when creating a monitoring channel since it creates a slice
@@ -81,15 +83,15 @@
             self.creator = self.caller
             if not self.creator:
                 raise XOSProgrammingError("ServiceComponents's self.creator was not set")
-
-        super(VPGWCComponent, self).save(*args, **kwargs)
+        '''
+        super(VPGWCTenant, 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_mcord_servicecomponent(self.pk)
 
     def save_instance(self, instance):
         with transaction.atomic():
-            super(VPGWCComponent, self).save_instance(instance)
+            super(VPGWCTenant, self).save_instance(instance)
             if instance.isolation in ["vm"]:
                 for ntype in vpgwc_net_types:
                     lan_network = self.get_lan_network(instance, ntype)
@@ -104,7 +106,7 @@
     def delete(self, *args, **kwargs):
         # Delete the instance that was created for this tenant
         self.cleanup_container()
-        super(VPGWCComponent, self).delete(*args, **kwargs)
+        super(VPGWCTenant, self).delete(*args, **kwargs)
 
     def find_or_make_port(self, instance, network, **kwargs):
         port = Port.objects.filter(instance=instance, network=network)
@@ -121,7 +123,7 @@
         slice = self.provider_service.slices.all()[0]
         lan_networks = [x for x in slice.networks.all() if ntype in x.name]
         if not lan_networks:
-            raise XOSProgrammingError("No lan_network")
+            #raise XOSProgrammingError("No lan_network")
         return lan_networks[0]
 
     def manage_container(self):
@@ -134,11 +136,11 @@
         # provides us
         slice = self.get_slice()
         if slice.default_isolation in ["container_vm", "container"]:
-            super(VPGWCComponent,self).manage_container()
+            super(VPGWCTenant,self).manage_container()
             return
 
         if not self.s5s8_pgw_tag:
-            raise XOSConfigurationError("S5S8_PGW_TAG is missed")
+           # raise XOSConfigurationError("S5S8_PGW_TAG is missed")
 
         if self.instance:
             # We're good.
@@ -229,9 +231,9 @@
     # This section of code is atomic to prevent race conditions
     with transaction.atomic():
         # We find all of the tenants that are waiting to update
-        component = VPGWCComponent.objects.select_for_update().filter(pk=pk)
-        if not component:
+        tenant = VPGWCTenant.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
-        component = component[0]
-        component.manage_container()
+        tenant = tenant[0]
+        tenant.manage_container()
diff --git a/xos/synchronizer/steps/sync_vpgwc.py b/xos/synchronizer/steps/sync_vpgwc.py
index 70056b3..bbfc0a8 100644
--- a/xos/synchronizer/steps/sync_vpgwc.py
+++ b/xos/synchronizer/steps/sync_vpgwc.py
@@ -1,17 +1,17 @@
 import os
 import sys
 from django.db.models import Q, F
-from services.vpgwc.models import VPGWCService, VPGWCComponent
+from services.vpgwc.models import VPGWCService, VPGWCTenant
 from synchronizers.base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
 
 parentdir = os.path.join(os.path.dirname(__file__), "..")
 sys.path.insert(0, parentdir)
 
-class SyncVPGWCComponent(SyncInstanceUsingAnsible):
+class SyncVPGWCTenant(SyncInstanceUsingAnsible):
 
-    provides = [VPGWCComponent]
+    provides = [VPGWCTenant]
 
-    observes = VPGWCComponent
+    observes = VPGWCTenant
 
     requested_interval = 0
 
@@ -20,18 +20,20 @@
     service_key_name = "/opt/xos/configurations/mcord/mcord_private_key"
 
     def __init__(self, *args, **kwargs):
-        super(SyncVPGWCComponent, self).__init__(*args, **kwargs)
+        super(SyncVPGWCTenant, self).__init__(*args, **kwargs)
 
     def fetch_pending(self, deleted):
 
         if (not deleted):
-            objs = VPGWCComponent.get_tenant_objects().filter(
+            objs = VPGWCTenant.get_tenant_objects().filter(
                 Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False))
         else:
 
-            objs = VPGWCComponent.get_deleted_tenant_objects()
+            objs = VPGWCTenant.get_deleted_tenant_objects()
 
         return objs
 
+    # 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):
         return {"display_message": o.display_message, "s5s8_pgw_tag": o.s5s8_pgw_tag}
diff --git a/xos/synchronizer/vpgwc_config b/xos/synchronizer/vpgwc_config
index c6b9c23..d5cf77c 100755
--- a/xos/synchronizer/vpgwc_config
+++ b/xos/synchronizer/vpgwc_config
@@ -10,7 +10,8 @@
 [api]
 nova_enabled=True
 
-# Sets options for the observer
+
+# Sets options for the synchronizer
 [observer]
 # Optional name
 name=vpgwc
diff --git a/xos/tosca/resources/VPGWCComponent.py b/xos/tosca/resources/VPGWCComponent.py
index d30e6a0..afd6966 100644
--- a/xos/tosca/resources/VPGWCComponent.py
+++ b/xos/tosca/resources/VPGWCComponent.py
@@ -1,14 +1,14 @@
-from services.vpgwc.models import VPGWCComponent, VPGWCService
+from services.vpgwc.models import VPGWCTenant, VPGWCService
 from xosresource import XOSResource
 
-class XOSVPGWCComponent(XOSResource):
-    provides = "tosca.nodes.VPGWCComponent"
-    xos_model = VPGWCComponent
+class XOSVPGWCTenant(XOSResource):
+    provides = "tosca.nodes.VPGWCTenant"
+    xos_model = VPGWCTenant
     copyin_props = ["s5s8_pgw_tag", "display_message"]
     name_field = None
 
     def get_xos_args(self, throw_exception=True):
-        args = super(XOSVPGWCComponent, self).get_xos_args()
+        args = super(XOSVPGWCTenant, self).get_xos_args()
 
         provider_name = self.get_requirement("tosca.relationships.MemberOfService", throw_exception=throw_exception)
         if provider_name:
@@ -27,5 +27,5 @@
         pass
 
     def can_delete(self, obj):
-        return super(XOSVPGWCComponent, self).can_delete(obj)
+        return super(XOSVPGWCTenant, self).can_delete(obj)
 
diff --git a/xos/vPGWC-onboard.yaml b/xos/vPGWC-onboard.yaml
index bde25d8..555d3f1 100644
--- a/xos/vPGWC-onboard.yaml
+++ b/xos/vPGWC-onboard.yaml
@@ -3,7 +3,7 @@
 description: Onboard the vPGWC service
 
 imports:
-   - custom_types/xos.yaml
+  - custom_types/xos.yaml
 
 topology_template:
   node_templates:
@@ -19,9 +19,8 @@
           synchronizer: synchronizer/manifest
           synchronizer_run: vpgwc-synchronizer.py
           #tosca_custom_types: exampleservice.yaml
-          tosca_resource: tosca/resources/VPGWCComponent.py, tosca/resources/VPGWCService.py
+          tosca_resource: tosca/resources/VPGWCTenant.py, tosca/resources/VPGWCService.py
           #rest_service: subdirectory:vsg api/service/vsg/vsgservice.py
           #rest_tenant: subdirectory:cord api/tenant/cord/vsg.py
           private_key: file:///opt/xos/key_import/vPGWC_rsa
           public_key: file:///opt/xos/key_import/vPGWC_rsa.pub
-