fix 1238: Provide known ip-address, mac-address at created vnf
vnf is created at database. Instantiation parameters of
ip-address, mac-adddress are populated to the vnf, so that
it is available for jinja2 cloud-init parsing at LCM
Change-Id: Ida091f713219f702b753a044683d9474a2670cc1
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
diff --git a/osm_nbi/base_topic.py b/osm_nbi/base_topic.py
index 5492a8f..9572409 100644
--- a/osm_nbi/base_topic.py
+++ b/osm_nbi/base_topic.py
@@ -65,6 +65,26 @@
return tuple(filled)
+def increment_ip_mac(ip_mac, vm_index=1):
+ if not isinstance(ip_mac, str):
+ return ip_mac
+ try:
+ # try with ipv4 look for last dot
+ i = ip_mac.rfind(".")
+ if i > 0:
+ i += 1
+ return "{}{}".format(ip_mac[:i], int(ip_mac[i:]) + vm_index)
+ # try with ipv6 or mac look for last colon. Operate in hex
+ i = ip_mac.rfind(":")
+ if i > 0:
+ i += 1
+ # format in hex, len can be 2 for mac or 4 for ipv6
+ return ("{}{:0" + str(len(ip_mac) - i) + "x}").format(ip_mac[:i], int(ip_mac[i:], 16) + vm_index)
+ except Exception:
+ pass
+ return None
+
+
class BaseTopic:
# static variables for all instance classes
topic = None # to_override