Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch Info use same format as expected in Java... #327

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/python/SiteFE/LookUpService/modules/switchinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Date: 2021/12/01
"""
from SiteRMLibs.ipaddr import validMRMLName
from SiteRMLibs.ipaddr import normalizeipdict
from SiteRMLibs.ipaddr import replaceSpecialSymbols
from SiteRMLibs.CustomExceptions import NoOptionError
from SiteRMLibs.CustomExceptions import NoSectionError
Expand Down Expand Up @@ -73,7 +74,7 @@ def _genIPv6(cls, inval, inkey, esc=True):
return f"{inval['address']}/{subnet}"
cls.logger.debug('One of params in Dict not available. Upredictable output')
if isinstance(inval, list):
tmpKeys = [{'key': inkey, 'subkey': _genIPv6(cls, val, inkey), 'val': val} for val in inval]
tmpKeys = [{'key': inkey, 'subkey': _genIPv6(cls, val, inkey), 'val': normalizeipdict(val)} for val in inval]
return tmpKeys
cls.logger.debug(f'No IPv6 value. Return empty String. This might break things. Input: {inval} {inkey}')
return ''
Expand Down
9 changes: 8 additions & 1 deletion src/python/SiteRMLibs/ipaddr.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ def normalizedipwithnet(ipInput, netmask):
tmpNet = netmask.split('/')
return normalizedip(f"{ipInput}/{tmpNet[1]}")

def normalizeipdict(ipdict):
"""Normalize IP in a dictionary"""
if isinstance(ipdict, dict) and 'address' in ipdict:
tmpval = normalizedip(ipdict['address'])
ipdict['address'] = tmpval
return ipdict

def normalizedip(ipInput):
"""
Expand All @@ -44,9 +50,10 @@ def normalizedip(ipInput):
tmp = ipInput.split('/')
ipaddr = None
try:
ipaddr = ip_address(tmp[0]).compressed
ipaddr = ip_address(tmp[0]).exploded
except ValueError:
ipaddr = tmp[0]
ipaddr = _ipv6InJavaFormat(ipaddr)
if len(tmp) == 2:
return f"{ipaddr}/{tmp[1]}"
if len(tmp) == 1:
Expand Down