add sync_attributes for subscriber, enforce one vOLT per subscriber, auto-create subscriber object for vOLT
diff --git a/xos/cord/models.py b/xos/cord/models.py
index 59397a0..3dc4a67 100644
--- a/xos/cord/models.py
+++ b/xos/cord/models.py
@@ -73,9 +73,16 @@
"cdn_enable": False,
"users": [] }
+ sync_attributes = ("firewall_enable",
+ "firewall_rules",
+ "url_filter_enable",
+ "url_filter_rules",
+ "cdn_enable",)
+
def __init__(self, *args, **kwargs):
super(CordSubscriberRoot, self).__init__(*args, **kwargs)
self.cached_volt = None
+ self._initial_url_filter_enable = self.url_filter_enable
@property
def volt(self):
@@ -210,6 +217,13 @@
def services(self, value):
pass
+ def save(self, *args, **kwargs):
+ super(CordSubscriberRoot, self).save(*args, **kwargs)
+ if (self.volt) and (self.volt.vcpe): # and (self._initial_url_filter_enabled != self.url_filter_enable):
+ # 1) trigger manage_bbs_account to run
+ # 2) trigger vcpe observer to wake up
+ self.volt.vcpe.save()
+
# -------------------------------------------
# VOLT
# -------------------------------------------
@@ -319,6 +333,25 @@
vcpe.caller = self.creator
vcpe.save()
+ def manage_subscriber(self):
+ if (self.subscriber_root is None):
+ # The vOLT is not connected to a Subscriber, so either find an
+ # existing subscriber with the same SSID, or autogenerate a new
+ # subscriber.
+ #
+ # TODO: This probably goes away when we rethink the ONOS-to-XOS
+ # vOLT API.
+
+ subs = CordSubscriberRoot.get_tenant_objects().filter(service_specific_id = self.service_specific_id)
+ if subs:
+ sub = subs[0]
+ else:
+ sub = CordSubscriberRoot(service_specific_id = self.service_specific_id,
+ name = "autogenerated-for-vOLT-%s" % self.id)
+ sub.save()
+ self.subscriber_root = sub
+ self.save()
+
def cleanup_vcpe(self):
if self.vcpe:
# print "XXX cleanup vcpe", self.vcpe
@@ -335,6 +368,11 @@
def save(self, *args, **kwargs):
self.validate_unique_service_specific_id()
+ if (self.subscriber_root is not None):
+ subs = self.subscriber_root.get_subscribed_tenants(VOLTTenant)
+ if (subs) and (self not in subs):
+ raise XOSDuplicateKey("Subscriber should only be linked to one vOLT")
+
if not self.creator:
if not getattr(self, "caller", None):
# caller must be set when creating a vCPE since it creates a slice
@@ -345,6 +383,7 @@
super(VOLTTenant, self).save(*args, **kwargs)
self.manage_vcpe()
+ self.manage_subscriber()
self.cleanup_orphans()
def delete(self, *args, **kwargs):
@@ -499,6 +538,14 @@
# *** to be moved to CordSubscriberRoot
+ # TODO:
+ # 1) delete the stuff in this section
+ # 2) remove the associated fields from sync_attributes and default_attributes
+ # 3) in core/xoslib/methods/cordsubscriber.py, rename CordSubscriberNew to CordSubscriber
+ # 4) in observers/vcpe/steps/sync_vcpetenant, remove the stuff marked 'legacy'
+ # 5) update manage_bbs_account
+ # 6) come up with a way to auto-create Subscriber from vOLT, for backward compatibility
+
@property
def firewall_enable(self):
return self.get_attribute("firewall_enable", self.default_attributes["firewall_enable"])
@@ -796,10 +843,7 @@
if not self.bbs_account:
# make sure we use the proxied VCPEService object, not the generic Service object
vcpe_service = VCPEService.objects.get(id=self.provider_service.id)
- if self.service_specific_id=="SYNCME":
- self.bbs_account = "bbs01@onlab.us"
- else:
- self.bbs_account = vcpe_service.allocate_bbs_account()
+ self.bbs_account = vcpe_service.allocate_bbs_account()
super(VCPETenant, self).save()
else:
if self.bbs_account: