To enable access to an SR OS device, the user must create a Connection object, which is a Python object that references the application’s connection to a specific SR OS node.
The underlying connection transport protocol is NETCONF.
The connect() method is provided to create this Connection object.
The following example shows the creation of a connection named connection_object to a device with the IP address 192.168.168.1.
from pysros.management import connect
connection_object = connect(host='192.168.168.1', username='admin', password='admin')
The following table describes the arguments available for the connect() method.
Argument | Type | Mandatory | Description |
---|---|---|---|
host |
string |
Yes |
IP address, hostname, or FQDN of the SR OS device to connect to |
username |
string |
Yes |
Username to connect to the SR OS device |
password |
string |
Yes |
Password to connect to the SR OS device If no password is provided, SSH key-based authentication is attempted. |
port |
integer |
No |
TCP port on the SR OS node that the connect attempt is made to Default: 830 |
yang_directory |
string |
No |
Directory to read YANG module files from Default: None |
rebuild |
Boolean |
No |
Forces the schema cache to be rebuilt upon connect Default: False |
timeout |
integer |
No |
Maximum time for connection, obtaining YANG modules, and schema generation Default: 300 seconds |
hostkey_verify |
Boolean |
No |
Disables SSH hostkey checking. Nokia recommends to not use this in a live deployment. |
When a Python application makes a connection to an SR OS device using the connect() method, the application performs the following actions.
The device is queried to identify a set of modules required to manage the device. This is performed by identifying the module-set-id (yang-library:1.0) or content-id (yang-library:1.1) from the devices advertised capabilities.
The set of modules are queried using /modules-state from the IETF YANG library RFC 8525.
The local schema cache is checked to determine whether a model-driven management schema is already generated for the same set of YANG modules. If no identical local schema cache exists, or if the rebuild argument is set to True, the following occurs.
If the yang_directory argument is not provided to the connect() method, each YANG module listed by the SR OS node is downloaded directly from the node.
If the yang_directory argument is provided to the connect() method, the YANG module files from this directory that correspond to the list of required modules obtained from the router are used.
The YANG modules are compiled into a schema cache for use by the developer and the pySROS libraries.
The local model-driven schema cache is stored in the .pysros directory within the developer’s local home directory. If this directory is deleted or modified, the cache is rebuilt on the next connect() API call.