CordSubscriberNew, WIP
diff --git a/xos/core/xoslib/objects/cordsubscriber.py b/xos/core/xoslib/objects/cordsubscriber.py
index bc5c747..144fa63 100644
--- a/xos/core/xoslib/objects/cordsubscriber.py
+++ b/xos/core/xoslib/objects/cordsubscriber.py
@@ -1,5 +1,5 @@
from core.models import Slice, SlicePrivilege, SliceRole, Sliver, Site, Node, User
-from cord.models import VOLTTenant
+from cord.models import VOLTTenant, CordSubscriberRoot
from plus import PlusObjectMixin
from operator import itemgetter, attrgetter
from rest_framework.exceptions import APIException
@@ -93,6 +93,86 @@
print "attr", self.vcpe.vbng.service_specific_attribute
self.vcpe.vbng.save()
+class CordSubscriberNew(CordSubscriberRoot):
+ class Meta:
+ proxy = True
+
+ def __init__(self, *args, **kwargs):
+ super(CordSubscriber, self).__init__(*args, **kwargs)
+
+ def __unicode__(self):
+ return u"cordSubscriber-%s" % str(self.id)
+
+ passthroughs = ( # the following are now fields of CordSubscriberRoot
+ # ("firewall_enable", "vcpe.firewall_enable"),
+ # ("firewall_rules", "vcpe.firewall_rules"),
+ # ("url_filter_enable", "vcpe.url_filter_enable"),
+ # ("url_filter_rules", "vcpe.url_filter_rules"),
+ # ("url_filter_level", "vcpe.url_filter_level"),
+ # ("bbs_account", "vcpe.bbs_account"),
+ # ("users", "vcpe.users"),
+ # ("services", "vcpe.services"),
+ # ("cdn_enable", "vcpe.cdn_enable"),
+
+ ("ssh_command", "volt.vcpe.ssh_command"),
+ ("image", "volt.vcpe.image.id"),
+ ("image_name", "volt.vcpe.image.name"),
+ ("sliver", "volt.vcpe.sliver.id"),
+ ("sliver_name", "volt.vcpe.sliver.name"),
+ ("routeable_subnet", "volt.vcpe.vbng.routeable_subnet"),
+ ("vcpe_id", "volt.vcpe.id"),
+ ("vbng_id", "volt.vcpe.vbng.id"),
+ ("nat_ip", "volt.vcpe.nat_ip"),
+ ("lan_ip", "volt.vcpe.lan_ip"),
+ ("private_ip", "volt.vcpe.private_ip"),
+ ("wan_ip", "volt.vcpe.wan_ip"),
+ ("wan_mac", "volt.vcpe.wan_mac"),
+ ("vcpe_synced", "volt.vcpe.is_synced"),
+ )
+
+ 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])
+
+ raise AttributeError("getattr: %r object has no attribute %r" %
+ (self.__class__, key))
+
+ 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)
+
+ def save(self, *args, **kwargs):
+ super(CordSubscriber, self).save(*args, **kwargs)
+
+ # in case the vcpe or vbng fields were altered
+ # TODO: dirty detection?
+ if (self.volt):
+ print "save volt"
+ self.volt.save()
+ if (self.vcpe):
+ print "save vcpe"
+ self.vcpe.save()
+ if (self.vcpe.vbng):
+ print "save vbng", self.vcpe.vbng
+ print "attr", self.vcpe.vbng.service_specific_attribute
+ self.vcpe.vbng.save()
+