问题
I have written below code to login to HP ARuba Switches and Make changes.. But it is not working.. Gives Error after login. What Can I change in below code to make it work with Aruba OS. It should throw error if anything goes wrong and save it in one file based on error.. And if any other device comes other than Aruba , should throw error and continue. Model - 2930F-48G-PoE
Any help will be highly appreciated.
from getpass import getpass
from netmiko import ConnectHandler
from netmiko.ssh_exception import NetMikoTimeoutException
from netmiko.ssh_exception import AuthenticationException
from paramiko.ssh_exception import SSHException
from netmiko.aruba import ArubaSSH
from netmiko.aruba import *
username = input("Enter username: ")
password = getpass()
with open('HP_commands_file.txt') as f:
commands_list = f.read().splitlines()
with open('HP_devices_list.txt') as f:
devices_list = f.read().splitlines()
for devices in devices_list:
print("Connecting to device: " + devices)
host_name_of_device = devices
hp_device = {
'device_type' : 'hp_procurve' ,
'host' : host_name_of_device ,
'username' : username ,
'password' : password ,
}
## If we want error to be stored in particular file
Timeouts=open("Connection_TimeOuts_HP.txt", "a")
Authfailure=open("Auth_failures_HP.txt", "a")
SSHException=("SSH_Failure_HP.txt", 'a')
EOFError=("EOFerrors_HP.txt",'a')
UnknownError=("UnknownError_HP.txt",'a')
################# End#############
try:
net_connect = ConnectHandler(**hp_device)
except (AuthenticationException):
print("Authetication failure: " + host_name_of_device)
Authfailure.write('\n########\n' + host_name_of_device)
continue
except (NetMikoTimeoutException):
print("Time out from device: " + host_name_of_device)
Timeouts.write('\n########\n' + host_name_of_device)
continue
except (EOFError):
print("End of File reached: " + host_name_of_device)
EOFError.write('\n' + host_name_of_device)
continue
except (SSHException):
print("Not able to SSH: Try with Telnet: " + host_name_of_device)
SSHException.write('\n########\n' + host_name_of_device)
continue
except Exception as unknown_error:
print("May be error with enable mode or device name is wrong or other: " + str(unknown_error))
continue
output = net_connect.send_config_set(commands_list)
print(output)
来源:https://stackoverflow.com/questions/62419885/code-to-login-hp-aruba-switches-network-programming