alab_management.device_manager module#

This module is adapted from Mause/rpc.

The task process can only get access to a wrapper over the real device object. The wrapper will redirect all the method calls to the real device object via RabbitMQ. The real device object is in DeviceManager class, which will handle all the request to run certain methods on the real device.

class DeviceManager(_check_status=True)[source]#

Bases: object

Device manager is basically a rabbitmq-backed RPC server, which receives and executes commands on the device drivers, as requested by the task process.

on_message(channel, method, props, _body)[source]#

Function that handle the command message.

The structure of _body:

{
    "task_id": str,
    "device": str,
    "method": str,
    "args": List,
    "kwargs": Dict,
}
run()[source]#

Start to listen on the device_rpc queue and conduct the command one by one.

class DeviceMethodCallState[source]#

Bases: object

holds the status of a pending method call to a device.

future: Future#
last_updated: float#
status: MethodCallStatus#
class DeviceWrapper(name, devices_client)[source]#

Bases: object

A wrapper over the device.

class DeviceMethodWrapper(device_name, method, method_handler)[source]#

Bases: object

A wrapper over a device method.

property method: str#

The name of the method.

property name: str#

The name of the device.

class DevicesClient(task_id, timeout=None)[source]#

Bases: object

A rabbitmq-backed RPC client for sending device requests to the Device Manager (server).

Use create_device_wrapper to create Device Wrapper instance.

call(device_name, method, *args, **kwargs)[source]#

Call a method inside the device with name device_name. args, kwargs will be feeded into the method directly.

Parameters:
  • device_name (str) – the name of device, which is defined by administer.

  • method (str) – the class method to call

  • args – positional arguments to feed into the method function

  • kwargs – keyword arguments to feed into the method function

Return type:

Any

Returns:

the result of function

create_device_wrapper(device_name)[source]#

Create a wrapper over a device with device_name.

Parameters:

device_name (str) – the name of device to be wrapped

Return type:

object

Returns:

A device wrapper that will send every call to class method to remote server.

on_message(channel, method_frame, properties, _body)[source]#

Callback function to handle a returned message from Device Manager.

class MethodCallStatus(value)[source]#

Bases: Enum

The status of a method call.

FAILURE = 4#
IN_PROGRESS = 2#
PENDING = 1#
SUCCESS = 3#