CORD-1008 fix issue with creating diag object, add more convenience methods for cordsubscriberroot
Change-Id: I3ac65d1f4a100429a5bbcf2b088184a1125333fb
diff --git a/xos/synchronizers/new_base/diag.py b/xos/synchronizers/new_base/diag.py
index b4868ac..3384c0b 100644
--- a/xos/synchronizers/new_base/diag.py
+++ b/xos/synchronizers/new_base/diag.py
@@ -15,9 +15,17 @@
try:
diag = diag_class.objects.filter(name=observer_name).first()
if (not diag):
- diag = diag_class(name=observer_name)
+ if hasattr(diag_class.objects, "new"):
+ # api style
+ diag = diag_class.objects.new(name=observer_name)
+ else:
+ # django style
+ diag = diag_class(name=observer_name)
br_str = diag.backend_register
- br = json.loads(br_str)
+ if br_str:
+ br = json.loads(br_str)
+ else:
+ br = {}
if loop_end:
br['last_run'] = loop_end
if loop_end and loop_start:
diff --git a/xos/xos_client/xosapi/convenience/cordsubscriberroot.py b/xos/xos_client/xosapi/convenience/cordsubscriberroot.py
index e722468..440925e 100644
--- a/xos/xos_client/xosapi/convenience/cordsubscriberroot.py
+++ b/xos/xos_client/xosapi/convenience/cordsubscriberroot.py
@@ -1,3 +1,4 @@
+import json
from xosapi.orm import ORMWrapper, register_convenience_wrapper
class ORMWrapperCordSubscriberRoot(ORMWrapper):
@@ -8,5 +9,71 @@
return volt_tenants[0]
return None
+ # all of these will go away when CordSubscriberRoot is made into a real object
+
+ sync_attributes = ("firewall_enable",
+ "firewall_rules",
+ "url_filter_enable",
+ "url_filter_rules",
+ "cdn_enable",
+ "uplink_speed",
+ "downlink_speed",
+ "enable_uverse",
+ "status")
+
+ def get_attribute(self, name, default=None):
+ if self.service_specific_attribute:
+ attributes = json.loads(self.service_specific_attribute)
+ else:
+ attributes = {}
+ return attributes.get(name, default)
+
+ @property
+ def firewall_enable(self):
+ return self.get_attribute("firewall_enable", False)
+
+ @property
+ def firewall_rules(self):
+ return self.get_attribute("firewall_rules", "accept all anywhere anywhere")
+
+ @property
+ def url_filter_enable(self):
+ return self.get_attribute("url_filter_enable", False)
+
+ @property
+ def url_filter_rules(self):
+ return self.get_attribute("url_filter_rules", "allow all")
+
+ @property
+ def url_filter_level(self):
+ return self.get_attribute("url_filter_level", "PG")
+
+ @property
+ def cdn_enable(self):
+ return self.get_attribute("cdn_enable", False)
+
+ @property
+ def devices(self):
+ return self.get_attribute("devices", [])
+
+ @property
+ def is_demo_user(self):
+ return self.get_attribute("is_demo_user", False)
+
+ @property
+ def uplink_speed(self):
+ return self.get_attribute("uplink_speed", 1000000000)
+
+ @property
+ def downlink_speed(self):
+ return self.get_attribute("downlink_speed", 1000000000)
+
+ @property
+ def enable_uverse(self):
+ return self.get_attribute("enable_uverse", True)
+
+ @property
+ def status(self):
+ return self.get_attribute("status", "enabled")
register_convenience_wrapper("CordSubscriberRoot", ORMWrapperCordSubscriberRoot)
diff --git a/xos/xos_client/xosapi/convenience/volttenant.py b/xos/xos_client/xosapi/convenience/volttenant.py
index b3645e2..d8bb24c 100644
--- a/xos/xos_client/xosapi/convenience/volttenant.py
+++ b/xos/xos_client/xosapi/convenience/volttenant.py
@@ -8,5 +8,14 @@
return vcpe_tenants[0]
return None
+ @property
+ def subscriber(self):
+ if not self.subscriber_root:
+ return None
+ subs = self.stub.CordSubscriberRoot.objects.filter(id=self.subscriber_root.id)
+ if not subs:
+ return None
+ return subs[0]
+
register_convenience_wrapper("VOLTTenant", ORMWrapperVOLTTenant)
diff --git a/xos/xos_client/xosapi/convenience/vsgtenant.py b/xos/xos_client/xosapi/convenience/vsgtenant.py
index aef9295..d58c757 100644
--- a/xos/xos_client/xosapi/convenience/vsgtenant.py
+++ b/xos/xos_client/xosapi/convenience/vsgtenant.py
@@ -1,6 +1,10 @@
from xosapi.orm import ORMWrapper, register_convenience_wrapper
class ORMWrapperVSGTenant(ORMWrapper):
+ sync_attributes = ("wan_container_ip", "wan_container_mac", "wan_container_netbits",
+ "wan_container_gateway_ip", "wan_container_gateway_mac",
+ "wan_vm_ip", "wan_vm_mac")
+
@property
def volt(self):
if not self.subscriber_tenant: