Pool module (ska_low_mccs.pool)

This module implements infrastructure for management of device pools.

It is useful for devices that handle commands by passing them to a pool of subservient devices.

todo

This is quite a basic class that allows for sending a command to all devices in a pool at once, and for sending a command to pools in sequence. In the long run, this might need to evolve into a class that send commands in a sequence that complies with a complex dependency graph.

class DevicePool(fqdns, logger, connect=True)[source]

A class for managing a static pool of devices.

It allows execution of a command on all members of the pool at the same time. i.e. asynchronously.

At this point it only explicitly supports the SKABaseDevice commands Disable(), Off(), Standby() and On(), but there is also a generic invoke_command method that allows execution of an arbitrary method by name.

It is only capable of supporting commands that return OK or FAILED, not STARTED or QUEUED.

__init__(fqdns, logger, connect=True)[source]

Initialise a new DevicePool object.

Parameters
  • fqdns (list(str)) – the FQDNs of the devices in this pool

  • logger (logging.Logger) – the logger to be used by this object.

  • connect (bool) – whether to establish connections immediately. Defaults to True. If False, the connections may be established by calling the connect() method, or by calling one of the supported commands.

callback(argin)[source]

A generic method to send a message to the pool of devices.

Parameters

argin – result of the command

Returns

Whether all of the messages were completed, return_code and message

connect()[source]

Connect to the devices in the pool.

disable()[source]

Call Disable() on all the devices in this device pool.

Returns

Whether the command succeeded or not

Return type

bool

invoke_command(command_name, arg=None)[source]

A generic method for invoking a command on all devices in the pool.

Parameters
  • command_name (str) – the name of the command to be invoked

  • arg (object) – optional argument to the command

Returns

Whether the command succeeded or not

Return type

bool

invoke_command_with_callback(command_name, fqdn, callback)[source]

A generic method to send a message to the pool of devices.

Parameters
  • command_name (str) – the name of the command to be invoked

  • fqdn (str) – FQDN to return message to

  • callback (str) – Callback command to call reply to

Returns

Whether the messages were sent or not

Return type

bool

off()[source]

Call Off() on all the devices in this device pool.

Returns

Whether the command succeeded or not

Return type

bool

on()[source]

Call On() on all the devices in this device pool.

Returns

Whether the command succeeded or not

Return type

bool

pool_stats()[source]

Statistics on which pool command replies are pending.

Returns

Number of pending responses for this pool

standby()[source]

Call Standby() on all the devices in this device pool.

Returns

Whether the command succeeded or not

Return type

bool

class DevicePoolSequence(pools, logger, connect=True)[source]

A class for managing a sequence of device pools.

It allows execution of a command on each pool in sequence.

For example, if we need to turn subracks on before we can turn tiles on, then we can

  • create a pool of subracks

  • create a pool of tiles

  • pass these two pools to this class

We can then call the on() command for this class, and it will

  • call the on() command for all subracks at the same time

  • wait for them to complete

  • call the on() command for all tiles at the same time.

At this point it only explicitly supports the SKABaseDevice commands Disable(), Off(), Standby() and On(), but there is also a generic invoke_command method that allows execution of an arbitrary method by name.

It is only capable of supporting commands that return OK or FAILED, not STARTED or QUEUED.

__init__(pools, logger, connect=True)[source]

Initialise a new DevicePoolSequence object.

Parameters
  • pools (list(DevicePool)) – a sequence of device pools

  • logger (logging.Logger) – the logger to be used by this object.

  • connect (bool) – whether to establish connections immediately. Defaults to True. If False, the connections may be established by calling the connect() method, or by calling one of the supported commands.

callback(argin)[source]

We need to check all pools have received their callbacks whenever we get a callback message.

Parameters

argin – results from executed command

Returns

A tuple containing a flag indicating whether pools are complete, an overall return code and an information status

Return type

(bool, ResultCode, str)

connect()[source]

Connect to the devices in the pools.

disable(reverse=False)[source]

Call Disable() on all the devices in this device pool.

Parameters

reverse (bool) – whether to call pools in reverse sequence. (You might turn everything on in a certain order, but need to turn them off again in reverse order.) Optional, defaults to False

Returns

Whether the command succeeded or not

Return type

bool

invoke_command(command_name, arg=None, reverse=False)[source]

A generic method for sequential invoking a command on a list of device pools.

Parameters
  • command_name (str) – the name of the command to be invoked

  • arg (object) – optional argument to the command

  • reverse (bool) – whether to call pools in reverse sequence. (You might turn everything on in a certain order, but need to turn them off again in reverse order.)

Returns

Whether the command succeeded or not

Return type

bool

invoke_command_with_callback(command_name, fqdn, callback, reverse=False)[source]

A generic method for sequential invoking a command on a list of device pools.

Parameters
  • command_name (str) – the name of the command to be invoked

  • fqdn (str) – FQDN to return message to

  • callback (str) – Callback command to call reply to

  • reverse (bool) – whether to call pools in reverse sequence. (You might turn everything on in a certain order, but need to turn them off again in reverse order.)

Returns

Whether the command succeeded or not

Return type

bool

off(reverse=False)[source]

Call Off() on all the devices in this device pool.

Parameters

reverse (bool) – whether to call pools in reverse sequence. (You might turn everything on in a certain order, but need to turn them off again in reverse order.) Optional, defaults to False

Returns

Whether the command succeeded or not

Return type

bool

on(reverse=False)[source]

Call On() on all the devices in this device pool.

Parameters

reverse (bool) – whether to call pools in reverse sequence. (You might turn everything on in a certain order, but need to turn them off again in reverse order.) Optional, defaults to False

Returns

Whether the command succeeded or not

Return type

bool

pool_stats()[source]

Stats on the pool.

Returns

The pool stats

Return type

str

standby(reverse=False)[source]

Call Standby() on all the devices in this device pool.

Parameters

reverse (bool) – whether to call pools in reverse sequence. (You might turn everything on in a certain order, but need to turn them off again in reverse order.) Optional, defaults to False

Returns

Whether the command succeeded or not

Return type

bool