How To Connect to A Network Device

Calling the CiscoAutomationFramework.connect_ssh function is how you connect to a device. it sets up the connection and all of the low level library and hands you an instantiated child of the CiscoFirmware object specific to the device type you are connected to.

You can connect by assigning the output directly to a variable:

from CiscoAutomationFramework import connect_ssh
ssh = connect_ssh('ip', 'username', 'password')
#other code here
ssh.close_connection()

However It is recommended to use a context manager so you dont have to remember to close the connection or if an exception if hit in your code it closes for you:

from CiscoAutomationFramework import connect_ssh
with connect_ssh('ip', 'username', 'password') as ssh:
    # Code here while logged into the device
# Code here while logged out of the device
CiscoAutomationFramework.connect_ssh(ip, username, password, port=22, enable_password=None, timeout=10) → CiscoAutomationFramework.FirmwareBase.CiscoFirmware

Connects to your cisco device, returns a firmware specific instance of CiscoFirmware object.

Parameters:
  • ip (str) – IP address or hostname of Cisco device
  • username (str) – Username used to login
  • password (str) – Password for user
  • port (int) – Port to use (default 22)
  • enable_password (str) – Enable password to use if the user does not have privileges directly to privilege exec
  • timeout (int) – SSH timeout in seconds
Returns:

CiscoFirmware Object

Return type:

CiscoFirmware