SSH NETCONF

A low-level NETCONF manager for initiating an SSH NETCONF session with a radio and executing some RPC. The main API is SSHNetconf.

Note

Applications would not usually call this API directly, but rather through the wrapper commander TgCommander.

Usage Examples

>>> from tgtools.drivers.sshnetconf import SSHNetconf
>>> netconf = SSHNetconf('192.168.0.1', username='admin', password='admin')
>>> netconf.connect()
>>> response = netconf.rpc(f'<get-events xmlns="http://siklu.com/yang/tg/events"><number>1</number></get-events>')
>>> netconf.disconnect()

Class Information:

class tgtools.drivers.sshnetconf.SSHNetconf(ip_addr: str | IPv4Address | IPv6Address, username: str = 'admin', password: str = 'admin', remote: str = '', socket_timeout: float = 2.5, ssh_logger: bool = False, log_level_file: int = 20, log_level_console: int = 50)

A NETCONF driver for Siklu by Ceragon TG radios. Essentially a wrapper for ncclient.

Radio can be connected to directly (to ip_addr); or indirectly, by tunneling into a remote Client Node (with name remote) via ip_addr.

__init__(ip_addr: str | IPv4Address | IPv6Address, username: str = 'admin', password: str = 'admin', remote: str = '', socket_timeout: float = 2.5, ssh_logger: bool = False, log_level_file: int = 20, log_level_console: int = 50)

Initialise with arguments:

Parameters:
  • ip_addr (str | ipaddress.IPv4Address | ipaddress.IPv6Address) – IP address of radio.

  • username (str) – Username to log in to radio (default: admin).

  • password (str) – Password to log in to radio (default admin).

  • remote (str) – Name of remote radio to tunnel into (default: ‘’, for no-tunneling).

  • socket_timeout (float) – Timeout for socket connection (default in consts.py).

  • ssh_logger (bool) – If True, enable logger (default: False).

  • log_level_file (int) – Logging level to file (default: logging.INFO).

  • log_level_console (int) – Logging level to console (default: logging.CRITICAL).

connect() bool

Open NETCONF connection to radio (either directly to ip_addr, or else to remote remote (if provided), by tunneling via ip_addr.

Returns:

True if radio is connected, False otherwise.

Return type:

bool

disconnect()

Disconnect Netconf session.

is_connected() bool

Check connection status.

Returns:

True if radio is connected, False otherwise.

Return type:

bool

rpc(cmd_xml: str) str

Send an RPC request (represented as XML) and return the XML response.

Parameters:

cmd_xml (str) – RPC request, as XML.

Returns:

Response to RPC reponse, as XML.

Return type:

str

ip_addr: str

IP address for radio, or (if remote provided: gateway to remote radio).

property last_err

Last error (clears after it’s accessed).

netconf: Manager | None

Underlying ncclient instance.

password: str

Password to log in to radio.

remote: str

Name of remote device (if tunneling through).

property rpc_response

RPC response to rpc() (clears after it’s accessed).

socket_timeout: float

Socket timeout

username: str

Username to log in to radio.