opsmill / infrahub-sdk-python

Python SDK to interact with Infrahub
https://www.opsmill.com
Apache License 2.0
3 stars 2 forks source link

task: Discuss and potentially provide an action plan for inconsistent way of defining queries on .infrahub.yml #55

Open ogenstad opened 1 month ago

ogenstad commented 1 month ago

Component

Python SDK

Task Description

Today we have Jinja2 transforms and Python transforms. Looking at a .infrahub.yml file the definitions can look like this:

---
jinja2_transforms:
  - name: "device_startup"
    description: "Template to generate startup configuration for network devices"
    query: "device_startup_info"
    template_path: "templates/device_startup_config.tpl.j2"

  - name: "clab_topology"
    query: "topology_info"
    template_path: "topology/topology.tpl.j2"

check_definitions:
  - name: backbone_link_redundancy
    class_name: InfrahubCheckBackboneLinkRedundancy
    file_path: "checks/check_backbone_link_redundancy.py"

python_transforms:
  - name: OCInterfaces
    class_name: OCInterfaces
    file_path: "transforms/openconfig.py"
  - name: oc_bgp_neighbors
    class_name: OCBGPNeighbors
    file_path: "transforms/openconfig.py"

generator_definitions:
  - name: update_upstream_interfaces_description
    file_path: "generators/upstream_interfaces.py"
    targets: upstream_interfaces
    query: upstream_interfaces
    parameters:
      id: "id"

Here we can note that the query param is used by:

They are not defined in:

In these types the queries are instead defined within the Python code i.e.

class OCInterfaces(InfrahubTransform):
    query = "oc_interfaces"

I would vote to remove the .query attribute from the Python classes and instead define them within a .infrahub.yml file as we don't have that option with the Jinja2 templates.