Skip to main content

Weighted allocation

When multiple resources can be allocated from a pool, you can control the allocation order using weights. Resources with higher weights are allocated first.

Prefix pool & Address pool

While this guide uses IP address pools, the same principles apply to IP prefix pools.

Prerequisites​

The examples on this page require your IP prefix node to inherit from CoreWeightedPoolResource. This adds an allocation_weight attribute to the node.

nodes:
- name: IPPrefix
namespace: Ipam
inherit_from:
- "BuiltinIPPrefix"
- "CoreWeightedPoolResource"

Step 1: Create a low-weight prefix​

Create a prefix with a lower allocation weight:

Navigate to IPAM → IP Prefixes and create a new prefix with:

  • Prefix: 10.100.5.0/24
  • Member Type: address
  • Allocation Weight: 100

Click Save.

Step 2: Create a high-weight prefix​

Create a second prefix with a higher allocation weight:

Navigate to IPAM → IP Prefixes and create a new prefix with:

  • Prefix: 10.100.6.0/24
  • Member Type: address
  • Allocation Weight: 200

Click Save.

Step 3: Create a pool with both prefixes​

Create a CoreIPAddressPool Resource Manager referencing both prefixes:

Navigate to Object Management → Resource Manager and create a new IP Address Pool with:

  • Name: My Weighted IP address pool
  • Default Address Type: IpamIPAddress
  • Default Prefix Length: 24
  • Resources: Select the 10.100.5.0/24 and 10.100.6.0/24 prefixes
  • IP Namespace: default

Step 4: Allocate from the pool​

mutation {
InfrahubIPAddressPoolGetResource(
data: {
hfid: ["My Weighted IP address pool"]
data: {description: "my first allocated ip"}
}
) {
ok
node {
id
display_label
}
}
}
Weighted allocation

You should have received an IP address from the 10.100.6.0/24 prefix, as it has a higher weight (200) than 10.100.5.0/24 (100).

Next​