Source: factory.deploy/ObjSubstrate.py
Resource limits for instances.
Current resource usage.
Network configuration for instances.
Template for creating instances.
| Method | Signature | Description |
|---|---|---|
| to_dict | to_dict() -> Dict[str, Any] |
|
| from_yaml | from_yaml(cls, yaml_file: str) -> 'InstanceTemplate' |
|
| save | save(yaml_file: str) |
Instance lifecycle events.
Event data class.
Event handling system for substrate operations.
| Method | Signature | Description |
|---|---|---|
| subscribe | subscribe(event_type: InstanceEvent, handler: Callable) |
Subscribe to an event type. |
| emit | emit(event: Event) |
Emit an event to all subscribed handlers. |
Metrics collection for substrate operations.
| Method | Signature | Description |
|---|---|---|
| track_operation | track_operation(operation: str) |
Context manager to track operation metrics. |
| get_metrics | get_metrics() -> Dict[str, Any] |
Get all collected metrics. |
Mixin to add caching capabilities to substrates.
An abstract base class for substrate controllers (like Docker, LXC, Proxmox, etc.).
It defines a unified interface for managing virtualized or containerized instances.
Enhanced with:
| Method | Signature | Description |
|---|---|---|
| ensure_connected | ensure_connected() -> bool |
Ensure connection is alive, reconnect if needed. |
| connect | connect() -> bool |
Establish a connection to the substrate (e.g., hypervisor, Docker daemon). |
| list_instances | list_instances() -> List[Dict[str, Any]] |
Lists all instances (VMs, containers) managed by the substrate. |
| get_instance | get_instance(name: str) -> Optional[Dict[str, Any]] |
Retrieves detailed information about a specific instance. |
| create_instance | create_instance(config: Dict[str, Any]) -> bool |
Creates a new instance based on the provided configuration. |
| start_instance | start_instance(name: str) -> bool |
Starts a specific instance. |
| stop_instance | stop_instance(name: str, force: bool = False) -> bool |
Stops a specific instance. |
| delete_instance | delete_instance(name: str, force: bool = False) -> bool |
Deletes a specific instance. |
| execute_command | execute_command(name: str, command: List[str]) -> Optional[Dict[str, Any]] |
Executes a command inside a running instance. |
| health_check | health_check() -> Dict[str, Any] |
Check substrate health status. |
| get_metrics | get_metrics(name: str) -> Optional[ResourceUsage] |
Get real-time metrics for an instance. |
| is_connected | is_connected() -> bool |
Checks if the client is connected to the substrate. |
| restart_instance | restart_instance(name: str, force: bool = False) -> bool |
Restarts a specific instance. |
| get_logs | get_logs(name: str, lines: int = 100, follow: bool = False) -> Optional[str] |
Get instance logs (default implementation returns None). |
| get_substrate_metrics | get_substrate_metrics() -> Dict[str, Any] |
Get metrics for all substrate operations. |
| set_resource_limits | set_resource_limits(name: str, limits: ResourceLimits) -> bool |
Set resource limits for an instance. |
| get_resource_limits | get_resource_limits(name: str) -> Optional[ResourceLimits] |
Get current resource limits. |
| create_snapshot | create_snapshot(name: str, snapshot_name: str) -> bool |
Create a snapshot (default implementation returns False). |
| restore_snapshot | restore_snapshot(name: str, snapshot_name: str) -> bool |
Restore from snapshot (default implementation returns False). |
| list_snapshots | list_snapshots(name: str) -> List[Dict[str, Any]] |
List snapshots for an instance. |
| delete_snapshot | delete_snapshot(name: str, snapshot_name: str) -> bool |
Delete a snapshot. |
| clone_instance | clone_instance(source: str, destination: str) -> bool |
Clone an instance (default implementation returns False). |
| attach_network | attach_network(name: str, network: NetworkConfig) -> bool |
Attach instance to a network (optional implementation). |
| detach_network | detach_network(name: str, network_name: str) -> bool |
Detach instance from a network (optional implementation). |
| list_networks | list_networks() -> List[Dict[str, Any]] |
List available networks (optional implementation). |
| create_from_template | create_from_template(template: InstanceTemplate) -> bool |
Create instance from template. |
Decorator for automatic retry with exponential backoff.