add ip addresses to vcpe and cordsubscriber objects
diff --git a/xos/cord/models.py b/xos/cord/models.py
index 4bb78b3..a24917a 100644
--- a/xos/cord/models.py
+++ b/xos/cord/models.py
@@ -361,6 +361,23 @@
def services(self, value):
pass
+ @property
+ def addresses(self):
+ if not self.sliver:
+ return {}
+
+ addresses = {}
+ for ns in self.sliver.networkslivers.all():
+ if "lan" in ns.network.name.lower():
+ addresses["lan"] = ns.ip
+ elif "wan" in ns.network.name.lower():
+ addresses["wan"] = ns.ip
+ elif "private" in ns.network.name.lower():
+ addresses["private"] = ns.ip
+ elif "nat" in ns.network.name.lower():
+ addresses["nat"] = ns.ip
+ return addresses
+
def pick_node(self):
nodes = list(Node.objects.all())
# TODO: logic to filter nodes by which nodes are up, and which
diff --git a/xos/core/xoslib/methods/cordsubscriber.py b/xos/core/xoslib/methods/cordsubscriber.py
index 863fcbe..f351552 100644
--- a/xos/core/xoslib/methods/cordsubscriber.py
+++ b/xos/core/xoslib/methods/cordsubscriber.py
@@ -40,13 +40,18 @@
image_name = ReadOnlyField()
routeable_subnet = serializers.CharField(required=False)
+ lan_ip = ReadOnlyField()
+ wan_ip = ReadOnlyField()
+ nat_ip = ReadOnlyField()
+ private_ip = ReadOnlyField()
+
humanReadableName = serializers.SerializerMethodField("getHumanReadableName")
class Meta:
model = CordSubscriber
fields = ('humanReadableName', 'id',
'service_specific_id', 'vlan_id',
- 'vcpe_id', 'sliver', 'sliver_name', 'image', 'image_name', 'firewall_enable', 'firewall_rules', 'url_filter_enable', 'url_filter_rules', 'url_filter_level', 'cdn_enable', 'vbng_id', 'routeable_subnet',)
+ 'vcpe_id', 'sliver', 'sliver_name', 'image', 'image_name', 'firewall_enable', 'firewall_rules', 'url_filter_enable', 'url_filter_rules', 'url_filter_level', 'cdn_enable', 'vbng_id', 'routeable_subnet', 'nat_ip', 'lan_ip', 'wan_ip', 'private_ip')
def getHumanReadableName(self, obj):
diff --git a/xos/core/xoslib/objects/cordsubscriber.py b/xos/core/xoslib/objects/cordsubscriber.py
index 72a9984..38142d4 100644
--- a/xos/core/xoslib/objects/cordsubscriber.py
+++ b/xos/core/xoslib/objects/cordsubscriber.py
@@ -56,6 +56,30 @@
raise AttributeError("getattr: %r object has no attribute %r" %
(self.__class__, key))
+ @property
+ def nat_ip(self):
+ if not self.vcpe:
+ return None
+ return self.vcpe.addresses.get("nat",None)
+
+ @property
+ def lan_ip(self):
+ if not self.vcpe:
+ return None
+ return self.vcpe.addresses.get("lan",None)
+
+ @property
+ def wan_ip(self):
+ if not self.vcpe:
+ return None
+ return self.vcpe.addresses.get("wan",None)
+
+ @property
+ def private_ip(self):
+ if not self.vcpe:
+ return None
+ return self.vcpe.addresses.get("private",None)
+
def __setattr__(self, key, value):
for (member_name, passthrough_name) in self.passthroughs:
if key==member_name: