luxos.asyncops#
- luxos.asyncops.RETRIES = 0#
default number (>1) of retries on a failed operation
- luxos.asyncops.RETRIES_DELAY = 1.0#
delay (s) between retries
- luxos.asyncops.TIMEOUT = 3.0#
default timeout (s) for operations
- async luxos.asyncops.rexec(host: str, port: int, cmd: str, parameters: str | int | float | bool | list[Any] | dict[str, Any] | None = None, timeout: float | None = None, retry: int | None = None, retry_delay: float | None = None) dict[str, Any] #
Send a command to a host.
- Parameters:
host – A string representing the host IP or a name.
port – An integer representing the port number to connect to.
cmd – A string representing the command to execute.
parameters – Any additional parameters for the command.
timeout – A float representing the maximum time in seconds to wait for a response before timing out.
retry – Optional. An integer representing the number of times to retry the command execution in case of failure.
retry_delay – Optional. A float representing the delay in seconds between each retry attempt.
- Returns:
A dictionary containing the response from the execution of the command.
- Raises:
Any exception that occurs during the execution of the command. –
Notes
If timeout/retry/retry_delay aren’t provided (or None), they will default to the module level values (
TIMEOUT
,RETRIES
, andRETRIES_DELAY
).This function will handle logon/logoff automatically.
- luxos.asyncops.validate(res: dict[str, Any], extrakey: str | None = None, minfields: None | int = None, maxfields: None | int = None) Any #
Validate a message returned from a miner.
- Parameters:
res – The dictionary returned from a miner.
extrakey – if present it will try to extract it from res.
cmd – A string representing the command to execute.
minfields – The min length of the field extrakey.
maxfields – The max length of the field extrakey.
- Returns:
A dictionary containing the response from the execution of the command if extrakey is None, else a dict or a list of items.
- Raises:
RuntimeError – if minfield > maxfield (internal error).
MinerMessageMalformedError – the res dict is missing either ‘STATUS’ or ‘id’ keys.
MinerMessageError – the message is well formed but STATUS is not S.
MinerMessageMalformedError – the res[extrakey] is not a list
MinerMessageInvalidError – the message is missing extarkey or the len(res[extrakey]) is not valid.