CORD-1638 Rename ExampleTenant and drop obsolete references
Change-Id: Ia68efa15d84e536fd2f77aa3fea7ebabfd4a18c2
diff --git a/xos/admin.py b/xos/admin.py
deleted file mode 100644
index 50ac7fc..0000000
--- a/xos/admin.py
+++ /dev/null
@@ -1,134 +0,0 @@
-
-# Copyright 2017-present Open Networking Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-
-# admin.py - ExampleService 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.exampleservice.models import *
-
-class ExampleServiceForm(forms.ModelForm):
-
- class Meta:
- model = ExampleService
- fields = '__all__'
-
- def __init__(self, *args, **kwargs):
- super(ExampleServiceForm, 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(ExampleServiceForm, self).save(commit=commit)
-
-class ExampleServiceAdmin(ReadOnlyAwareAdmin):
-
- model = ExampleService
- verbose_name = SERVICE_NAME_VERBOSE
- verbose_name_plural = SERVICE_NAME_VERBOSE_PLURAL
- form = ExampleServiceForm
- 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.select_by_user(request.user)
-
-admin.site.register(ExampleService, ExampleServiceAdmin)
-
-class ExampleTenantForm(forms.ModelForm):
-
- class Meta:
- model = ExampleTenant
- fields = '__all__'
-
- creator = forms.ModelChoiceField(queryset=User.objects.all())
-
- def __init__(self, *args, **kwargs):
- super(ExampleTenantForm, self).__init__(*args, **kwargs)
-
- self.fields['kind'].widget.attrs['readonly'] = True
- self.fields['kind'].initial = SERVICE_NAME
-
- self.fields['provider_service'].queryset = ExampleService.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 ExampleService.objects.exists():
- self.fields['provider_service'].initial = ExampleService.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(ExampleTenantForm, self).save(commit=commit)
-
-
-class ExampleTenantAdmin(ReadOnlyAwareAdmin):
-
- verbose_name = TENANT_NAME_VERBOSE
- verbose_name_plural = TENANT_NAME_VERBOSE_PLURAL
-
- 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',)
-
- form = ExampleTenantForm
-
- suit_form_tabs = (('general', 'Details'),)
-
- def get_queryset(self, request):
- return ExampleTenant.select_by_user(request.user)
-
-admin.site.register(ExampleTenant, ExampleTenantAdmin)
-
diff --git a/xos/api/service/exampleservice.py b/xos/api/service/exampleservice.py
deleted file mode 100644
index 51aee08..0000000
--- a/xos/api/service/exampleservice.py
+++ /dev/null
@@ -1,70 +0,0 @@
-
-# Copyright 2017-present Open Networking Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-
-from rest_framework.decorators import api_view
-from rest_framework.response import Response
-from rest_framework.reverse import reverse
-from rest_framework import serializers
-from rest_framework import generics
-from rest_framework import viewsets
-from rest_framework import status
-from rest_framework.decorators import detail_route, list_route
-from rest_framework.views import APIView
-from core.models import *
-from django.forms import widgets
-from django.conf.urls import patterns, url
-from api.xosapi_helpers import PlusModelSerializer, XOSViewSet, ReadOnlyField
-from django.shortcuts import get_object_or_404
-from xos.apibase import XOSListCreateAPIView, XOSRetrieveUpdateDestroyAPIView, XOSPermissionDenied
-from xos.exceptions import *
-import json
-import subprocess
-from services.exampleservice.models import ExampleService
-
-class ExampleServiceSerializer(PlusModelSerializer):
- id = ReadOnlyField()
- humanReadableName = serializers.SerializerMethodField("getHumanReadableName")
- service_message = serializers.CharField(required=False)
-
- class Meta:
- model = ExampleService
- fields = ('humanReadableName',
- 'id',
- 'service_message')
-
- def getHumanReadableName(self, obj):
- return obj.__unicode__()
-
-class ExampleServiceViewSet(XOSViewSet):
- base_name = "exampleservice"
- method_name = "exampleservice"
- method_kind = "viewset"
- queryset = ExampleService.objects.all()
- serializer_class = ExampleServiceSerializer
-
- @classmethod
- def get_urlpatterns(self, api_path="^"):
- patterns = super(ExampleServiceViewSet, self).get_urlpatterns(api_path=api_path)
-
- return patterns
-
- def list(self, request):
- object_list = self.filter_queryset(self.get_queryset())
-
- serializer = self.get_serializer(object_list, many=True)
-
- return Response(serializer.data)
-
diff --git a/xos/api/tenant/exampletenant.py b/xos/api/tenant/exampletenant.py
deleted file mode 100644
index 120a4aa..0000000
--- a/xos/api/tenant/exampletenant.py
+++ /dev/null
@@ -1,83 +0,0 @@
-
-# Copyright 2017-present Open Networking Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-
-from rest_framework.decorators import api_view
-from rest_framework.response import Response
-from rest_framework.reverse import reverse
-from rest_framework import serializers
-from rest_framework import generics
-from rest_framework import status
-from core.models import *
-from django.forms import widgets
-from xos.apibase import XOSListCreateAPIView, XOSRetrieveUpdateDestroyAPIView, XOSPermissionDenied
-from api.xosapi_helpers import PlusModelSerializer, XOSViewSet, ReadOnlyField
-
-from services.exampleservice.models import ExampleTenant, ExampleService
-
-def get_default_example_service():
- example_services = ExampleService.objects.all()
- if example_services:
- return example_services[0]
- return None
-
-class ExampleTenantSerializer(PlusModelSerializer):
- id = ReadOnlyField()
- provider_service = serializers.PrimaryKeyRelatedField(queryset=ExampleService.objects.all(), default=get_default_example_service)
- tenant_message = serializers.CharField(required=False)
- backend_status = ReadOnlyField()
-
- humanReadableName = serializers.SerializerMethodField("getHumanReadableName")
-
- class Meta:
- model = ExampleTenant
- fields = ('humanReadableName', 'id', 'provider_service', 'tenant_message', 'backend_status')
-
- def getHumanReadableName(self, obj):
- return obj.__unicode__()
-
-class ExampleTenantViewSet(XOSViewSet):
- base_name = "exampletenant"
- method_name = "exampletenant"
- method_kind = "viewset"
- queryset = ExampleTenant.objects.all()
- serializer_class = ExampleTenantSerializer
-
- @classmethod
- def get_urlpatterns(self, api_path="^"):
- patterns = super(ExampleTenantViewSet, self).get_urlpatterns(api_path=api_path)
-
- # example to demonstrate adding a custom endpoint
- patterns.append( self.detail_url("message/$", {"get": "get_message", "put": "set_message"}, "message") )
-
- return patterns
-
- def list(self, request):
- queryset = self.filter_queryset(self.get_queryset())
-
- serializer = self.get_serializer(queryset, many=True)
-
- return Response(serializer.data)
-
- def get_message(self, request, pk=None):
- example_tenant = self.get_object()
- return Response({"tenant_message": example_tenant.tenant_message})
-
- def set_message(self, request, pk=None):
- example_tenant = self.get_object()
- example_tenant.tenant_message = request.data["tenant_message"]
- example_tenant.save()
- return Response({"tenant_message": example_tenant.tenant_message})
-
diff --git a/xos/attic/header.py b/xos/attic/header.py
index 17d1bf4..3ee13a7 100644
--- a/xos/attic/header.py
+++ b/xos/attic/header.py
@@ -23,5 +23,5 @@
SERVICE_NAME = 'exampleservice'
SERVICE_NAME_VERBOSE = 'Example Service'
SERVICE_NAME_VERBOSE_PLURAL = 'Example Services'
-TENANT_NAME_VERBOSE = 'Example Tenant'
-TENANT_NAME_VERBOSE_PLURAL = 'Example Tenants'
+SERVICE_INSTANCE_NAME_VERBOSE = 'Example Service Instance'
+SERVICE_INSTANCE_VERBOSE_PLURAL = 'Example Service Instances'
diff --git a/xos/exampleservice-onboard.yaml b/xos/exampleservice-onboard.yaml
index f0b3ef3..29a40b1 100644
--- a/xos/exampleservice-onboard.yaml
+++ b/xos/exampleservice-onboard.yaml
@@ -30,11 +30,8 @@
# The following will concatenate with base_url automatically, if
# base_url is non-null.
xproto: ./
- admin: admin.py
tosca_custom_types: exampleservice.yaml
- tosca_resource: tosca/resources/exampleservice.py, tosca/resources/exampletenant.py
- rest_service: api/service/exampleservice.py
- rest_tenant: api/tenant/exampletenant.py
+ tosca_resource: tosca/resources/exampleservice.py, tosca/resources/exampleserviceinstance.py
private_key: file:///opt/xos/key_import/exampleservice_rsa
public_key: file:///opt/xos/key_import/exampleservice_rsa.pub
diff --git a/xos/exampleservice.m4 b/xos/exampleservice.m4
index 6886a8c..214130c 100644
--- a/xos/exampleservice.m4
+++ b/xos/exampleservice.m4
@@ -35,6 +35,17 @@
type: string
required: false
+ tosca.nodes.ExampleServiceInstance:
+ derived_from: tosca.nodes.Root
+ description: >
+ A ServiceInstance of the example service
+ properties:
+ xos_base_tenant_props
+ tenant_message:
+ type: string
+ required: false
+
+ # deprecated, replaced by ExampleServiceInstance
tosca.nodes.ExampleTenant:
derived_from: tosca.nodes.Root
description: >
diff --git a/xos/exampleservice.xproto b/xos/exampleservice.xproto
index 0d5a70b..7356f3a 100644
--- a/xos/exampleservice.xproto
+++ b/xos/exampleservice.xproto
@@ -6,8 +6,8 @@
}
-message ExampleTenant (TenantWithContainer){
- option name = "exampletenant";
- option verbose_name = "Example Tenant";
+message ExampleServiceInstance (TenantWithContainer){
+ option name = "exampleserviceinstance";
+ option verbose_name = "Example Service Instance";
required string tenant_message = 1 [help_text = "Tenant Message to Display", max_length = 254, null = False, db_index = False, blank = False];
}
diff --git a/xos/exampleservice.yaml b/xos/exampleservice.yaml
index 5594ff9..04eed5c 100644
--- a/xos/exampleservice.yaml
+++ b/xos/exampleservice.yaml
@@ -98,6 +98,24 @@
type: string
required: false
+ tosca.nodes.ExampleServiceInstance:
+ derived_from: tosca.nodes.Root
+ description: >
+ A ServiceInstance of the example service
+ properties:
+ kind:
+ type: string
+ default: generic
+ description: Kind of tenant
+ service_specific_id:
+ type: string
+ required: false
+ description: Service specific ID opaque to XOS but meaningful to service
+ tenant_message:
+ type: string
+ required: false
+
+ # deprecated, replaced by ExampleServiceInstance
tosca.nodes.ExampleTenant:
derived_from: tosca.nodes.Root
description: >
diff --git a/xos/synchronizer/exampleservice_config.yaml b/xos/synchronizer/exampleservice_config.yaml
index d41f45d..275a09f 100644
--- a/xos/synchronizer/exampleservice_config.yaml
+++ b/xos/synchronizer/exampleservice_config.yaml
@@ -20,7 +20,7 @@
password: "@/opt/xos/services/exampleservice/credentials/xosadmin@opencord.org"
required_models:
- ExampleService
- - ExampleTenant
+ - ExampleServiceInstance
- ServiceDependency
- ServiceMonitoringAgentInfo
dependency_graph: "/opt/xos/synchronizers/exampleservice/model-deps"
diff --git a/xos/synchronizer/model_policies/model_policy_exampletenant.py b/xos/synchronizer/model_policies/model_policy_exampleserviceinstance.py
similarity index 87%
rename from xos/synchronizer/model_policies/model_policy_exampletenant.py
rename to xos/synchronizer/model_policies/model_policy_exampleserviceinstance.py
index ee2880a..8244204 100644
--- a/xos/synchronizer/model_policies/model_policy_exampletenant.py
+++ b/xos/synchronizer/model_policies/model_policy_exampleserviceinstance.py
@@ -17,5 +17,5 @@
from synchronizers.new_base.modelaccessor import *
from synchronizers.new_base.model_policies.model_policy_tenantwithcontainer import TenantWithContainerPolicy
-class ExampleTenantPolicy(TenantWithContainerPolicy):
- model_name = "ExampleTenant"
+class ExampleServiceInstancePolicy(TenantWithContainerPolicy):
+ model_name = "ExampleServiceInstance"
diff --git a/xos/synchronizer/steps/exampletenant_playbook.yaml b/xos/synchronizer/steps/exampleserviceinstance_playbook.yaml
similarity index 95%
rename from xos/synchronizer/steps/exampletenant_playbook.yaml
rename to xos/synchronizer/steps/exampleserviceinstance_playbook.yaml
index 0902bc4..5830815 100644
--- a/xos/synchronizer/steps/exampletenant_playbook.yaml
+++ b/xos/synchronizer/steps/exampleserviceinstance_playbook.yaml
@@ -15,7 +15,7 @@
---
-# exampletenant_playbook
+# exampleserviceinstance_playbook
- hosts: "{{ instance_name }}"
connection: ssh
diff --git a/xos/synchronizer/steps/sync_exampletenant.py b/xos/synchronizer/steps/sync_exampleserviceinstance.py
similarity index 87%
rename from xos/synchronizer/steps/sync_exampletenant.py
rename to xos/synchronizer/steps/sync_exampleserviceinstance.py
index d37e4c3..3462960 100644
--- a/xos/synchronizer/steps/sync_exampletenant.py
+++ b/xos/synchronizer/steps/sync_exampleserviceinstance.py
@@ -25,22 +25,22 @@
logger = Logger(level=logging.INFO)
-class SyncExampleTenant(SyncInstanceUsingAnsible):
+class SyncExampleServiceInstance(SyncInstanceUsingAnsible):
- provides = [ExampleTenant]
+ provides = [ExampleServiceInstance]
- observes = ExampleTenant
+ observes = ExampleServiceInstance
requested_interval = 0
- template_name = "exampletenant_playbook.yaml"
+ template_name = "exampleserviceinstance_playbook.yaml"
service_key_name = "/opt/xos/synchronizers/exampleservice/exampleservice_private_key"
watches = [ModelLink(ServiceDependency,via='servicedependency'), ModelLink(ServiceMonitoringAgentInfo,via='monitoringagentinfo')]
def __init__(self, *args, **kwargs):
- super(SyncExampleTenant, self).__init__(*args, **kwargs)
+ super(SyncExampleServiceInstance, self).__init__(*args, **kwargs)
def get_exampleservice(self, o):
if not o.owner:
@@ -76,7 +76,7 @@
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 = ExampleTenant.objects.all()
+ objs = ExampleServiceInstance.objects.all()
for obj in objs:
if obj.owner.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))
@@ -87,7 +87,7 @@
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))
+ logger.info("handling watch notification for monitoring agent info:%s for ExampleServiceInstance object:%s" % (monitoring_agent_info, obj))
#Run ansible playbook to update the routing table entries in the instance
fields = self.get_ansible_fields(instance)
@@ -95,5 +95,5 @@
fields["target_uri"] = monitoring_agent_info.target_uri
template_name = "monitoring_agent.yaml"
- super(SyncExampleTenant, self).run_playbook(obj, fields, template_name)
+ super(SyncExampleServiceInstance, self).run_playbook(obj, fields, template_name)
pass
diff --git a/xos/tosca/resources/exampletenant.py b/xos/tosca/resources/exampleserviceinstance.py
similarity index 65%
rename from xos/tosca/resources/exampletenant.py
rename to xos/tosca/resources/exampleserviceinstance.py
index 1d6c76a..7b8f640 100644
--- a/xos/tosca/resources/exampletenant.py
+++ b/xos/tosca/resources/exampleserviceinstance.py
@@ -1,4 +1,3 @@
-
# Copyright 2017-present Open Networking Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,21 +12,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-
from xosresource import XOSResource
from core.models import Service
-from services.exampleservice.models import ExampleTenant, SERVICE_NAME as EXAMPLETENANT_KIND
+from services.exampleservice.models import ExampleServiceInstance
-class XOSExampleTenant(XOSResource):
- provides = "tosca.nodes.ExampleTenant"
- xos_model = ExampleTenant
+class XOSExampleServiceInstance(XOSResource):
+ provides = ["tosca.nodes.ExampleServiceInstance",
+ "tosca.nodes.ExampleTenant" # deprecated
+ ]
+ xos_model = ExampleServiceInstance
name_field = "service_specific_id"
copyin_props = ("tenant_message",)
def get_xos_args(self, throw_exception=True):
- args = super(XOSExampleTenant, self).get_xos_args()
+ args = super(XOSExampleServiceInstance, self).get_xos_args()
- # ExampleTenant must always have a provider_service
+ # ExampleServiceInstance must always have a provider_service
provider_name = self.get_requirement("tosca.relationships.TenantOfService", throw_exception=True)
if provider_name:
args["owner"] = self.get_xos_object(Service, throw_exception=True, name=provider_name)
@@ -36,9 +36,9 @@
def get_existing_objs(self):
args = self.get_xos_args(throw_exception=False)
- return ExampleTenant.objects.filter(owner=args["owner"], service_specific_id=args["service_specific_id"])
+ return ExampleServiceInstance.objects.filter(owner=args["owner"], service_specific_id=args["service_specific_id"])
return []
def can_delete(self, obj):
- return super(XOSExampleTenant, self).can_delete(obj)
+ return super(XOSExampleServiceInstance, self).can_delete(obj)