pythonnetwork-programmingcisconapalm

backing a cisco router, using NAPALM, using remote login using SSH


this image is the diagram for GNS3 of routers want to configureTrying to Backup the configuration of a Cisco Router. but the connection is not opening.

    from napalm import *
    import napalm
    drivers = napalm.get_network_driver('ios')
    device_detail = {'hostname':'192.168.1.2','username':'wahid','password':'wahid'}
    router = drivers(**device_detail)
    router.open() 
#The problem is here <- Exception has occurred: ValueError
#Failed to enter enable mode. Please ensure you pass the 'secret' argument to #ConnectHandler.
    print('Connection is Opened with ->{}'.format(device_detail['hostname']))
    config = router.get_config()
    print('Configuratin on this {} router ->'.format(device_detail['hostname']))

Solution

  • Can you try as follows:

    from napalm import get_network_driver
    from getpass import getpass
     
     
    hostname = input("IP address of router: ")
    username = input(f"Username of {hostname}: ")
    password = getpass(f"Password of {hostname}")
    secret = getpass(f"Enable password of {hostname}: ")
     
    driver = get_network_driver("ios")
    device_detail = {
        "hostname": hostname,
        "username": username,
        "password": password,
        "optional_args": {
            "secret": secret
        }
    }
     
    with driver(**device_detail) as router:
        print(router.get_facts())