Console
pamiq_core.console.WebApiServer ¶
WebApiServer(
system_status: SystemStatusProvider,
host: str = "localhost",
port: int = 8391,
max_queue_size: int = DEFAULT_QUEUE_SIZE,
)
Web API Server for controlling the system.
This class provides a simple Web API for controlling the thread controller, allowing external applications to pause, resume, and shutdown the system.
API Endpoints
-
GET /api/status
- Returns the current system status.
- Response: {"status": status_name}
- Status codes: 200 OK, 500 Internal Server Error
-
POST /api/pause
- Pauses the system.
- Response: {"result": "ok"} or {"error": "Command queue is full, try again later"}
- Status codes: 200 OK, 503 Service Unavailable
-
POST /api/resume
- Resumes the system.
- Response: {"result": "ok"} or {"error": "Command queue is full, try again later"}
- Status codes: 200 OK, 503 Service Unavailable
-
POST /api/shutdown
- Shuts down the system.
- Response: {"result": "ok"} or {"error": "Command queue is full, try again later"}
- Status codes: 200 OK, 503 Service Unavailable
-
POST /api/save-state:
- Saves a state of the current system state.
- Response: {"result": "ok"} or {"error": "Command queue is full, try again later"}
- Status codes: 200 OK, 503 Service Unavailable
Error Responses
- 404 Not Found: {"error": "Invalid API endpoint"}
- 405 Method Not Allowed: {"error": "Invalid API method"}
- 500 Internal Server Error: {"error": "Internal server error"}
Initialize the WebApiHandler.
PARAMETER | DESCRIPTION |
---|---|
system_status
|
Provider for system status information.
TYPE:
|
host
|
Hostname to run the API server on.
TYPE:
|
port
|
Port to run the API server on.
TYPE:
|
max_queue_size
|
Maximum size of the command queue.
TYPE:
|
Source code in src/pamiq_core/console/web_api.py
run_in_background ¶
has_commands ¶
Check if there are commands in the queue.
RETURNS | DESCRIPTION |
---|---|
bool
|
True if there are commands, False otherwise. |
receive_command ¶
Receive a command from the queue without blocking.
RETURNS | DESCRIPTION |
---|---|
ControlCommands
|
The command from the queue. |
RAISES | DESCRIPTION |
---|---|
Empty
|
If there are no commands in the queue. |
Source code in src/pamiq_core/console/web_api.py
pamiq_core.console.WebApiClient ¶
Client for PAMIQ Web API communication.
Provides methods to interact with PAMIQ system via HTTP API.
Initialize Web API client.
PARAMETER | DESCRIPTION |
---|---|
host
|
API server host
TYPE:
|
port
|
API server port
TYPE:
|
Source code in src/pamiq_core/console/web_api.py
get_status ¶
Get system status.
RETURNS | DESCRIPTION |
---|---|
SystemStatus
|
Status enum. If error is occurred, return offline status |
Source code in src/pamiq_core/console/web_api.py
pause ¶
Pause the system.
RETURNS | DESCRIPTION |
---|---|
str | None
|
Result message or None if request failed |
Source code in src/pamiq_core/console/web_api.py
resume ¶
Resume the system.
RETURNS | DESCRIPTION |
---|---|
str | None
|
Result message or None if request failed |
Source code in src/pamiq_core/console/web_api.py
save_state ¶
Save system state.
RETURNS | DESCRIPTION |
---|---|
str | None
|
Result message or None if request failed |
Source code in src/pamiq_core/console/web_api.py
shutdown ¶
Shutdown the system.
RETURNS | DESCRIPTION |
---|---|
str | None
|
Result message or None if request failed |
Source code in src/pamiq_core/console/web_api.py
pamiq_core.console.SystemStatus ¶
Bases: Enum
Enum representing the system's operational status.
status_name
property
¶
Returns the lowercase string representation of the status.
RETURNS | DESCRIPTION |
---|---|
str
|
The lowercase string name of the status. |
pamiq_core.console.Console ¶
pamiq-console.
Users can Control pamiq with CUI interface interactively.
Initialize CUI interface.
Source code in src/pamiq_core/console/cui.py
fetch_status ¶
run_command ¶
Check connection status before command execution.
Source code in src/pamiq_core/console/cui.py
main_loop ¶
Running CUI interface.
Source code in src/pamiq_core/console/cui.py
command_help ¶
Show all commands and details.
Source code in src/pamiq_core/console/cui.py
command_h ¶
command_pause ¶
command_p ¶
command_resume ¶
command_r ¶
command_shutdown ¶
Shutdown the AMI system.