infrahub-generator-creator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseInfrahub Generator Creator
Infrahub Generator 创建器
Overview
概述
Expert guidance for creating Infrahub Generators. Generators
query data from Infrahub via GraphQL and create new nodes and
relationships based on the result -- enabling design-driven
automation where a "design" object automatically creates
downstream infrastructure.
为创建Infrahub Generators提供专业指导。Generators通过GraphQL从Infrahub查询数据,并基于查询结果创建新节点和关系,从而实现设计驱动的自动化:即「设计」对象可自动创建下游基础设施。
When to Use
适用场景
- Building design-driven automation (topology -> devices)
- Creating objects from templates or design definitions
- Implementing idempotent create-or-update workflows
- Auto-generating infrastructure from high-level designs
- Understanding the generator tracking system
- 构建设计驱动的自动化(拓扑 -> 设备)
- 基于模板或设计定义创建对象
- 实现幂等的创建或更新工作流
- 从高层设计自动生成基础设施
- 了解生成器跟踪系统
Rule Categories
规则分类
| Priority | Category | Prefix | Description |
|---|---|---|---|
| CRITICAL | Architecture | | Components, groups |
| CRITICAL | Python Class | | Generator, generate() |
| HIGH | Tracking | | Upsert, idempotent |
| HIGH | API Ref | | Constructor, props |
| HIGH | Registration | | .infrahub.yml config |
| MEDIUM | Patterns | | Cleaning, batch, store |
| LOW | Testing | | infrahubctl commands |
| 优先级 | 分类 | 前缀 | 描述 |
|---|---|---|---|
| 最高 | 架构 | | 组件、组 |
| 最高 | Python类 | | Generator, generate() |
| 高 | 跟踪 | | Upsert, 幂等 |
| 高 | API参考 | | 构造函数、属性 |
| 高 | 注册 | | .infrahub.yml 配置 |
| 中 | 模式 | | 清理、批量、存储 |
| 低 | 测试 | | infrahubctl 命令 |
Generator Basics
生成器基础
Every generator has three components:
- Target group -- objects that trigger the generator
- GraphQL query (file) -- fetches the design data
.gql - Python class -- inherits from , implements
InfrahubGeneratorgenerate()
python
from infrahub_sdk.generator import InfrahubGenerator
class MyGenerator(InfrahubGenerator):
async def generate(self, data: dict) -> None:
obj = await self.client.create(
kind="DcimDevice",
data={"name": "spine-01"},
)
await obj.save(allow_upsert=True)每个生成器包含三个组件:
- 目标组 -- 触发生成器的对象
- GraphQL查询(文件) -- 获取设计数据
.gql - Python类 -- 继承自 ,实现
InfrahubGenerator方法generate()
python
from infrahub_sdk.generator import InfrahubGenerator
class MyGenerator(InfrahubGenerator):
async def generate(self, data: dict) -> None:
obj = await self.client.create(
kind="DcimDevice",
data={"name": "spine-01"},
)
await obj.save(allow_upsert=True)Supporting References
参考资料
- examples.md -- Complete Generator patterns (POP topology, network segment, minimal)
- ../infrahub-common/graphql-queries.md -- GraphQL query writing reference
- ../infrahub-common/infrahub-yml-reference.md -- .infrahub.yml project configuration
- ../infrahub-common/rules/ -- Shared rules (git integration, caching gotchas)
- ../infrahub-schema-creator/SKILL.md -- Schema definitions Generators work with
- rules/ -- Individual rules organized by category prefix
- examples.md -- 完整的Generator模式(POP拓扑、网络分段、最简示例)
- ../infrahub-common/graphql-queries.md -- GraphQL查询编写参考
- ../infrahub-common/infrahub-yml-reference.md -- .infrahub.yml 项目配置参考
- ../infrahub-common/rules/ -- 共享规则(git集成、缓存注意事项)
- ../infrahub-schema-creator/SKILL.md -- 生成器配套的Schema定义
- rules/ -- 按类别前缀组织的独立规则