How to migrate number pools to ranges
Before Infrahub 1.12, a number pool held one range, set with start_range and end_range. From Infrahub 1.12, a number pool holds a list of ranges, set with ranges. start_range and end_range are deprecated.
What the deprecation means for you​
- The upgrade to 1.12 needs no change to your schema files, scripts or queries. It converts the
start_rangeandend_rangeof each pool into one range with the same bounds. Each pool keeps the numbers it allocated. start_rangeandend_rangekeep working on a pool that holds one range. A schema load that uses them returns a deprecation warning, and the GraphQL schema marks them as deprecated.- On a pool that holds several ranges,
start_rangeandend_rangereturn null, and setting them returns an error that lists the ranges to change instead. Migrate the code that uses a pool before you add a second range to it. - A later version of Infrahub will remove
start_rangeandend_range. The version is not announced yet. After that version, schema files, scripts and queries that still usestart_rangeorend_rangefail. Migrate them now instead of waiting for the removal.
Find what you need to migrate​
Search your schema files, scripts, Generators and GraphQL queries for start_range and end_range. Each match is one of these cases:
- A
NumberPoolattribute declaresstart_rangeorend_rangein itsparameters. Follow MigrateNumberPoolattributes in your schema. - A GraphQL mutation, a Python SDK script or a Generator creates or updates a
CoreNumberPoolwithstart_rangeorend_range. Follow Migrate code that creates or updates pools. - A GraphQL query or a Python SDK script reads the
start_rangeorend_rangeof a pool. Follow Migrate code that reads pools.
You also need to act in these cases:
- You run
infrahubctlor the Python SDK outside Infrahub, for example on a laptop, in a CI pipeline or in another application. Follow Upgrade infrahubctl and the Python SDK. - Two pools allocate numbers for the same unique attribute and their ranges overlap. Follow Separate pools that overlap on a unique attribute.
You have nothing to migrate in these cases:
- You create and edit pools only in the web interface. From 1.12, the pool form sets ranges.
- A
NumberPoolattribute declares none ofstart_range,end_rangeandranges. Its pool holds one range from1to the largest number Infrahub supports, as before 1.12.
Migrate with an AI coding agent​
The prompt below covers every case on this page. Each migration section also has a prompt for that case only.
Prompt for AI assisted refactoring
Copy this prompt into your AI coding agent at the root of the repository that holds your schema files and code. Review each change before you load the schema or run the code.
# Task: Migrate Infrahub number pools from start_range and end_range to ranges
## Context
Infrahub 1.12 deprecates the `start_range` and `end_range` fields of number pools in favor of `ranges`, a list of ranges. Each range has `start`, `end` and `allocation_weight`, and each of them is optional. A later version of Infrahub removes `start_range` and `end_range`.
## Migration rules
### 1. NumberPool attributes in schema files
In the `parameters` of each attribute with `kind: NumberPool`, replace `start_range` and `end_range` with one range under `ranges`.
Before:
```yaml
parameters:
start_range: 100
end_range: 4094
```
After:
```yaml
parameters:
ranges:
- start: 100
end: 4094
```
When only one of the two is set, write only that bound, for example `- start: 100`. Do not keep `start_range` or `end_range` next to `ranges`.
### 2. GraphQL mutations that create or update a CoreNumberPool
Before:
```graphql
start_range: {value: 100}
end_range: {value: 1000}
```
After:
```graphql
ranges: [{start: 100, end: 1000}]
```
In `CoreNumberPoolUpdate` and `CoreNumberPoolUpsert`, `ranges` replaces all the ranges of the pool, so send both bounds. When the old mutation set only one bound, read the stored bounds of the pool first and send the stored value for the other bound.
### 3. Python SDK code that creates or updates a CoreNumberPool
Before:
```python
pool = await client.create(
kind="CoreNumberPool",
name="VLAN ID pool",
node="IpamVLAN",
node_attribute="vlan_id",
start_range=100,
end_range=1000,
)
await pool.save()
```
After:
```python
pool = await client.create(
kind="CoreNumberPool",
name="VLAN ID pool",
node="IpamVLAN",
node_attribute="vlan_id",
ranges=[{"start": 100, "end": 1000}],
)
await pool.save()
```
For code that sets `start_range.value` or `end_range.value` on an existing pool, declare the pool with `client.create()` with the same `name`, `node` and `node_attribute` and the complete `ranges` list, then call `save(allow_upsert=True)`. When the old code set only one bound, read the stored bounds first and keep the stored value for the other bound.
### 4. Code that reads start_range or end_range
Read the `ranges` relationship of the pool instead, and loop over every range. `start` and `end` are null for a range without that bound.
GraphQL before:
```graphql
start_range { value }
end_range { value }
```
GraphQL after:
```graphql
ranges {
edges {
node {
start { value }
end { value }
allocation_weight { value }
}
}
}
```
Python SDK after:
```python
pool = await client.get(kind="CoreNumberPool", name__value="VLAN ID pool", include=["ranges"])
await pool.ranges.fetch()
for pool_range in pool.ranges.peers:
print(pool_range.peer.start.value, pool_range.peer.end.value, pool_range.peer.allocation_weight.value)
```
## Instructions
1. Find every use of `start_range` and `end_range` in YAML and JSON schema files, in Python code, in `.gql` and `.graphql` files, and in GraphQL strings inside the code.
2. Apply the migration rule that matches each use.
3. Where the repository sets a version of `infrahub-sdk`, for example in `pyproject.toml` or `requirements.txt`, require 1.24.0 or later.
4. List every file you changed and every place you left for review.
## Notes
- Do not change the bounds of any range.
- Ignore uses of `start_range` and `end_range` that are not about Infrahub number pools.
- When a change is unclear, leave the code as it is and report it.
- Do not use `add()`, `extend()` or `remove()` on the `ranges` relationship of a pool.
The agent finds only what is in the repository it reads. Repeat the prompt for each repository that holds schema files or code that uses number pools.
Upgrade infrahubctl and the Python SDK​
With Infrahub 1.12, use infrahub-sdk version 1.24.0 or later wherever you run infrahubctl or the Python SDK yourself:
pip install --upgrade 'infrahub-sdk[ctl]>=1.24.0'
Earlier versions do not support ranges, and can create a pool with the wrong ranges without returning an error.
Generators, Transformations and checks that Infrahub runs from a Git repository use the SDK installed with Infrahub, so they need no upgrade. When you run a Generator with infrahubctl on your own machine, it uses your local SDK.
Migrate NumberPool attributes in your schema​
Infrahub creates one pool for each NumberPool attribute of your schema and sets the ranges of that pool from the parameters of the attribute. You change these ranges only in the schema.
Prompt for AI assisted refactoring
Copy this prompt into your AI coding agent at the root of the repository that holds your schema files. Review each change before you load the schema.
# Task: Migrate NumberPool attributes from start_range and end_range to ranges
## Context
Infrahub 1.12 deprecates the `start_range` and `end_range` fields of number pools in favor of `ranges`, a list of ranges. Each range has `start`, `end` and `allocation_weight`, and each of them is optional. A later version of Infrahub removes `start_range` and `end_range`.
## Migration rule
### NumberPool attributes in schema files
In the `parameters` of each attribute with `kind: NumberPool`, replace `start_range` and `end_range` with one range under `ranges`.
Before:
```yaml
parameters:
start_range: 100
end_range: 4094
```
After:
```yaml
parameters:
ranges:
- start: 100
end: 4094
```
When only one of the two is set, write only that bound, for example `- start: 100`. Do not keep `start_range` or `end_range` next to `ranges`.
## Instructions
1. Find every attribute with `kind: NumberPool` in the YAML and JSON schema files whose `parameters` set `start_range` or `end_range`.
2. Apply the migration rule to each of them.
3. List the attributes you changed.
## Notes
- Do not change the bounds of any range.
- Ignore uses of `start_range` and `end_range` that are not about Infrahub number pools.
- When a change is unclear, leave the code as it is and report it.
Update the schema files​
In the parameters of each NumberPool attribute, replace start_range and end_range with one range under ranges. Each range has a start and an end, both included.
When the attribute declares both bounds:
# Before
parameters:
start_range: 100
end_range: 4094
# After
parameters:
ranges:
- start: 100
end: 4094
When the attribute declares one bound, declare only that bound:
# Before
parameters:
start_range: 100
# After
parameters:
ranges:
- start: 100
A range without a start begins at 1, and a range without an end stops at the largest number Infrahub supports, so the pool allocates from the same numbers as before.
Remove start_range and end_range when you add ranges. Infrahub refuses a schema that declares both, with the error start_range/end_range cannot be combined with ranges.