Skip to main content

Allocate resources from pools

Object templates support automatic resource allocation. This guide extends the device and interface example from Use object templates to show how to wire a CoreIPAddressPool to the interface template so that IP addresses are allocated automatically on object creation.

Prerequisites​

Schema extension used in this guide

Add the two IPAM nodes and an ip_address relationship to InfraInterface. Adapt the type names to match your own schema.

---
# yaml-language-server: $schema=https://schema.infrahub.app/infrahub/schema/latest.json
version: "1.0"

nodes:
- name: IPAddress
namespace: Ipam
label: "IP Address"
display_label: "{{ address__value }}"
inherit_from:
- BuiltinIPAddress

- name: IPPrefix
namespace: Ipam
label: "IP Prefix"
display_label: "{{ prefix__value }}"
inherit_from:
- BuiltinIPPrefix

- name: Interface
namespace: Infra
label: "Interface"
include_in_menu: true
icon: "mdi:ethernet"
display_label: "{{ name__value }}"
order_by:
- name__value
uniqueness_constraints:
- ["device", "name__value"]
human_friendly_id: ["device__name__value", "name__value"]
attributes:
- name: name
kind: Text
- name: description
kind: Text
optional: true
- name: enable
kind: Boolean
optional: false
default_value: false
relationships:
- name: device
peer: InfraDevice
optional: false
cardinality: one
kind: Parent
- name: ip_address
peer: IpamIPAddress
optional: true
cardinality: one
kind: Attribute

Once IpamIPAddress is in the schema, Infrahub automatically generates an ip_address_from_resource_pool field on TemplateInfraInterface — this is what connects the template to the pool.

Load the schema before continuing:

infrahubctl schema load /path/to/schema-extension.yml

Create the resource pool​

First create a prefix to draw addresses from, then create the pool backed by that prefix.

Create the IP prefix:

  1. Navigate to IPAM > Prefixes
  2. Click + Add IP Prefix
  3. Fill in:
    • Prefix: 192.168.0.0/16
    • Member Type: address
    • Is Pool: true
  4. Save

Create the IP address pool:

  1. Navigate to Resource Manager > IP Address Pool
  2. Click + Add IP Address Pool
  3. Fill in:
    • Name: Interface IP Pool
    • Default Address Type: IpamIPAddress
    • IP Namespace: default
    • Resources: select 192.168.0.0/16
  4. Save

Assign the pool to the interface template​

With the pool created, update the interface template from the previous section to allocate an IP address from it whenever a new interface is created.

  1. Navigate to Object Management > Templates
  2. Open Template-SwitchModel123-Ethernet1 (or any interface template)
  3. On the IP Address field, click the pool selector button and choose Interface IP Pool
  4. The field will show an Allocated by pool badge
  5. Save

Create objects — IP addresses are allocated automatically​

Creating a device from the template works exactly as described in the Create object instances section. No additional steps are required — when the device is saved, Infrahub allocates an available IP address from Interface IP Pool and assigns it to each interface's ip_address field.

info

Resource allocation happens at object creation time, not at template creation time. Each new device gets its own unique address drawn from the pool.

For more information about resource pools, see: