Connecting to a model-driven SR OS device

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.

Note: All arguments are ignored when the Python application is executed on an SR OS device.
Table: Connect() method arguments
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.

Note: The connect method is slower to complete for the first compilation of a specific set of YANG modules. Subsequent connections for that set of YANG modules are significantly faster. A locally cached set of YANG modules is not specific to an individual router.

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.