X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNBI.git;a=blobdiff_plain;f=osm_nbi%2Fbase_topic.py;h=bbe63377cae19ad22594209c30b2ed50f5df9778;hp=5492a8f2798177411e320a2e2163ef9c74a62e8b;hb=341ac1bac7b115d64a50ec166aa5e6d186b39443;hpb=19b9752a7f43e1fcf1bdfd0040c1e8edfe9e6f3a;ds=inline diff --git a/osm_nbi/base_topic.py b/osm_nbi/base_topic.py index 5492a8f..bbe6337 100644 --- a/osm_nbi/base_topic.py +++ b/osm_nbi/base_topic.py @@ -65,6 +65,26 @@ def versiontuple(v): 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 @@ -127,7 +147,7 @@ class BaseTopic: if count >= quota: name = proj["name"] raise ValidationError("quota ({}={}) exceeded for project {} ({})".format(quota_name, quota, name, pid), - http_code=HTTPStatus.UNAUTHORIZED) + http_code=HTTPStatus.UNPROCESSABLE_ENTITY) def _validate_input_new(self, input, force=False): """ @@ -288,6 +308,7 @@ class BaseTopic: def _send_msg(self, action, content, not_send_msg=None): if self.topic_msg and not_send_msg is not False: + content = content.copy() content.pop("_admin", None) if isinstance(not_send_msg, list): not_send_msg.append((self.topic_msg, action, content))