How annetutil/annet works
Purpose and entry points
Annet is a Python CLI/library for intent-based network configuration generation, comparison with device state, command-patch creation, and deployment. Main entry points are annet/__main__.py, annet/cli.py, and the package orchestration modules annet/gen.py, annet/diff.py, and annet/deploy.py. The root annet.py is also a top-level launcher.
Command pipeline
The primary control flow is progressive: gen creates desired configuration, diff obtains current configuration and compares it, patch converts the difference into device commands, and deploy applies those commands. Core stages reside in annet/gen.py, annet/diff.py, annet/patching.py, and annet/deploy.py. CLI argument parsing and command selection are separated into annet/argparse.py and annet/cli_args.py.
Context, storage, and adapters
Runtime behavior is selected through a context containing generator and storage definitions. Storage is an abstraction boundary between Annet and inventory/source-of-truth systems: file-backed input is implemented at annet/adapters/file/provider.py; NetBox integration begins at annet/adapters/netbox/provider.py and version-specific storage implementations are in annet/adapters/netbox/v37/storage.py, annet/adapters/netbox/v41/storage.py, and annet/adapters/netbox/v42/storage.py. NetBox is the material external service; adapters also include stub fetch/deploy implementations for extension or testing.
Desired-state generation
User-supplied Python generator packages produce full or partial desired device configuration. The generator framework defines execution modes, results, references, annotation, and failure handling in annet/generators/base.py, annet/generators/entire.py, annet/generators/partial.py, and annet/generators/result.py. Example extension packages under annet_generators/ demonstrate the intended plugin boundary rather than being core production logic.
Device and vendor modeling
Device identity, hardware/platform handling, and vendor selection are centralized in annet/hardware.py, annet/vendors/registry.py, and annet/vendors/base.py. Vendor libraries map supported platforms such as Cisco, Huawei, Juniper, Arista, and RouterOS to behavior in paths such as annet/vendors/library/cisco.py, annet/vendors/library/huawei.py, and annet/vendors/library/juniper.py. A bundled device database supports network-device metadata at annet/annlib/netdev/devdb/data/devdb.json.
Diff, parsing, and patch compilation
Annet parses hierarchical network configurations, computes structural differences, then compiles vendor-specific command sequences. Shared mechanics are in annet/annlib/diff.py, annet/annlib/patching.py, and annet/annlib/rbparser/. The parser/rulebook boundary allows generic config changes to be rendered differently per platform; deployment-aware parsing is specifically represented by annet/annlib/rbparser/deploying.py.
Rulebooks and deployment
Rulebooks encode platform syntax, ordering, replacement/removal semantics, and deploy transformations. Python rule logic is organized by vendor under annet/rulebook/ (for example annet/rulebook/huawei/, annet/rulebook/cisco/, annet/rulebook/juniper/), while declarative rule assets are under annet/rulebook/texts/, including annet/rulebook/texts/huawei.rul, annet/rulebook/texts/cisco.deploy, and annet/rulebook/texts/juniper.order. Deployment execution and UI-oriented handling are separated into annet/deploy.py and annet/deploy_ui.py.
Higher-level network policy features
The repository includes two domain layers usable by generators: mesh/BGP topology processing in annet/mesh/executor.py, annet/mesh/registry.py, and annet/mesh/port_processor.py; and routing-policy modeling/rendering in annet/rpl/policy.py, annet/rpl/routemap.py, and annet/rpl_generators/execute.py. These produce configuration intent before the central generation-to-deployment pipeline.
Main entry points: gen.py Desired config generation · cli.py Command selection · diff.py Current-state diff · provider.py Storage abstraction
Components 20
CLI & Orchestration
- CLI launchers
annet/__main__.py - Command selection · Parses arguments and selects gen, diff, patch, or deploy.
annet/cli.py - CLI arguments
annet/argparse.py - Desired config generation
annet/gen.py - Current-state diff
annet/diff.py
Intent Sources
- Generator packages · User Python generators produce full or partial device intent.
- Generator framework · Defines generator modes, results, references, and failure handling.
annet/generators/base.py - Mesh/BGP intent
annet/mesh/executor.py - Routing policy intent
annet/rpl_generators/execute.py
Inventory & Device Model
- Storage abstraction · Selects source-of-truth and generator definitions through runtime context.
annet/adapters/file/provider.py - NetBox adapters · Version-specific storage adapters integrate with NetBox.
annet/adapters/netbox/provider.py - NetBox
- Hardware & vendor model
annet/hardware.py - Vendor libraries · Maps supported network platforms to vendor behavior.
annet/vendors/registry.py
Diff & Patch Compilation
- Structural config diff · Parses hierarchical configuration and computes changes.
annet/annlib/diff.py - Command patch compiler · Compiles configuration differences into device commands.
annet/annlib/patching.py
Rulebooks & Deployment
- Vendor rulebooks · Encodes platform syntax, ordering, replacement, removal, and deploy transformations.
- Deployment-aware parser
annet/annlib/rbparser/deploying.py - Deployment execution · Applies compiled command patches to devices.
annet/deploy.py - Network devices
Connections 23
- CLI launchers → Command selection: starts
- Command selection → CLI arguments: parses
- Command selection → Desired config generation: gen
- Command selection → Current-state diff: diff / patch
- Command selection → Deployment execution: deploy
- Generator packages → Generator framework: implements
- Mesh/BGP intent → Desired config generation: topology intent
- Routing policy intent → Desired config generation: policy intent
- Generator framework → Desired config generation: executes
- Storage abstraction → Desired config generation: inventory/context
- NetBox adapters → Storage abstraction: implements
- NetBox adapters → NetBox: queries
- Storage abstraction → Current-state diff: current state
- Hardware & vendor model → Vendor libraries: selects vendor
- Vendor libraries → Desired config generation: platform behavior
- Desired config generation → Current-state diff: desired config
- Current-state diff → Structural config diff: compares configs
- Structural config diff → Command patch compiler: changes
- Vendor libraries → Vendor rulebooks: selects rules
- Vendor rulebooks → Deployment-aware parser: deploy rules
- Command patch compiler → Deployment-aware parser: command plan
- Deployment-aware parser → Deployment execution: transformed commands
- Deployment execution → Network devices: applies