mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fix handling of duplicate prefixes
This commit is contained in:
@ -105,7 +105,7 @@ def rebuild_prefixes(vrf):
|
||||
for n in stack:
|
||||
n['children'] += 1
|
||||
stack.append({
|
||||
'pk': prefix['pk'],
|
||||
'pk': [prefix['pk']],
|
||||
'prefix': prefix['prefix'],
|
||||
'children': 0,
|
||||
})
|
||||
@ -123,17 +123,16 @@ def rebuild_prefixes(vrf):
|
||||
|
||||
# Handle duplicate prefixes
|
||||
elif stack[-1]['prefix'] == p['prefix']:
|
||||
update_queue.append(
|
||||
Prefix(pk=p['pk'], _depth=len(stack) - 1, _children=stack[-1]['children'])
|
||||
)
|
||||
stack[-1]['pk'].append(p['pk'])
|
||||
|
||||
# If this is a sibling or parent of the most recent prefix, pop nodes from the
|
||||
# stack until we reach a parent prefix (or the root)
|
||||
else:
|
||||
while stack and not contains(stack[-1]['prefix'], p['prefix']):
|
||||
node = stack.pop()
|
||||
for pk in node['pk']:
|
||||
update_queue.append(
|
||||
Prefix(pk=node['pk'], _depth=len(stack), _children=node['children'])
|
||||
Prefix(pk=pk, _depth=len(stack), _children=node['children'])
|
||||
)
|
||||
push_to_stack(p)
|
||||
|
||||
@ -145,8 +144,9 @@ def rebuild_prefixes(vrf):
|
||||
# Clear out any prefixes remaining in the stack
|
||||
while stack:
|
||||
node = stack.pop()
|
||||
for pk in node['pk']:
|
||||
update_queue.append(
|
||||
Prefix(pk=node['pk'], _depth=len(stack), _children=node['children'])
|
||||
Prefix(pk=pk, _depth=len(stack), _children=node['children'])
|
||||
)
|
||||
|
||||
# Final flush of any remaining Prefixes
|
||||
|
Reference in New Issue
Block a user