infrahub-transform-creator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseInfrahub Transform Creator
Infrahub 转换创建工具
Overview
概览
Expert guidance for creating Infrahub transforms.
Transforms convert Infrahub data into different formats
-- JSON, text, CSV, device configs, or any text-based
output -- using Python classes or Jinja2 templates.
为创建Infrahub转换提供专业指导。
转换可使用Python类或Jinja2模板将Infrahub数据转换为不同格式
——JSON、文本、CSV、设备配置,或任何基于文本的输出。
When to Use
适用场景
- Building data transformations (Infrahub data -> another format)
- Generating device configurations from infrastructure data
- Creating CSV reports, cable matrices, or inventory exports
- Rendering Jinja2 templates with query data
- Combining Python logic with Jinja2 rendering
- Connecting transforms to artifacts for automated output
- 构建数据转换(Infrahub数据 -> 其他格式)
- 基于基础设施数据生成设备配置
- 创建CSV报表、线缆矩阵或库存导出文件
- 使用查询数据渲染Jinja2模板
- 结合Python逻辑与Jinja2渲染能力
- 将转换与工件关联以实现自动化输出
Rule Categories
规则分类
| Priority | Category | Prefix | Description |
|---|---|---|---|
| CRITICAL | Types | | Python vs Jinja2 choice |
| CRITICAL | Python | | InfrahubTransform class |
| CRITICAL | Jinja2 | | Template syntax, filters |
| HIGH | Hybrid | | Python + Jinja2 combined |
| HIGH | Artifacts | | Output files, targets |
| HIGH | API Ref | | Class attrs, methods |
| MEDIUM | Patterns | | Utilities, CSV, shared |
| LOW | Testing | | Transform/render commands |
| 优先级 | 分类 | 前缀 | 描述 |
|---|---|---|---|
| 严重 | 类型 | | Python与Jinja2的选型 |
| 严重 | Python | | InfrahubTransform类 |
| 严重 | Jinja2 | | 模板语法、过滤器 |
| 高 | 混合模式 | | Python + Jinja2 结合使用 |
| 高 | 工件 | | 输出文件、目标 |
| 高 | API参考 | | 类属性、方法 |
| 中等 | 最佳实践 | | 工具函数、CSV、共享逻辑 |
| 低 | 测试 | | 转换/渲染命令 |
Transform Basics
转换基础知识
Two types of transforms:
| Type | Output | Entry Point |
|---|---|---|
| Python | JSON/dict or text | |
| Jinja2 | Text | |
python
from infrahub_sdk.transforms import InfrahubTransform
class MyTransform(InfrahubTransform):
query = "my_query"
async def transform(self, data: dict) -> dict:
device = data["DcimDevice"]["edges"][0]["node"]
return {"hostname": device["name"]["value"]}两种转换类型:
| 类型 | 输出 | 入口点 |
|---|---|---|
| Python | JSON/dict 或文本 | |
| Jinja2 | 文本 | |
python
from infrahub_sdk.transforms import InfrahubTransform
class MyTransform(InfrahubTransform):
query = "my_query"
async def transform(self, data: dict) -> dict:
device = data["DcimDevice"]["edges"][0]["node"]
return {"hostname": device["name"]["value"]}Supporting References
参考资料
- examples.md -- Complete transform patterns (Python, Jinja2, hybrid, CSV)
- ../infrahub-common/graphql-queries.md -- GraphQL query writing reference
- infrahub-yml-reference.md -- .infrahub.yml project configuration
- ../infrahub-common/rules/ -- Shared rules (git integration, caching) across all skills
- ../infrahub-schema-creator/SKILL.md -- Schema definitions transforms work with
- rules/ -- Individual rules by category
- examples.md -- 完整的转换示例模式(Python、Jinja2、混合模式、CSV)
- ../infrahub-common/graphql-queries.md -- GraphQL查询编写参考
- infrahub-yml-reference.md -- .infrahub.yml 项目配置参考
- ../infrahub-common/rules/ -- 所有技能通用的共享规则(Git集成、缓存)
- ../infrahub-schema-creator/SKILL.md -- 转换所使用的Schema定义
- rules -- 按分类整理的独立规则