CORD-1250 Update to new Service/Tenancy models
Change-Id: Ie98caa95aed385413f9f28668fe3f3d5f4eab9e9
diff --git a/xos/admin.py b/xos/admin.py
index a479d9c..094872d 100644
--- a/xos/admin.py
+++ b/xos/admin.py
@@ -9,7 +9,7 @@
from django.utils import timezone
from django.contrib.contenttypes import generic
from suit.widgets import LinkedSelect
-from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline, TenantRootTenantInline, TenantRootPrivilegeInline
+from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline
from core.middleware import get_request
from services.vtr.models import *
@@ -53,14 +53,13 @@
def __init__(self,*args,**kwargs):
super (VTRTenantForm,self ).__init__(*args,**kwargs)
- self.fields['provider_service'].queryset = VTRService.objects.all()
+ self.fields['owner'].queryset = VTRService.objects.all()
if self.instance:
if self.instance.target_id:
self.fields["target"].initial = CordSubscriberRoot.get_content_object(self.instance.target_type, self.instance.target_id)
if (not self.instance) or (not self.instance.pk):
- self.fields['kind'].initial = VTR_KIND
if VTRService.objects.exists():
- self.fields["provider_service"].initial = VTRService.objects.all()[0]
+ self.fields["owner"].initial = VTRService.objects.all()[0]
def save(self, commit=True):
if self.cleaned_data.get("target"):
@@ -75,7 +74,7 @@
class VTRTenantAdmin(ReadOnlyAwareAdmin):
list_display = ('backend_status_icon', 'id', 'target_type', 'target_id', 'test', 'argument' )
list_display_links = ('backend_status_icon', 'id')
- fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service',
+ fieldsets = [ (None, {'fields': ['backend_status_text', 'owner',
'target', 'scope', 'test', 'argument', 'is_synced', 'result_code', 'result'],
'classes':['suit-tab suit-tab-general']})]
readonly_fields = ('backend_status_text', 'service_specific_attribute', 'is_synced')
diff --git a/xos/api/tenant/truckroll.py b/xos/api/tenant/truckroll.py
deleted file mode 100644
index caf9e24..0000000
--- a/xos/api/tenant/truckroll.py
+++ /dev/null
@@ -1,74 +0,0 @@
-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 services.vtr.models import VTRTenant, VTRService
-from services.rcord.models import CordSubscriberRoot
-from xos.apibase import XOSListCreateAPIView, XOSRetrieveUpdateDestroyAPIView, XOSPermissionDenied
-from api.xosapi_helpers import PlusModelSerializer, XOSViewSet, ReadOnlyField
-from django.contrib.contenttypes.models import ContentType
-
-def get_default_vtr_service():
- vtr_services = VTRService.objects.all()
- if vtr_services:
- return vtr_services[0]
- return None
-
-class VTRTenantForAPI(VTRTenant):
- class Meta:
- proxy = True
- app_label = "cord"
-
-class VTRTenantSerializer(PlusModelSerializer):
- id = ReadOnlyField()
- target_id = serializers.IntegerField()
- test = serializers.CharField()
- scope = serializers.CharField()
- argument = serializers.CharField(required=False)
- provider_service = serializers.PrimaryKeyRelatedField(queryset=VTRService.objects.all(), default=get_default_vtr_service)
- result = serializers.CharField(required=False)
- result_code = serializers.CharField(required=False)
- backend_status = ReadOnlyField()
-
- humanReadableName = serializers.SerializerMethodField("getHumanReadableName")
- is_synced = serializers.SerializerMethodField("isSynced")
-
- class Meta:
- model = VTRTenantForAPI
- fields = ('humanReadableName', 'id', 'provider_service', 'target_id', 'scope', 'test', 'argument', 'result', 'result_code', 'is_synced', 'backend_status' )
-
- def getHumanReadableName(self, obj):
- return obj.__unicode__()
-
- def isSynced(self, obj):
- return (obj.enacted is not None) and (obj.enacted >= obj.updated)
-
- def create(self, validated_data):
- # force the target_type to be CordSubscriberRoot
- validated_data["target_type_id"] = ContentType.objects.get_for_model(CordSubscriberRoot).id
- return super(VTRTenantSerializer, self).create(validated_data)
-
-class TruckRollViewSet(XOSViewSet):
- base_name = "truckroll"
- method_name = "truckroll"
- method_kind = "viewset"
- queryset = VTRTenantForAPI.objects.all() # select_related().all()
- serializer_class = VTRTenantSerializer
-
- @classmethod
- def get_urlpatterns(self, api_path="^"):
- patterns = super(TruckRollViewSet, self).get_urlpatterns(api_path=api_path)
-
- return patterns
-
- def list(self, request):
- queryset = self.filter_queryset(self.get_queryset())
-
- serializer = self.get_serializer(queryset, many=True)
-
- return Response(serializer.data)
-
diff --git a/xos/attic/header.py b/xos/attic/header.py
index e483538..36d0a6f 100644
--- a/xos/attic/header.py
+++ b/xos/attic/header.py
@@ -1,5 +1,5 @@
from django.db import models
-from core.models import Service, XOSBase, Slice, Instance, Tenant, TenantWithContainer, Node, Image, User, Flavor, NetworkParameter, NetworkParameterType, Port, AddressPool
+from core.models import Service, XOSBase, Slice, Instance, ServiceInstance, TenantWithContainer, Node, Image, User, Flavor, NetworkParameter, NetworkParameterType, Port, AddressPool
from core.models.xosbase import StrippedCharField
import os
from django.db import models, transaction
diff --git a/xos/attic/vtrtenant_model.py b/xos/attic/vtrtenant_model.py
index f2d24c3..2bd55cb 100644
--- a/xos/attic/vtrtenant_model.py
+++ b/xos/attic/vtrtenant_model.py
@@ -3,7 +3,7 @@
def __init__(self, *args, **kwargs):
vtr_services = VTRService.objects.all()
if vtr_services:
- self._meta.get_field("provider_service").default = vtr_services[0].id
+ self._meta.get_field("owner").default = vtr_services[0].id
super(VTRTenant, self).__init__(*args, **kwargs)
def save(self, *args, **kwargs):
diff --git a/xos/synchronizer/steps/sync_vtrtenant.py b/xos/synchronizer/steps/sync_vtrtenant.py
index 7cc480f..5182f01 100644
--- a/xos/synchronizer/steps/sync_vtrtenant.py
+++ b/xos/synchronizer/steps/sync_vtrtenant.py
@@ -23,10 +23,11 @@
super(SyncVTRTenant, self).__init__(*args, **kwargs)
def get_vtr_service(self, o):
- if not o.provider_service:
+ if not o.owner:
return None
- vtrs = VTRService.objects.filter(id=o.provider_service.id)
+ # cast from Service to VTRService
+ vtrs = VTRService.objects.filter(id=o.owner.id)
if not vtrs:
return None
@@ -36,20 +37,17 @@
target = o.target
if target:
model_name = getattr(target, "model_name", target.__class__.__name__)
- # CordSubscriberRoot is a Proxy object, and o.target will point to
- # the base class... so fix it up.
- if model_name == "TenantRoot":
- target = CordSubscriberRoot.objects.get(id=target.id)
- return target
+ if model_name in ["ServiceInstance", "CordSubscriberRoot"]:
+ # cast from ServiceInstance to CordSubscriberRoot
+ csrs = CordSubscriberRoot.objects.filter(id=target.id)
+ if csrs:
+ return csrs[0]
return None
def get_vcpe_service(self, o):
target = self.get_target(o)
if target and target.volt and target.volt.vcpe:
- vcpes = VSGService.objects.filter(id=target.volt.vcpe.provider_service.id)
- if not vcpes:
- return None
- return vcpes[0]
+ return target.volt.vcpe
return None
def get_instance(self, o):
diff --git a/xos/vtr-onboard.yaml b/xos/vtr-onboard.yaml
index db4b653..8188cd1 100644
--- a/xos/vtr-onboard.yaml
+++ b/xos/vtr-onboard.yaml
@@ -18,7 +18,6 @@
admin_template: templates/vtradmin.html
tosca_custom_types: tosca/custom_types/vtr.yaml
tosca_resource: tosca/resources/vtrservice.py
- rest_tenant: api/tenant/truckroll.py
private_key: file:///opt/xos/key_import/vsg_rsa
public_key: file:///opt/xos/key_import/vsg_rsa.pub
diff --git a/xos/vtr.xproto b/xos/vtr.xproto
index e60425f..e21812b 100644
--- a/xos/vtr.xproto
+++ b/xos/vtr.xproto
@@ -2,7 +2,7 @@
option name="vtr";
option verbose_name="Virtual Truck Roll Service";
-message VTRTenant (Tenant){
+message VTRTenant (ServiceInstance){
required string test = 1 [choices = "(('ping', 'Ping'), ('traceroute', 'Trace Route'), ('tcpdump', 'Tcp Dump'), ('memory', 'Memory'), ('bandwidth', 'Bandwidth'))", max_length = 30, content_type = "stripped", blank = False, help_text = "type of test", null = False, db_index = False];
required string scope = 2 [choices = "(('container', 'Container'), ('vm', 'VM'))", max_length = 30, content_type = "stripped", blank = False, help_text = "scope of test", null = False, db_index = False];
optional string argument = 3 [db_index = False, max_length = 40, null = True, content_type = "stripped", blank = True];