Commander

Manages the interaction with a single radio, with API tgtools.crawler.commander.TgCommander. Methods are provided to:

  • Connect and disconnect from a radio (either IP-accessible or IP-less remote Client Node).

  • Execute the get RPC to fetch comprehensive telemetry, and store both the raw (XML) response, as well as the parsed response.

  • Execute the get-events RPC to fetch the latest events, and parse the output.

  • Execute the get-config RPC to fetch one of the configuration databases.

  • Execute the run-cli-commands RPC to send CLI commands to the radio.

  • Execute the set-system-date and set-system-time RPCs to set the radio’s date and time based on the computer’s clock.

  • Maintain a log of all errors and all configuration-affecting commands sent to the radios.

Usage Examples:

>>> from tgtools import TgCommander, Credential
>>> credential = Credential('192.168.0.1')
>>> cmd = TgCommander(credential)
>>> cmd.connect()
>>> if cmd.is_connected:
>>>     cmd.get_and_parse()
>>>     print(f"Local radio name: {cmd.local_name}")
        Local radio name: dn1

>>>     print(f"List of remote Client Nodes: {cmd.remote_cns_names}")
        Local radio name: dn1

>>>     cmd.get_events_and_parse(2)
>>>     print(cmd.events_parsed)
        Events:
               {'route': '192.168.0.1', 'sampled': '2025-01-03 12:30:48', 'local': 'dn1', 'index': 0, 'timestamp': ' 2024-12-29 21:19:00.288', 'id': '101', 'category': 'SYSTEM', 'device': 'LOCAL', 'type': 'GPS', 'msg': 'GPS state changed from 3D to no-fix', 'power_event': '', 'link_name': '', 'link_event': '', 'up_for': '', 'cause': ''}
               {'route': '192.168.0.1', 'sampled': '2025-01-03 12:30:48', 'local': 'dn1', 'index': 1, 'timestamp': ' 2024-12-29 21:19:01.288', 'id': '102', 'category': 'SYSTEM', 'device': 'LOCAL', 'type': 'GPS', 'msg': 'GPS state changed from no-fix to 3D', 'power_event': '', 'link_name': '', 'link_event': '', 'up_for': '', 'cause': ''}

>>>     cmd.disconnect()

Class Information:

class tgtools.crawler.commander.TgCommander(credential: Credential, remote_cn: str = '')
__init__(credential: Credential, remote_cn: str = '')
Parameters:
  • credential (Credential) – Credential to log into radio (IP address, username, password).

  • remote_cn (str) – Name of remote Client Node (if tunneling into a remote radio).

cli_send(commands: list[str])

Run the run-cli-commands RPC, sending to the radio a list of CLI commands.

Parameters:

commands (list[str]) – List of CLI commands.

connect() bool

Connect to radio.

Returns:

Indication of whether connection was successful.

Return type:

bool

disconnect()

Disconnect from radio.

get_and_parse()

The main API for running the get RPC, fetching result and parsing it. The parsed output is updated in get_parsed. Also updated are the local_name and remote_cns_names attributes.

get_config(config_db: str)

Run the get-config RPC and pretty-format the received XML.

Parameters:

config_db (sr) – The configuration database requested: ‘candidate’, ‘running, or ‘startup’.

get_events_and_parse(num_events: int = 200)

The main API for running the get-events RPC, fetching result and parsing it.

Parameters:

num_events (int) – Number of events to fetch (default: 200).

get_events_rpc(num_events: int = 200) str | None

Execute the get-events RPC. Avoid calling directly, and use instead get_events_and_parse().

Parameters:

num_events (int) – Number of events to fetch (default: 200).

Returns:

response from radio as XML

Return type:

str | None

get_parse(get_xml: str, prefix_fields: dict[str, str]) TgParser

Parse the XML response of the get RPC. Avoid calling directly, and use instead get_and_parse().

Parameters:
  • get_xml (str) – The raw XML response from the radio to the get RPC.

  • prefix_fields (dict[str,str]) – Optional labels to prepend to the parsed output (typically indicating the radio and timestamp).

Return type:

TgParser

get_rpc() str

Execute the get RPC. Avoid calling directly, and use instead get_and_parse().

Returns:

response from radio, as raw XML

Return type:

str

set_tod(hours_shift: float = 0)

Configure the date and time using the set-system-time and set-system*date RPCs. The date and time are copied from the computer (running this program), with the addition of hours_shift (to compensate for possible different time zones).

Parameters:

hours_shift (float) – delta hours added to the computer’s time before sending to radio. For example, if computer time is 08:00 and hours_shift equals 2.5, the time configured to radio will be 10:30. The default for hours_shift is zero.

commands: list[Cmd]

List of (configuration-changing) commands sent to radio.

config_xml: dict[str, str]

Response to the get-config RPC (raw XML).

credential: Credential

Radio’s login credential (IP address, username, password).

errors: list[Err]

List of errors encountered while interacting with radio.

events_parsed: Events

Response to the get-events RPC, parsed.

events_xml: str

Response to the get-events RPC (raw XML).

get_parsed: dict[str, list]

Response to the get RPC, parsed.

get_sections: list[str]

Parsing sections for the response of the get RPC.

get_xml: str

Response to the get RPC (the raw XML).

property is_connected: bool

Indication if radio is connected.

rtype: bool

local_name: str

Name of local radio (updated after calling get_and_parse()).

remote_cn: str

Name of remote radio (if tunneling into a remote Client Node, rather than a local one specified in credential).

remote_cns_names: list[str]

List of all remote Client Nodes (updated after calling get_and_parse()).

ssh

Underlying SSHNetconf session.