phsm commented on code in PR #10594:
URL: https://github.com/apache/cloudstack/pull/10594#discussion_r2626235037
##########
scripts/vm/network/security_group.py:
##########
@@ -131,20 +134,37 @@ def ipv6_link_local_addr(mac=None):
return ipaddress.ip_address('fe80::' + ':'.join(re.findall(r'.{4}',
eui64)))
-def split_ips_by_family(ips):
- if type(ips) is str:
- ips = [ip for ip in ips.split(';') if ip != '']
+def split_ips_by_family(*addresses):
+ """
+ Takes one or more IP addresses as the input, and returns two lists:
+ one for ipv4 addresses, one for ipv6 addresses
+
+ If one of the inputs is a string, it tries to split it by semicolon,
+ and ignores the empty fields, or the fields with the value '0'
+ """
+ ips = []
+ for i in addresses:
+ if not i: # IP address can be sometimes None (e.g. when ipv6 address
not present)
+ continue
+ if type(i) is str:
+ ips += [ip for ip in i.split(';') if ip != '' and ip != '0']
+ else:
+ ips.append(str(i))
Review Comment:
I've rechecked this function.
It has 2 for loops:
The first does the initial parse and splits some of the elements. The result
is stored in the intermediate `ips` list that is not returned back. This is
the forloop you're referring to.
The second for loop does the precise sort into lists `ip4s` and `ip6s` using
python ipaddress library. And those are the lists returned by the function.
Of course I could redo it into a single forloop, but back then I decided to
have it more verbose for the readability.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]