Dynamic API Implementation
Overview
The dynamic API endpoint generation system automatically creates FastAPI endpoints from workflow metadata. This creates a single source of truth for workflow definitions and provides excellent maintainability.
System Components
WorkflowMetadataMixin
The WorkflowMetadataMixin allows workflows to define their API metadata directly in the workflow class:
workflow_description: Human-readable descriptionworkflow_name: Human-readable workflow nameworkflow_input_class: Pydantic input modelworkflow_api_endpoint: API endpoint pathworkflow_namespace: Workflow namespace
Dynamic API Generator
The dynamic API generator:
- Automatically discovers workflows with complete metadata
- Generates FastAPI endpoint functions dynamically
- Handles proper routing, documentation, and parameter validation
- Provides consistent error handling and response formatting
Workflow Examples
All workflows use the metadata system, including:
- BackupWorkflow:
/ngc/backup- “Backup network device configuration to Config Store” - DeployWorkflow:
/ngc/deploy- “Deploy intended configuration to network device with approval workflow” - VpcCreationWorkflow:
/ngc/vpc_creation- “Create VPC with route distinguisher assignment and VRF provisioning” - VpcDeletionWorkflow:
/ngc/vpc_deletion- “Delete VPC and associated VRFs with validation checks” - ReprovisionWorkflow:
/ngc/reprovision- “Reprovision network device using ZTP and perform post-provision backup” - ConnectedHostMetadataWorkflow:
/ngc/connected_host_metadata- “Discover and analyze connected hosts through MAC table and LLDP neighbor data” - HelloWorld:
/hello_world- “Simple hello world workflow for testing and demonstration” - HelloWorldApproval:
/hello_world_approval- “Hello world workflow with approval step for testing staged workflows”
Integrated Benefits
- CLI automatically discovers workflows and generates commands
- OpenAPI documentation is automatically generated
- Consistent parameter validation across all interfaces
- Single source of truth for workflow definitions
Technical Implementation
Workflow Definition with Metadata
Automatic Endpoint Generation
Key Benefits
Single Source of Truth
- Workflow metadata is defined once in the workflow class
- API endpoints, CLI help, and documentation all derive from the same source
- Consistent information across all interfaces
Automatic Discovery
- New workflows are automatically discovered and exposed using the API
- CLI automatically generates commands for new workflows
- No manual endpoint registration required
Easy Maintenance
- Adding a new workflow requires only:
- Adding
WorkflowMetadataMixinto the workflow class - Setting the metadata attributes
- Adding to
REGISTERED_WORKFLOWSlist
- Adding
- System automatically handles the rest
Comprehensive Documentation
- Workflow descriptions appear in:
- OpenAPI/Swagger documentation
- CLI help text
- Workflow discovery endpoints
- Consistent documentation across all interfaces
Type Safety
- Pydantic input models ensure type safety
- FastAPI automatically generates request/response schemas
- CLI parameter validation matches API validation
Architecture
Workflow Discovery Flow
Components
WorkflowMetadataMixin (src/nv_config_manager/temporal/common/mixins/metadata.py)
Dynamic Endpoint Generator (src/nv_config_manager/temporal/api/dynamic_endpoints.py)
Registration System
Adding New Workflows
Create Workflow with Metadata
Create Input Model
Register Workflow
That’s It
The workflow is now automatically:
- Available using the API at
/v1/workflow/ngc/my_new_workflow - Documented in OpenAPI/Swagger
- Available in CLI as
uv run workflow-cli my-new-workflow - Included in workflow discovery endpoints
Workflow Discovery API
List Workflow Executions
Returns workflow execution summaries. Query parameters such as workflow_type,
status, user, site, device_name, device_id, device_role, and
device_platform filter the execution list.
Get Registered Workflow Types
Returns the legacy list of registered workflow type names.
Get Workflow Metadata
Returns registered workflow metadata and the RBAC roles needed by the UI:
Testing
Unit Tests
Integration Tests
Summary
The dynamic API system provides a clean, maintainable approach to workflow management. By defining metadata directly in workflow classes, the system automatically generates consistent APIs, CLI commands, and documentation. This approach scales well as new workflows are added and ensures consistency across all interfaces.