Skip to main content

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_range and end_range of each pool into one range with the same bounds. Each pool keeps the numbers it allocated.
  • start_range and end_range keep 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_range and end_range return 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_range and end_range. The version is not announced yet. After that version, schema files, scripts and queries that still use start_range or end_range fail. 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:

You also need to act in these cases:

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 NumberPool attribute declares none of start_range, end_range and ranges. Its pool holds one range from 1 to 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.

Load the schema​

If you use Git integration, commit the changes and let Infrahub import them.

If you use infrahubctl:

  1. Check the schema:

    infrahubctl schema check path/to/your/schema/files
  2. Load it on the default branch:

    infrahubctl schema load path/to/your/schema/files

The load returns a deprecation warning for each attribute that still uses start_range or end_range.

success

If the load returns no deprecation warning and every NumberPool attribute that sets bounds declares ranges, your schema files are migrated.

Migrate code that creates or updates pools​

These pools are the ones you create with a GraphQL mutation, the Python SDK or a Generator. In GraphQL and the Python SDK, their pool_type is User.

From 1.12, creating a pool or changing its ranges also creates, updates or deletes CoreNumberPoolRange objects. Grant the accounts that run your scripts and Generators the matching create, update and delete permissions on CoreNumberPoolRange, in addition to their permissions on CoreNumberPool.

Prompt for AI assisted refactoring

Copy this prompt into your AI coding agent at the root of the repository that holds your scripts and Generators. Review each change before you run the code.

# Task: Migrate code that creates or updates Infrahub number pools 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

### 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.

### 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.

## Instructions

1. Find every GraphQL mutation and every Python SDK call that creates or updates a `CoreNumberPool` with `start_range` or `end_range`, in Python code, in `.gql` and `.graphql` files, and in GraphQL strings inside the code.
2. Apply the migration rule that matches each of them.
3. 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.

In GraphQL​

Create a pool​

Before:

mutation {
CoreNumberPoolCreate(
data: {
name: {value: "VLAN ID pool"}
node: {value: "IpamVLAN"}
node_attribute: {value: "vlan_id"}
start_range: {value: 100}
end_range: {value: 1000}
}
) {
ok
}
}

After:

mutation {
CoreNumberPoolCreate(
data: {
name: {value: "VLAN ID pool"}
node: {value: "IpamVLAN"}
node_attribute: {value: "vlan_id"}
ranges: [{start: 100, end: 1000}]
}
) {
ok
}
}

A range can leave out start or end, for example ranges: [{start: 100}]. Infrahub then reads the missing bound from the attribute the pool allocates for:

  • A range without a start begins at the min_value of the attribute, or at 1 when the attribute has no min_value or a min_value below 1.
  • A range without an end stops at the max_value of the attribute, or at the largest number Infrahub supports when the attribute has no max_value.

Update a pool​

ranges replaces all the ranges of the pool. Send both bounds of the range, even when the old mutation changed only one. Read the stored bound first, as described in Migrate code that reads pools. The example below keeps the stored start, 100.

Before:

mutation {
CoreNumberPoolUpdate(
data: {
id: "<POOL-ID>"
end_range: {value: 2000}
}
) {
ok
}
}

After:

mutation {
CoreNumberPoolUpdate(
data: {
id: "<POOL-ID>"
ranges: [{start: 100, end: 2000}]
}
) {
ok
}
}

With the Python SDK and in Generators​

The SDK takes the same fields as GraphQL. Each range is a dictionary with start, end and allocation_weight, and each of them can be left out.

Create a pool​

Before:

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:

pool = await client.create(
kind="CoreNumberPool",
name="VLAN ID pool",
node="IpamVLAN",
node_attribute="vlan_id",
ranges=[{"start": 100, "end": 1000}],
)
await pool.save()

Update a pool​

To change the ranges of an existing pool, declare the pool with its complete list of ranges and save it with allow_upsert=True. When the old code changed only one bound, read the stored bounds first, as described in Migrate code that reads pools, and keep the stored value for the other bound. Infrahub finds the pool by its name, keeps the ranges whose bounds match, creates the new ones and deletes the others.

Before:

pool = await client.get(kind="CoreNumberPool", name__value="VLAN ID pool")
pool.end_range.value = 2000
await pool.save()

After:

pool = await client.create(
kind="CoreNumberPool",
name="VLAN ID pool",
node="IpamVLAN",
node_attribute="vlan_id",
ranges=[{"start": 100, "end": 2000}],
)
await pool.save(allow_upsert=True)
warning

Do not change ranges with add(), extend() or remove() on the ranges relationship of the pool. The CoreNumberPool mutations accept ranges as bounds, not as references to CoreNumberPoolRange objects.

Migrate code that reads pools​

This applies to every pool, whether a NumberPool attribute or your own code created it. Before 1.12, a pool held one range, so code read start_range and end_range. A pool can now hold several ranges, so loop over all of them.

Prompt for AI assisted refactoring

Copy this prompt into your AI coding agent at the root of the repository that holds your scripts and queries. Review each change before you run the code.

# Task: Migrate code that reads Infrahub number pools 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

### 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 GraphQL query and every Python SDK call that reads `start_range` or `end_range` of a `CoreNumberPool`.
2. Apply the migration rule to each of them.
3. List every file you changed, and every place where the code assumes that a pool holds one range.

## 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.

In GraphQL​

Before:

query {
CoreNumberPool(ids: ["<POOL-ID>"]) {
edges {
node {
start_range { value }
end_range { value }
}
}
}
}

After:

query {
CoreNumberPool(ids: ["<POOL-ID>"]) {
edges {
node {
ranges {
edges {
node {
start { value }
end { value }
allocation_weight { value }
}
}
}
}
}
}
}

start and end return null for a range without that bound.

With the Python SDK​

Before:

pool = await client.get(kind="CoreNumberPool", name__value="VLAN ID pool")
print(pool.start_range.value, pool.end_range.value)

After:

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)

start.value and end.value are None for a range without that bound.

Separate pools that overlap on a unique attribute​

From 1.12, Infrahub refuses a range that overlaps a range of another pool for the same kind and unique attribute, as described in Pools for the same unique attribute. Infrahub checks ranges only when you save them, so pools whose ranges overlapped before the upgrade still overlap after it.

When one of those pools allocates a number that the other pool tracks for an object, Infrahub refuses the save. The error names the pool, the number, the object that holds the number and the other pool.

To separate the two pools:

  1. Choose the pool that keeps the numbers in the overlap.
  2. List the numbers the other pool tracks in the overlap, in its allocations table or with InfrahubNumberPoolAllocations, as described in View how much of a pool is in use.
  3. Attach each of those numbers to the pool you chose. To do so, update the object with the number as value and that pool as from_pool. Infrahub removes the number from the other pool, as described in Move a number to another pool.
  4. Change the ranges of the other pool so that they no longer overlap, as described in Change the ranges of a pool. Infrahub refuses this change while the pool still tracks a number outside its new ranges. For a pool that a NumberPool attribute creates, change the ranges in the schema, as described in Update the schema files.