gendev_tools.nat_mch package

Submodules

gendev_tools.nat_mch.nat_mch module

gendev_tools.nat_mch.nat_mch_telnet module

nat_mch_telnet.py

This is a lazy implementation of the GenDev interface. The ultimate purpose of this module is to be encapsulated within another module that really implements that interface. Unfortunately, NAT MCHs don’t allow to go for a full implementation of the GenDev interface based on an only communication interface. The main operation that is only supported by the command line interface is the firmware update. So that, this module based on Telnet, as access way, and the command line interface of the MCH, shall only be used to perform a firmware update and nothing else. For other operations, better use the module based on the communication via the MHC web interface.

class gendev_tools.nat_mch.nat_mch_telnet.NATMCHTelnet(ip_address: str, backplane, port: int = 23, logger: Optional[gendev_tools.gendev_logger.GenDevLogger] = None, hostname: Optional[str] = None, open: bool = True, **kwargs)[source]

Bases: object

NATMCTelnet access an NAT MCH via Telnet.

This module implements some operations using the command line interface via Telnet. Thus, the MCH has to be accessible in the network. The firmware update relies on the mchconfig-server to serve the firmware image using the FTP protocol.

Supported operations:

  • Retrieve the general information of the MCH.

  • Firmware update of the MCH.

  • Enable DHCP mode of the MCH.

BOOT_TIME = 60
PROMPT = b'nat> '
__init__(ip_address: str, backplane, port: int = 23, logger: Optional[gendev_tools.gendev_logger.GenDevLogger] = None, hostname: Optional[str] = None, open: bool = True, **kwargs)[source]

Class constructor.

Parameters
  • ip_address (str) – the IP address of the MCH.

  • backplane (BackplaneType) – type of backplane in which the MCH is installed.

  • port (int) – port of the Telnet service (usually, 23).

  • logger (Logger) – reference to a logger that is being used.

  • log_to_file (Bool) – boolean flag to indicate if the log should be written

  • a file. (to) –

  • hostname (str) – hostname of the MCH.

  • open (bool) – whether to establish the connection at instantiation time or later. Set this argument to False when a deferred link establishment is aimed.

  • **telnet_ip_address (str) – the ip address of the telnet connection, if not equal to the IP address of the MCH, i.e. when connecting via a MOXA (optional).

  • **tftp_server_address (str) – IP address of the machine hosting the TFTP server with the fw images. Default value = 172.30.4.69.

  • **tftp_server_fw_path (str) – path to the fw binaries in the TFTP server. Default value = “fw/”.

Raises
close()[source]

Close the Telnet session.

This is needed when multiple methods of this module are called in a row.

device_info() → tuple[bool, OrderedDict][source]

Retrieve the main information about the device.

The information is returned in a dictionary with 2 categories: Board and Network. This feature is supported by all the implemented communication interfaces, so the best one is chosen when multiple are allowed.

An example of the returned dictionary:

{
  'Board': {
    'fw_ver': 'V2.21.8',
    'fpga_ver': 'V1.14',
    'mcu_ver': '1.2',
    'serial_num': '113522-1426'},
  'Network': {'ip_address': '172.30.5.238',
    'mac_address': '00:40:42:22:05:92',
    'subnet_address': '255.255.252.0',
    'gateway_address': '172.30.7.254'}
}
Returns

  • On success, a dictionary with the device information.

  • On failure, an empty dictionary.

Return type

A tuple containing the a success flag in the first position. In the second position

Raises
open()[source]

Establish the connection to the target MCH.

Raises
  • ConnTimeout – if the connection to the device gets lost.

  • NoRouteToDevice – if the device is not reachable.

  • ConnectionRefused – if the telnet connection is refused.

reboot_all_slots()[source]

Method to power cycle all AMC slots.

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

reboot_slot(amc_num)[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

set_configuration(category: str, data: OrderedDict, apply: bool = 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.

This method supports the following configuration categories (taken from the webpage names):

  • Backplane configuration [backplane]

The configuration files are hosted by the server, and they are named following this way: latest_mch_conf_<form factor>_<modifier>_cfg.txt. For factor should match the type of chassis, while the modifier allows choosing a non-standard configuration.

Parameters
  • category (str) – the target set of parameters to be affected by the change. The accepted values are previously listed.

  • data (dic) – dictionary containing modifiers that allow for choosing a particular backplane configuration file.

  • apply (bool) – whether to reboot the MCH to make active the changes or not. Disable rebooting when multiple changes are going to be performed in the device. Reboot the device after the last change.

Returns

A tuple containing a bool indicating if the operation was successful, and an error message.

Raises
  • ConnectionError – If the device is not accessible.

  • NoRouteToDevice – when the device is not reachable after applying the new configuration.

set_dhcp_mode() → tuple[bool, str][source]

Enables DHCP mode in the network configuration of the device.

Performs the following steps:
  • Enables DHCP mode on the MCH.

  • Sets the internal IP address value to match the address provided by the DHCP server(required to prevent DHCP lease issues).

  • Sets the hostname value.

Returns

If failure, a tuple containing False, and a message about the failure. If success, a tuple containing True, and an empty string.

Raises
  • ConnectionError – If the device is not accessible.

  • NoValidConn – If no valid connection types supporting this feature are used by the device.

update_fw(fw_version: str, part: str = 'MCH') → tuple[bool, str][source]

Update the firmware of the device.

This method expects the firmware binary pointed by the value of the argument fw_version to be available in the TFTP server. Mainly, this method injects the command update_firmware to an NAT MCH.

Parameters
  • fw_version – version release number for the new fw.

  • part – not used

Returns

If failure, it returns a tuple containing False, and a message about the failure. If success, it returns True,

gendev_tools.nat_mch.nat_mch_moxa module

nat_mch_moxa.py

Communication via Moxa is performed via a telnet connection. Therefore, the Moxa class is implemented as a child class that inherits from NATMCHTelnet. As such, all operations supported by the telnet class are supported by the MOXA class.

class gendev_tools.nat_mch.nat_mch_moxa.NATMCHMoxa(mch_ip_address: str, moxa_ip_address: str, port: int, backplane, logger: gendev_tools.gendev_logger.GenDevLogger = None, hostname: str = None, **kwargs)[source]

Bases: gendev_tools.nat_mch.nat_mch_telnet.NATMCHTelnet

NATMCHMoxa access an NAT MCH via Moxa.

This module implements some operations using the command line interface via Moxa. Thus, the MCH has to be connected to a Moxa serial server. The firmware update relies on the mchconfig-server to serve the firmware image using the FTP protocol.

Supported operations: - Retrieve the general information of the MCH. - Firmware update of the MCH. - Enabling of DHCP on the MCH.

__init__(mch_ip_address: str, moxa_ip_address: str, port: int, backplane, logger: gendev_tools.gendev_logger.GenDevLogger = None, hostname: str = None, **kwargs)[source]

Class constructor.

Parameters
  • ip_address – the IP address of the Moxa serial server.

  • port – port of the Moxa server that the MCH is connected to, in the range [0, 1, … 16]

  • logger – reference to a logger that is being used

Raises

gendev_err.ConnTimeout if the device is not reachable.

gendev_tools.nat_mch.nat_mch_web module

Module contents