CORD-1008 add convenience wrappers for CordSubscriberRoot and VOLTTenant
Change-Id: Ie9b657a15eeeba647952a7f29faafa13035b6fb7
diff --git a/xos/xos_client/xosapi/convenience/cordsubscriberroot.py b/xos/xos_client/xosapi/convenience/cordsubscriberroot.py
new file mode 100644
index 0000000..e722468
--- /dev/null
+++ b/xos/xos_client/xosapi/convenience/cordsubscriberroot.py
@@ -0,0 +1,12 @@
+from xosapi.orm import ORMWrapper, register_convenience_wrapper
+
+class ORMWrapperCordSubscriberRoot(ORMWrapper):
+ @property
+ def volt(self):
+ volt_tenants = self.stub.VOLTTenant.objects.filter(subscriber_root_id = self.id)
+ if volt_tenants:
+ return volt_tenants[0]
+ return None
+
+
+register_convenience_wrapper("CordSubscriberRoot", ORMWrapperCordSubscriberRoot)
diff --git a/xos/xos_client/xosapi/convenience/volttenant.py b/xos/xos_client/xosapi/convenience/volttenant.py
new file mode 100644
index 0000000..b3645e2
--- /dev/null
+++ b/xos/xos_client/xosapi/convenience/volttenant.py
@@ -0,0 +1,12 @@
+from xosapi.orm import ORMWrapper, register_convenience_wrapper
+
+class ORMWrapperVOLTTenant(ORMWrapper):
+ @property
+ def vcpe(self):
+ vcpe_tenants = self.stub.VSGTenant.objects.filter(subscriber_tenant_id = self.id)
+ if vcpe_tenants:
+ return vcpe_tenants[0]
+ return None
+
+
+register_convenience_wrapper("VOLTTenant", ORMWrapperVOLTTenant)
diff --git a/xos/xos_client/xosapi/orm.py b/xos/xos_client/xosapi/orm.py
index d113835..dc84c96 100644
--- a/xos/xos_client/xosapi/orm.py
+++ b/xos/xos_client/xosapi/orm.py
@@ -92,7 +92,7 @@
dest_model = self.stub.invoke("Get%s" % fk_entry["modelName"], id)
elif fk_kind=="generic_fk":
- dest_model = self.stub.genericForeignKeyResolve(getattr(self, fk_entry["ct_fieldName"]), fk_id)
+ dest_model = self.stub.genericForeignKeyResolve(getattr(self, fk_entry["ct_fieldName"]), fk_id)._wrapped_class
else:
raise Exception("unknown fk_kind")
@@ -195,6 +195,10 @@
return d
@property
+ def model_name(self):
+ return self._wrapped_class.__class__.__name__
+
+ @property
def ansible_tag(self):
return "%s_%s" % (self._wrapped_class.__class__.__name__, self.id)
@@ -419,4 +423,6 @@
return cls(wrapped_class, *args, **kwargs)
import convenience.instance
+import convenience.cordsubscriberroot
+import convenience.volttenant