gendev_tools package¶
Subpackages¶
Submodules¶
gendev_tools.gendev_err module¶
gendev_err.py¶
Custom exeception types for the GenDev Tools library.
-
exception
gendev_tools.gendev_err.ConnNotImplemented(*args)[source]¶ Bases:
ExceptionConnection Not Implemented Exception.
This exception is raised when an operation relies on a particular connection type that is not implemented for the given device.
-
exception
gendev_tools.gendev_err.ConnTimeout(*args)[source]¶ Bases:
ExceptionConnection timeout Exception.
gendev_tools.gendev_interface module¶
gendev_interface¶
Public API offering some useful features for configuring/maintaining devices supported by the ICSHWI WP4.
This is just an interface, which means it has to be implemented for a particular device. Don’t use this directly, look inside the project for a module that implements this interface.
Main features supported by the API: - FW update - Accessing/Setting configuration parameters - Running dry checks against a golden configuration
-
class
gendev_tools.gendev_interface.ConnType(value)[source]¶ Bases:
enum.EnumThis enumeration specifies the allowed connection types.
Any device implementing the GenDevInterface should allow using one or more of the following connection types:
ETHER: Ethernet connection using TCP/IP.
SERIAL: Serial connection.
MOXA: Serial connection through a MOXA Hub (accessible over Ethernet).
TELNET: Serial connection through Ethernet using Telnet.
SSH: Secure Shell connection through Ethernet.
-
ETHER= 0¶
-
MOXA= 2¶
-
SERIAL= 1¶
-
SSH= 4¶
-
TELNET= 3¶
-
class
gendev_tools.gendev_interface.GenDevInterface(device_model: str, manufacturer: str, serial_num: str, allowed_conn: list, hostname: Optional[str] = None, vlan: Optional[str] = None, mac_address: Optional[str] = None, logger: Optional[logging.Logger] = None, log_en: bool = False)[source]¶ Bases:
objectInterface for a Generic Device.
This interface can be implemented to control any device that includes some sort of management interface: command line trough a serial port, a web interface, …
Details for particular devices should be handled on their implementation for this interface.
-
__init__(device_model: str, manufacturer: str, serial_num: str, allowed_conn: list, hostname: Optional[str] = None, vlan: Optional[str] = None, mac_address: Optional[str] = None, logger: Optional[logging.Logger] = None, log_en: bool = False)[source]¶ Class constructor.
- Parameters
device_model – The device identifier
manufacturer – The device manufacturer
serial_num – Serial number of the device
allowed_conn – A list containing the supported connection types for the device. See the ConnType enum for details.
hostname – given hostname by CSEntry.
vlan – vlan in which the device is registered.
mac_address – MAC address of the network interface connected to the TN network.
logger – Reference to a logger instance. When this is not None, the code will add info to the main’s program log.
-
abstract
check_configuration(category: str, config: OrderedDict) → tuple[bool, str][source]¶ Check the settings of the device.
This method retrieves the configuration parameters of a device, and performs a comparison against the values given by config. When differences are detected, the values are reported to a log, the method only returns a general message indicating the result of the check.
- Parameters
category (str) – a key indicating the target settings when
device has several subset of configuration parameters. (a) –
config (OrderedDict) – a dictionary containing the expected
for all the parameters that are aimed to check. (values) –
- Returns
a boolean value indiciating whether the checking was successful or not; and a text message when the checking was unsuccesful.
- Return type
tuple[bool, str]
-
abstract
device_info() → tuple[bool, dict][source]¶ Retrieve the main information about the device.
The information is returned in a dictionary with 2 categories: board and network.
- Returns
If success, a dictionary with the device information. If failure, an empty dictionary on failure.
-
abstract
get_configuration(category: str) → tuple[bool, dict][source]¶ Get the configuration of the device.
This method returns a dictionary containing the configuration parameters of the device implementing this interface. If the device has several configuration categories, keys from the dictionary might contain other dictionaries. This method can be used for checking the good configuration of a device.
- Parameters
category – points to a subset of the configuration parameters of the device.
- Returns
A dictionary containing the configuration of the device.
- Raises
ConnectionError – If the device is not accessible.
-
abstract
reboot_slot(amc_num) → tuple[bool, str][source]¶ Method to power cycle an individual AMC slot.
- Parameters
amc_num – AMC slot number to power cycle.
- Returns
On success, an empty string.
On failure, a string containing the failure message.
- Return type
A tuple containing the a success flag in the first position. In the second position
-
abstract
set_configuration(category: str, data, verify=True) → tuple[bool, str][source]¶ Change the configuration of the device.
This method focuses on the configuration parameters that are not defined within a configuration script. Specifying the entire set of parameters is not mandatory, and also, a particular category of settings can be modified without affecting the rest.
- Parameters
category (str) – settings category to be affected.
data (dict) – dictionary containing the values to be modified
verify (bool) – when True, the method performs a checking after setting the new parameters.
- Returns
0 when successful or verify=False
A dictionary containing the values that are not matching the expectation. For each key, the expected and the given values are provided.
- Raises
ConnectionError – If the device is not accessible.
-
abstract
set_dhcp_mode() → tuple[bool, str][source]¶ Enables DHCP mode in the network configuration of the device.
- Raises
ConnectionError – If the device is not accessible.
NoValidConn – If no valid connection types supporting this feature are used by the device.
-
abstract
update_fw(fw_version: str, part: str) → tuple[bool, str][source]¶ Update the firmware of the device.
- Parameters
fw_version – version release number for the new fw.
part – modifier allowing the update of different parts within the same device.
- Returns
If failure, it returns a tuple containing False, and a message about the failure. If success, it returns (True,)
- Raises
ConnectionError – If the device is not accessible.
-