Extending hier_config
This guide covers the three most common in-tree contributions: adding support for a new platform, adding a new driver rule type, and adding config view properties. For customizing drivers outside the library (in your own code), see Customizing and Creating Drivers.
Every change described here follows TDD: write the failing test first, then implement.
Adding an In-Tree Platform Driver
- Create the driver package:
hier_config/platforms/<platform>/containingdriver.pywith a class subclassingHConfigDriverBase(hier_config/platforms/driver_base.py). Override_instantiate_rules()to return anHConfigDriverRulesmodel constructed with the platform's rules (seeplatforms/huawei_vrp/driver.pyfor a small example). - Register the platform: add a member to the
Platformenum inhier_config/models.py. - Wire the constructor: map the new enum member to your driver class in the
platform_driversdict insideget_hconfig_driver(hier_config/constructors.py). - Add tests: create
tests/test_driver_<platform>.pyfollowing the testing conventions. Add any config fixtures totests/fixtures/. - Document it: add a driver section and a platform-table row to Drivers.
- Changelog: add an entry under
## [Unreleased]inCHANGELOG.md.
Rule behavior available to drivers (negation, sectional exiting, ordering, idempotency, substitutions, etc.) is catalogued in Driver Rule Types.
Adding a Driver Rule Type
- Model: add a frozen Pydantic model in
hier_config/models.py. Subclass the project-localBaseModel(neverpydantic.BaseModeldirectly — the local base enforcesfrozen=True, extra="forbid"). Lineage matching usesmatch_rules: tuple[MatchRule, ...]; collections must be immutable (tuple/frozenset). - Rules container: add a named module-level default factory function and a field to
HConfigDriverRulesinhier_config/platforms/driver_base.py. - Consume the rule: implement the behavior in
hier_config/child.pyand/orhier_config/root.py(typically evaluated viaHConfigChild.is_lineage_match()). - Populate: add instances of the rule to the relevant platform drivers'
_instantiate_rules(). - Test, document, changelog: failing test first; document the rule type in Driver Rule Types and add a glossary entry; update
CHANGELOG.md.
Adding Config View Properties
- Abstract property: declare it on
HConfigViewBaseorConfigViewInterfaceBaseinhier_config/platforms/view_base.py. - Platform implementations: implement the property in each platform's
view.py(e.g.,hier_config/platforms/cisco_ios/view.py). - Test: add coverage in
tests/config_view/(per-platform files such astest_view_cisco_ios.py). - Document: add the property to Config View.
Where Changes Belong
| Change type | Location |
|---|---|
| New platform support | hier_config/platforms/<name>/driver.py |
| New rule type | hier_config/models.py + hier_config/platforms/driver_base.py |
| New utility function | hier_config/utils.py |
| New view property | hier_config/platforms/view_base.py + each platform's view.py |
| Core tree algorithm | hier_config/base.py (shared) or hier_config/root.py (HConfig-only) |
Read the Architecture Overview before making structural changes.