Skip to content

Commit 6f5a8d3

Browse files
author
earthmant
committed
rework port fixed ips handling logic
1 parent ddcd226 commit 6f5a8d3

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

neutron_plugin/port.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -286,20 +286,18 @@ def _handle_fixed_ips(port):
286286
if subnet_id:
287287
fixed_ips_element['subnet_id'] = subnet_id
288288

289-
if 'fixed_ips' not in port and not fixed_ips_element:
290-
return
291-
292-
elif 'fixed_ips' not in port and fixed_ips_element:
293-
port['fixed_ips'] = [fixed_ips_element]
294-
295-
addresses = [ip.get('ip_address') for ip in port['fixed_ips']]
296-
subnets = [net.get('subnet_id') for net in port['fixed_ips']]
297-
289+
fixed_ips = port.get(
290+
'fixed_ips',
291+
[] if not fixed_ips_element else [fixed_ips_element])
292+
addresses = [ip.get('ip_address') for ip in fixed_ips]
293+
subnets = [net.get('subnet_id') for net in fixed_ips]
298294
# applying fixed ip parameter, if available
299295
if fixed_ips_element and not \
300296
(fixed_ips_element.get('ip_address') in addresses or
301297
fixed_ips_element.get('subnet_id') in subnets):
302-
port['fixed_ips'] = [fixed_ips_element]
298+
fixed_ips.append(fixed_ips_element)
299+
if fixed_ips:
300+
port['fixed_ips'] = fixed_ips
303301

304302

305303
def _handle_security_groups(port):

0 commit comments

Comments
 (0)