Skip to content

Commit

Permalink
Merge pull request #355 from SUNET/bugfix.initcheck_dist_linknet_offset
Browse files Browse the repository at this point in the history
Bugfix.initcheck dist linknet offset
  • Loading branch information
indy-independence authored Jun 26, 2024
2 parents 1149290 + be0e002 commit f425c2a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/cnaas_nms/devicehandler/underlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ def find_free_mgmt_lo_ip(session) -> Optional[IPv4Address]:
return None


def find_free_infra_linknet(session) -> Optional[IPv4Network]:
def find_free_infra_linknet(session, offset: int = 0) -> Optional[IPv4Network]:
"""Returns first free IPv4 infra linknet (/31)."""
used_linknets = []
current_offset = offset
linknet_query = session.query(Linknet).filter(Linknet.device_a_ip.isnot(None))
ln: Linknet
for ln in linknet_query:
Expand All @@ -65,6 +66,9 @@ def find_free_infra_linknet(session) -> Optional[IPv4Network]:
for num, net in enumerate(infra_ip_net.subnets(new_prefix=31)):
if net in used_linknets:
continue
elif current_offset > 0:
current_offset -= 1
continue
else:
return net
return None
8 changes: 6 additions & 2 deletions src/cnaas_nms/devicehandler/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def update_linknets(
)
)

for local_if, data in neighbors.items():
for idx, (local_if, data) in enumerate(neighbors.items()):
logger.debug(f"Local: {local_if}, remote: {data[0]['hostname']} {data[0]['port']}")
remote_device_inst: Device = session.query(Device).filter(Device.hostname == data[0]["hostname"]).one_or_none()
if not remote_device_inst:
Expand Down Expand Up @@ -339,7 +339,11 @@ def update_linknets(
DeviceType.CORE,
DeviceType.DIST,
]:
ipv4_network = find_free_infra_linknet(session)
if dry_run:
# dry_run requires linknet offset since linknet IPs are not added to database
ipv4_network = find_free_infra_linknet(session, idx)
else:
ipv4_network = find_free_infra_linknet(session)
else:
ipv4_network = None
new_link = Linknet.create_linknet(
Expand Down

0 comments on commit f425c2a

Please sign in to comment.