infrahub-managing-generators

Creates Infrahub Generators that build infrastructure objects from design definitions and GraphQL queries.

9|2|Updated Aug 27, 2025
One-click install
npx skills add https://github.com/opsmill/infrahub-solution-ai-dc --skill infrahub-managing-generators-opsmill
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: infrahub-managing-generators
Source: https://github.com/opsmill/infrahub-solution-ai-dc/tree/main/.agents/skills/infrahub-managing-generators
Command: npx skills add https://github.com/opsmill/infrahub-solution-ai-dc --skill infrahub-managing-generators-opsmill

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing Infrahub Generators involves a three-part contract — a CoreGeneratorGroup target, a GraphQL query, and an async Python class — plus a tracking system that deletes stale objects on re-runs. Missteps like sync generate() methods, missing allow_upsert, bare-string relationship references, or wrong group types cause silent failures or data loss. This Skill encodes the rules, API reference, and tested patterns to get generators right the first time. ## Core Features & Use Cases - Generator Scaffolding Guidance: Walks through the full workflow — identify the design pattern, write the .gql query, implement the InfrahubGenerator subclass, register in .infrahub.yml, and test with infrahubctl. - Idempotency & Tracking Rules: Explains the delete_unused_nodes tracking contract, why every save needs allow_upsert=True, and how to keep re-runs safe. - Relationship Reference Rules: Documents the three accepted forms (HFID dict, ID dict, SDK object) and the bare-string anti-pattern behind "Unable to find the node" errors. - Performance Patterns: Covers InfrahubNode.from_graphql hydration to collapse O(N+1) round trips, batch creation, and data-cleaning helpers. - Use Case: You need a generator that turns a data center topology design into devices, interfaces, and IP pool allocations. The Skill provides the query shape, Python class skeleton, registration YAML, and testing commands. ## Quick Start Ask the assistant to create an Infrahub generator named create_dc that builds devices from a data center topology design.

Frequently Asked Questions about infrahub-managing-generators

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create an Infrahub Generator in Python?▼

Create a GraphQL .gql query fetching the design data, write a class inheriting from InfrahubGenerator with an async generate(self, data) method, and register it in .infrahub.yml under generator_definitions with query, targets, class_name, and parameters fields.

Why does my Infrahub generator never run?▼

The most common cause is pointing targets at a CoreStandardGroup instead of a CoreGeneratorGroup — the dispatcher only schedules the latter, so the generator loads but never fires. Also verify the query name in generator_definitions exactly matches the queries block entry.

Why does my generator fail on the second run?▼

Saves without allow_upsert=True error out on the first already-existing object, aborting the rest of generate(). Always call await obj.save(allow_upsert=True) so re-runs create or update idempotently within the tracking context.

How do I reference related objects in client.create for Infrahub?▼

Pass an HFID dict like {"hfid": ["name"]}, an ID dict like {"id": uuid}, or an SDK object directly. A bare string is treated as an id lookup and fails with "Unable to find the node" when it is not a valid UUID.

How do I test an Infrahub generator locally?▼

Run infrahubctl generator <name> <param>=<value> against a running server, after verifying connectivity with infrahubctl info. Local runs share the tracking group with pipeline runs, so test on a branch since the cleanup pass can delete objects from prior runs.

When should I use InfrahubNode.from_graphql instead of client.get?▼

Use from_graphql when generate() iterates relationship edges from the query response and re-fetches each peer with client.get — that pattern costs N+1 round trips. Hydrating peers directly from the response requires __typename and id in the query selection and reduces it to one round trip.