plumb through delete-vBNG API call
diff --git a/xos/cord/models.py b/xos/cord/models.py
index 37b9bd9..5c5d972 100644
--- a/xos/cord/models.py
+++ b/xos/cord/models.py
@@ -607,7 +607,8 @@
KIND = "vBNG"
- default_attributes = {"routeable_subnet": ""}
+ default_attributes = {"routeable_subnet": "",
+ "mapped_ip": ""}
@property
def routeable_subnet(self):
@@ -616,3 +617,11 @@
@routeable_subnet.setter
def routeable_subnet(self, value):
self.set_attribute("routeable_subnet", value)
+
+ @property
+ def mapped_ip(self):
+ return self.get_attribute("mapped_ip", self.default_attributes["mapped_ip"])
+
+ @mapped_ip.setter
+ def mapped_ip(self, value):
+ self.set_attribute("mapped_ip", value)
diff --git a/xos/observers/vbng/steps/sync_vbngtenant.py b/xos/observers/vbng/steps/sync_vbngtenant.py
index dfcbabb..b0dd345 100644
--- a/xos/observers/vbng/steps/sync_vbngtenant.py
+++ b/xos/observers/vbng/steps/sync_vbngtenant.py
@@ -37,11 +37,10 @@
return objs
def defer_sync(self, o, reason):
+ logger.info("defer object %s due to %s" % (str(o), reason))
raise Exception("defer object %s due to %s" % (str(o), reason))
- def sync_record(self, o):
- logger.info("sync'ing VBNGTenant %s" % str(o))
-
+ def get_private_ip(self, o):
vcpes = VCPETenant.get_tenant_objects().all()
vcpes = [x for x in vcpes if (x.vbng is not None) and (x.vbng.id == o.id)]
if not vcpes:
@@ -64,17 +63,31 @@
self.defer_sync(o, "WAN network is not filled in yet")
return
- private_ip = external_ns.ip
+ return external_ns.ip
+
+ def sync_record(self, o):
+ logger.info("sync'ing VBNGTenant %s" % str(o))
if not o.routeable_subnet:
+ private_ip = self.get_private_ip(o)
+ logger.info("contacting vBNG service to request mapping for private ip %s" % private_ip)
+
r = requests.post(VBNG_API + "%s" % private_ip, )
if (r.status_code != 200):
raise Exception("Received error from bng service (%d)" % r.status_code)
logger.info("received public IP %s from private IP %s" % (r.text, private_ip))
o.routeable_subnet = r.text
+ o.mapped_ip = private_ip
o.save()
- def delete_record(self, m):
- pass
+ def delete_record(self, o):
+ logger.info("deleting VBNGTenant %s" % str(o))
+
+ if o.mapped_ip:
+ private_ip = o.mapped_ip
+ logger.info("contacting vBNG service to delete private ip %s" % private_ip)
+ r = requests.delete(VBNG_API + "%s" % private_ip, )
+ if (r.status_code != 200):
+ raise Exception("Received error from bng service (%d)" % r.status_code)
diff --git a/xos/observers/vcpe/steps/sync_vcpetenant.py b/xos/observers/vcpe/steps/sync_vcpetenant.py
index 8d85601..fcfc982 100644
--- a/xos/observers/vcpe/steps/sync_vcpetenant.py
+++ b/xos/observers/vcpe/steps/sync_vcpetenant.py
@@ -30,6 +30,7 @@
SyncStep.__init__(self, **args)
def defer_sync(self, o, reason):
+ logger.info("defer object %s due to %s" % (str(o), reason))
raise Exception("defer object %s due to %s" % (str(o), reason))
def fetch_pending(self, deleted):