Skip to content

Commit

Permalink
Run IPAM reconcilement after assignment from pool
Browse files Browse the repository at this point in the history
Runs the IPAM reconcilement process when assigning an IP address or
prefix from a pool. Without this utilization or hierarchy isn't
recalculated.
  • Loading branch information
ogenstad committed May 21, 2024
1 parent 5493efe commit d0d2a8f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import TYPE_CHECKING, Any, Optional

from infrahub.core import registry
from infrahub.core.ipam.reconciler import IpamReconciler
from infrahub.core.query.ipam import get_ip_addresses
from infrahub.core.query.resource_manager import (
IPAddressPoolGetReserved,
Expand Down Expand Up @@ -65,6 +66,8 @@ async def get_resource(
node = await Node.init(db=db, schema=target_schema, branch=branch)
await node.new(db=db, address=str(next_prefix), ip_namespace=ip_namespace, **data)
await node.save(db=db)
reconciler = IpamReconciler(db=db, branch=branch)
await reconciler.reconcile(ip_value=next_prefix, namespace=ip_namespace.id, node_uuid=node.get_id())

if identifier:
query_set = await IPAddressPoolSetReserved.init(
Expand Down
3 changes: 3 additions & 0 deletions backend/infrahub/core/node/resource_manager/ip_prefix_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import TYPE_CHECKING, Any, Optional

from infrahub.core import registry
from infrahub.core.ipam.reconciler import IpamReconciler
from infrahub.core.query.ipam import get_subnets
from infrahub.core.query.resource_manager import (
PrefixPoolGetReserved,
Expand Down Expand Up @@ -69,6 +70,8 @@ async def get_resource(
node = await Node.init(db=db, schema=target_schema, branch=branch)
await node.new(db=db, prefix=str(next_prefix), member_type=member_type, ip_namespace=ip_namespace, **data)
await node.save(db=db)
reconciler = IpamReconciler(db=db, branch=branch)
await reconciler.reconcile(ip_value=next_prefix, namespace=ip_namespace.id, node_uuid=node.get_id())

if identifier:
query_set = await PrefixPoolSetReserved.init(
Expand Down

0 comments on commit d0d2a8f

Please sign in to comment.