redo cordsubscriber fields using passthrough
diff --git a/xos/core/xoslib/methods/cordsubscriber.py b/xos/core/xoslib/methods/cordsubscriber.py
index f724c1e..1470323 100644
--- a/xos/core/xoslib/methods/cordsubscriber.py
+++ b/xos/core/xoslib/methods/cordsubscriber.py
@@ -12,16 +12,23 @@
if hasattr(serializers, "ReadOnlyField"):
# rest_framework 3.x
- IdField = serializers.ReadOnlyField
+ ReadOnlyField = serializers.ReadOnlyField
else:
# rest_framework 2.x
- IdField = serializers.Field
+ ReadOnlyField = serializers.Field
class CordSubscriberIdSerializer(serializers.ModelSerializer, PlusSerializerMixin):
- id = IdField()
- vcpe_id = IdField()
- sliver_id = IdField()
+ id = ReadOnlyField()
+ vcpe_id = ReadOnlyField()
+ sliver = ReadOnlyField()
+ image = ReadOnlyField()
firewall_enable = serializers.BooleanField()
+ firewall_rules = serializers.CharField()
+ url_filter_enable = serializers.BooleanField()
+ url_filter_rules = serializers.CharField()
+ cdn_enable = serializers.BooleanField()
+ sliver_name = ReadOnlyField()
+ image_name = ReadOnlyField()
humanReadableName = serializers.SerializerMethodField("getHumanReadableName")
@@ -29,11 +36,11 @@
model = CordSubscriber
fields = ('humanReadableName', 'id',
'service_specific_id',
- 'vcpe_id', 'sliver_id', 'firewall_enable')
+ 'vcpe_id', 'sliver', 'sliver_name', 'image', 'image_name', 'firewall_enable', 'firewall_rules', 'url_filter_enable', 'url_filter_rules', 'cdn_enable')
def getHumanReadableName(self, obj):
- return str(obj)
+ return obj.__unicode__()
class CordSubscriberList(XOSListCreateAPIView):
queryset = CordSubscriber.get_tenant_objects().select_related().all()
diff --git a/xos/core/xoslib/objects/cordsubscriber.py b/xos/core/xoslib/objects/cordsubscriber.py
index d483cac..654d8a3 100644
--- a/xos/core/xoslib/objects/cordsubscriber.py
+++ b/xos/core/xoslib/objects/cordsubscriber.py
@@ -4,6 +4,20 @@
from operator import itemgetter, attrgetter
from rest_framework.exceptions import APIException
+"""
+import os
+import sys
+sys.path.append("/opt/xos")
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings")
+import django
+from core.models import *
+from hpc.models import *
+from cord.models import *
+django.setup()
+from core.xoslib.objects.cordsubscriber import CordSubscriber
+c=CordSubscriber.get_tenant_objects().select_related().all()[0]
+"""
+
class CordSubscriber(VOLTTenant, PlusObjectMixin):
class Meta:
proxy = True
@@ -22,29 +36,45 @@
def vcpe_id(self, value):
pass
- @property
- def sliver_id(self):
- if self.vcpe and self.vcpe.sliver:
- return self.vcpe.sliver.id
- else:
- return None
+ passthroughs = ( ("firewall_enable", "vcpe.firewall_enable"),
+ ("firewall_rules", "vcpe.firewall_rules"),
+ ("url_filter_enable", "vcpe.url_filter_enable"),
+ ("url_filter_rules", "vcpe.url_filter_rules"),
+ ("cdn_enable", "vcpe.cdn_enable"),
+ ("image", "vcpe.image.id"),
+ ("image_name", "vcpe.image.name"),
+ ("sliver", "vcpe.sliver.id"),
+ ("sliver_name", "vcpe.sliver.name") )
- @sliver_id.setter
- def sliver_id(self, value):
- pass
+ def __getattr__(self, key):
+ for (member_name, passthrough_name) in self.passthroughs:
+ if key==member_name:
+ parts = passthrough_name.split(".")
+ obj = self
+ for part in parts[:-1]:
+ obj = getattr(obj, part)
+ if not obj:
+ return None
+ return getattr(obj, parts[-1])
- @property
- def firewall_enable(self):
- if self.vcpe:
- return self.vcpe.firewall_enable
- else:
- return None
+ raise AttributeError("getattr: %r object has no attribute %r" %
+ (self.__class__, key))
- @firewall_enable.setter
- def firewall_enable(self, value):
- if self.vcpe:
- self.vcpe.firewall_enable = value
- # TODO: save it
+ def __setattr__(self, key, value):
+ for (member_name, passthrough_name) in self.passthroughs:
+ if key==member_name:
+ parts = passthrough_name.split(".")
+ obj = self
+ for part in parts[:-1]:
+ obj = getattr(obj, part)
+ if not obj:
+ return
+ setattr(obj, parts[-1], value)
+
+ super(CordSubscriber, self).__setattr__(key, value)
+
+
+