X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=osm_nbi%2Fbase_topic.py;h=c67ec76903d0ed686279376b278535bfb31fa63e;hb=f3ea2ed8d6932d3709e15a8f69a34f57405bb740;hp=5492a8f2798177411e320a2e2163ef9c74a62e8b;hpb=19b9752a7f43e1fcf1bdfd0040c1e8edfe9e6f3a;p=osm%2FNBI.git diff --git a/osm_nbi/base_topic.py b/osm_nbi/base_topic.py index 5492a8f..c67ec76 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): """