此图是GNS3路由器想要配置的图。但是连接没有打开
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']))
你可以试一下:
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())