Skip to content

Commit 6944dc9

Browse files
authored
Weighted pool allocation docs and attribute description (#6518)
* Add docs * Add attribute description * add inherited generic
1 parent e2bf321 commit 6944dc9

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

.vale/styles/spelling-exceptions.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
agent
22
Alibaba
3+
allocation_weight
34
Ansible
45
anonymized
56
append_git_suffix

backend/infrahub/core/schema/definitions/core/resource_pool.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,16 @@
4040
include_in_menu=False,
4141
branch=BranchSupportType.AWARE,
4242
generate_profile=False,
43-
attributes=[Attr(name="allocation_weight", label="Weight", kind="Number", optional=True, order_weight=10000)],
43+
attributes=[
44+
Attr(
45+
name="allocation_weight",
46+
label="Weight",
47+
description="Weight determines allocation priority, resources with higher values are selected first.",
48+
kind="Number",
49+
optional=True,
50+
order_weight=10000,
51+
)
52+
],
4453
)
4554

4655
core_ip_prefix_pool = NodeSchema(

docs/docs/guides/resource-manager.mdx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,40 @@ Execute this mutation twice, note the identifier. The resulting IP prefix should
524524

525525
:::
526526

527+
:::success Weighted allocation of an IP prefix
528+
529+
When multiple resources are managed by a resource manager and need to be allocated in a specific order, you can assign weights to control that behavior.
530+
531+
To enable this, update your schema to inherit from the `CoreWeightedPoolResource` generic. This adds the `allocation_weight` attribute to your Prefix resource.
532+
533+
Set a value for allocation_weight when creating the Prefix. **Higher values are preferred first during allocation**.
534+
535+
<Tabs>
536+
<TabItem value="YAML" label="Schema update">
537+
538+
```yaml
539+
nodes:
540+
- name: IPPrefix
541+
namespace: Ipam
542+
include_in_menu: false
543+
inherit_from:
544+
- "BuiltinIPPrefix"
545+
- "CoreWeightedPoolResource"
546+
description: "IPv4 or IPv6 network"
547+
label: "IP Prefix"
548+
relationships:
549+
- name: vlan
550+
peer: IpamVLAN
551+
optional: true
552+
cardinality: one
553+
kind: Attribute
554+
```
555+
556+
</TabItem>
557+
</Tabs>
558+
559+
:::
560+
527561
## Using number pool
528562

529563
A `CoreNumberPool` is connected to a node's numeric attribute. It lets you automatically assign numbers from a set range as values for that attribute.

docs/docs/topics/resource-manager.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ A resource manager in Infrahub allocates resources in a branch agnostic way. Whe
1717

1818
Depending on how you use the resource manager, it can allocate resources in an idempotent way. This is helpful when you want to use generators that have to behave in an idempotent way.
1919

20+
Resources that inherit from `CoreWeightedPoolResource` have an `allocation_weight` attribute, which lets you influence allocation order. Resources with higher weights are preferred first when allocating a Prefix or IP Address from a pool.
21+
2022
Resources can be allocated in 2 different ways:
2123

2224
- Direct allocation: A direct allocation is typically used when you don't need the resource to be related to another node in Infrahub, or if you want establish such a relation at a later time. For example, you want to allocated an IP address out of a pool that is not going to be linked to another node in Infrahub.

0 commit comments

Comments
 (0)