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_enabled: Set toTrueto expose the workflow through the APIworkflow_api_endpoint: API endpoint pathworkflow_namespace: Workflow namespace
Dynamic API Generator
The dynamic API generator:
- Creates routes for the workflow registry’s workflows that set
workflow_api_enabled = True; the registry rejects an API-enabled workflow with incomplete metadata at startup - 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 a network device using pre- and post-ZTP backups” - 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, including
workflow_api_enabled = True - Adding to
BUILTIN_WORKFLOWSor to a workflow plugin descriptor
- 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 (packages/workflows/src/nv_config_manager_workflows/metadata/mixin.py)
Dynamic Endpoint Generator (src/nv_config_manager/temporal/api/dynamic_endpoints.py)
Registration System
The API builds one validated workflow registry snapshot when it is imported. If
the registry cannot be built, because an installed plugin is invalid or
conflicts with another, or because the built-in plugin is not registered
(WorkflowPluginDiscoveryError), the API fails to start. The API’s dynamic
routes, /metadata, and /types read from the snapshot:
Adding New Workflows
Create Workflow with Metadata
Create Input Model
Register Workflow
Add a built-in workflow to BUILTIN_WORKFLOWS:
A workflow shipped in its own distribution belongs in that plugin’s
WorkflowPluginDescriptor instead; see
Registering a workflow plugin.
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 class name of every registered workflow, including API-disabled
child workflows such as TenantDeployWorkflow. Use /v1/workflow/metadata for
the set of workflows the API can start.
Get Workflow Metadata
Returns metadata for each API-enabled workflow 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.