refactor vHSS cord-3.0
Change-Id: I45fec5512d4e2974d925cc0a943feecb6a6a85d8
diff --git a/xos/admin.py b/xos/admin.py
deleted file mode 100644
index df1ad24..0000000
--- a/xos/admin.py
+++ /dev/null
@@ -1,116 +0,0 @@
-# admin.py - VHSSService 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.vhss.models import *
-
-class VHSSServiceForm(forms.ModelForm):
-
- class Meta:
- model = VHSSService
- fields = '__all__'
-
- def __init__(self, *args, **kwargs):
- super(VHSSServiceForm, 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(VHSSServiceForm, self).save(commit=commit)
-
-class VHSSServiceAdmin(ReadOnlyAwareAdmin):
-
- model = VHSSService
- verbose_name = "vHSS Service"
- verbose_name_plural = "vHSS Services"
- 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', 'vHSS Service Details', ),
- ('slices', 'Slices',),
- )
-
- suit_form_includes = ((
- 'top',
- 'administration'),
- )
-
- def get_queryset(self, request):
- return VHSSService.get_service_objects_by_user(request.user)
-
-admin.site.register(VHSSService, VHSSServiceAdmin)
-
-class VHSSTenantForm(forms.ModelForm):
-
- class Meta:
- model = VHSSTenant
- fields = '__all__'
-
- creator = forms.ModelChoiceField(queryset=User.objects.all())
-
- def __init__(self, *args, **kwargs):
- super(VHSSTenantForm, self).__init__(*args, **kwargs)
-
- self.fields['kind'].widget.attrs['readonly'] = True
- self.fields['kind'].initial = "vhss"
-
- self.fields['provider_service'].queryset = VHSSService.get_service_objects().all()
-
- if self.instance:
- self.fields['creator'].initial = self.instance.creator
- self.fields['tenant_message'].initial = self.instance.tenant_message
-
- if (not self.instance) or (not self.instance.pk):
- self.fields['creator'].initial = get_request().user
- if VHSSService.get_service_objects().exists():
- self.fields['provider_service'].initial = VHSSService.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')
- return super(VHSSTenantForm, self).save(commit=commit)
-
-
-class VHSSTenantAdmin(ReadOnlyAwareAdmin):
-
- verbose_name = "vHSS Service Tenant"
- verbose_name_plural = "vHSS Service Tenants"
-
- list_display = ('id', 'backend_status_icon', 'instance', 'tenant_message')
- list_display_links = ('backend_status_icon', 'instance', 'tenant_message', 'id')
-
- fieldsets = [(None, {
- 'fields': ['backend_status_text', 'kind', 'provider_service', 'instance', 'creator', 'tenant_message'],
- 'classes': ['suit-tab suit-tab-general'],
- })]
-
- readonly_fields = ('backend_status_text', 'instance',)
-
-
- suit_form_tabs = (('general', 'Details'),)
-
- def get_queryset(self, request):
- return VHSSTenant.get_tenant_objects_by_user(request.user)
-
-admin.site.register(VHSSTenant, VHSSTenantAdmin)
-
diff --git a/xos/header.py b/xos/header.py
deleted file mode 100644
index 2e60747..0000000
--- a/xos/header.py
+++ /dev/null
@@ -1,15 +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 d30acce..77053cc 100644
--- a/xos/models.py
+++ b/xos/models.py
@@ -2,6 +2,22 @@
from models_decl import VHSSService_decl
from models_decl import VHSSTenant_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 VHSSService(VHSSService_decl):
class Meta:
proxy = True
diff --git a/xos/synchronizer/steps/sync_vhsstenant.py b/xos/synchronizer/steps/sync_vhsstenant.py
index 78167f8..f48b126 100644
--- a/xos/synchronizer/steps/sync_vhsstenant.py
+++ b/xos/synchronizer/steps/sync_vhsstenant.py
@@ -1,14 +1,12 @@
import os
import sys
+from django.db.models import Q, F
from synchronizers.new_base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
from synchronizers.new_base.modelaccessor import *
-#from xos.logger import Logger, logging
parentdir = os.path.join(os.path.dirname(__file__), "..")
sys.path.insert(0, parentdir)
-#logger = Logger(level=logging.INFO)
-
class SyncVHSSTenant(SyncInstanceUsingAnsible):
provides = [VHSSTenant]
@@ -17,66 +15,31 @@
requested_interval = 0
- template_name = "sync_vhss.yaml"
+ template_name = "vhsstenant_playbook.yaml"
- service_key_name = "/opt/xos/synchronizers/mcord/mcord_private_key"
-
- #watches = [ModelLink(ServiceDependency,via='servicedependency'), ModelLink(ServiceMonitoringAgentInfo,via='monitoringagentinfo')]
-
- def __init__(self, *args, **kwargs):
- super(SyncVHSSTenant, self).__init__(*args, **kwargs)
-
- def get_vhss(self, o):
- if not o.provider_service:
- return None
-
- vhss = VHSSService.objects.filter(id=o.provider_service.id)
-
- if not vhss:
- return None
-
- return vhss[0]
+ service_key_name = "/opt/xos/configurations/mcord/mcord_private_key"
#Gets the attributes that are used by the Ansible template but are not
#part of the set of default attributes.
+ def __init__(self, *args, **kwargs):
+ super(SyncVHSSTenant, self).__init__(*args, **kwargs)
+
+ def fetch_pending(self, deleted):
+
+ if (not deleted):
+ objs = VHSSTenant.get_tenant_objects().filter(
+ Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False))
+ else:
+
+ objs = VHSSTenant.get_deleted_tenant_objects()
+
+ return objs
+
def get_extra_attributes(self, o):
fields = {}
fields['tenant_message'] = o.tenant_message
- vhss = self.get_vhss(o)
- fields['service_message'] = vhss.service_message
return fields
def delete_record(self, port):
pass
-
- #def handle_service_monitoringagentinfo_watch_notification(self, monitoring_agent_info):
- # if not monitoring_agent_info.service:
- # logger.info("handle watch notifications for service monitoring agent info...ignoring because service attribute in monitoring agent info:%s is null" % (monitoring_agent_info))
- # return
-
- # if not monitoring_agent_info.target_uri:
- # logger.info("handle watch notifications for service monitoring agent info...ignoring because target_uri attribute in monitoring agent info:%s is null" % (monitoring_agent_info))
- # return
-
- # objs = VHSSTenant.objects.all()
- # for obj in objs:
- # if obj.provider_service.id != monitoring_agent_info.service.id:
- # logger.info("handle watch notifications for service monitoring agent info...ignoring because service attribute in monitoring agent info:%s is not matching" % (monitoring_agent_info))
- # return
-
- # instance = self.get_instance(obj)
- # if not instance:
- # logger.warn("handle watch notifications for service monitoring agent info...: No valid instance found for object %s" % (str(obj)))
- # return
-
- # logger.info("handling watch notification for monitoring agent info:%s for ExampleTenant object:%s" % (monitoring_agent_info, obj))
-
- # #Run ansible playbook to update the routing table entries in the instance
- # fields = self.get_ansible_fields(instance)
- # fields["ansible_tag"] = obj.__class__.__name__ + "_" + str(obj.id) + "_monitoring"
- # fields["target_uri"] = monitoring_agent_info.target_uri
-
- # template_name = "monitoring_agent.yaml"
- # super(SyncVHSSTenant, self).run_playbook(obj, fields, template_name)
- # pass
diff --git a/xos/synchronizer/steps/vhsstenant_playbook.yaml b/xos/synchronizer/steps/vhsstenant_playbook.yaml
index 896fd87..4ad8968 100644
--- a/xos/synchronizer/steps/vhsstenant_playbook.yaml
+++ b/xos/synchronizer/steps/vhsstenant_playbook.yaml
@@ -8,5 +8,3 @@
gather_facts: no
vars:
- tenant_message: "{{ tenant_message }}"
- - service_message: "{{ service_message }}"
-
diff --git a/xos/synchronizer/vhss_from_api_config b/xos/synchronizer/vhss_from_api_config
index 65539c0..b8a05cc 100644
--- a/xos/synchronizer/vhss_from_api_config
+++ b/xos/synchronizer/vhss_from_api_config
@@ -16,6 +16,6 @@
enable_watchers=True
accessor_kind=api
accessor_password=@/opt/xos/services/vhss/credentials/xosadmin@opencord.org
-#required_models=VHSSService, VHSSTenant, ServiceDependency, ServiceMonitoringAgentInfo
+#required_models=VHSSService, VHSSTenant, ServiceDependency
[networking]
use_vtn=True
diff --git a/xos/templates/vhssadmin.html b/xos/templates/vhssadmin.html
deleted file mode 100644
index 9952a95..0000000
--- a/xos/templates/vhssadmin.html
+++ /dev/null
@@ -1,9 +0,0 @@
-<div class = "left-nav">
- <ul>
- <li>
- <a href="/admin/mcordservice/vhsscomponent/">
- vHSS Service Components>
- </a>
- </li>
- </ul>
-</div>
diff --git a/xos/tosca/custom_types/vhss.m4 b/xos/tosca/custom_types/vhss.m4
index b36695c..9a2ee17 100644
--- a/xos/tosca/custom_types/vhss.m4
+++ b/xos/tosca/custom_types/vhss.m4
@@ -15,9 +15,6 @@
properties:
xos_base_props
xos_base_service_props
- service_message:
- type: string
- required: false
tosca.nodes.VHSSTenant:
derived_from: tosca.nodes.Root
diff --git a/xos/tosca/custom_types/vhss.yaml b/xos/tosca/custom_types/vhss.yaml
index e11f528..db0c41b 100644
--- a/xos/tosca/custom_types/vhss.yaml
+++ b/xos/tosca/custom_types/vhss.yaml
@@ -78,9 +78,6 @@
type: string
required: false
description: Version number of Service.
- service_message:
- type: string
- required: false
tosca.nodes.VHSSTenant:
derived_from: tosca.nodes.Root
diff --git a/xos/tosca/resources/vhssservice.py b/xos/tosca/resources/vhssservice.py
index 370a008..6d83bcd 100644
--- a/xos/tosca/resources/vhssservice.py
+++ b/xos/tosca/resources/vhssservice.py
@@ -4,6 +4,4 @@
class XOSVHSSService(XOSService):
provides = "tosca.nodes.VHSSService"
xos_model = VHSSService
- copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "private_key_fn", "versionNumber", "service_message"]
-
-
+ copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "private_key_fn", "versionNumber"]
diff --git a/xos/vhss-onboard.yaml b/xos/vhss-onboard.yaml
index 13f6005..000dded 100644
--- a/xos/vhss-onboard.yaml
+++ b/xos/vhss-onboard.yaml
@@ -14,10 +14,8 @@
# The following will concatenate with base_url automatically, if
# base_url is non-null.
xproto: ./
- admin: admin.py
- admin_template: templates/vhssadmin.html
- #synchronizer: synchronizer/manifest
- #synchronizer_run: vhss-synchronizer.py
+ synchronizer: synchronizer/manifest
+ synchronizer_run: vhss-synchronizer.py
tosca_custom_types: tosca/custom_types/vhss.yaml
tosca_resource: tosca/resources/vhssservice.py, tosca/resources/vhsstenant.py
private_key: file:///opt/xos/key_import/mcord_rsa
diff --git a/xos/vhss.xproto b/xos/vhss.xproto
index 740bc27..4a951f7 100644
--- a/xos/vhss.xproto
+++ b/xos/vhss.xproto
@@ -1,12 +1,12 @@
option name = "vHSS";
option verbose_name = "Virtual Home Subscriber Server";
+option app_label = "vhss";
option kind = "vEPC";
option legacy = "True";
message VHSSService (Service){
option name = "VHSSService";
option verbose_name = "Virtual Home Subscriber Server Service";
- required string service_message = 1 [help_text = "Service Message to Display", max_length = 254, null = False, db_index = False, blank = False];
}
message VHSSTenant (TenantWithContainer){