我的代码有问题-代码本身具有用户交互性(menu),并且包含一个文件,该文件具有netmiko将必须ssh和发送命令的开关,我担心的是该文件仅包含IP读取1个IP地址,尽管我确实有多个。
如果我在print(devices)
之前做过while True
,则可以看到列出的所有IP。
如果我在print
中输入了while True
,则只能看到最后一个IP。
完整代码如下:https://pastebin.com/1a6kC28b
with open('./devices_ip/devices_file') as f:
devices_list = f.read().splitlines()
for devices in devices_list:
ip_address_of_device = devices
Cisco_device = {
'device_type': 'cisco_ios',
'ip': ip_address_of_device,
'username': username,
'password': password
}
ICX_device = {
'device_type': 'ruckus_fastiron',
'ip': ip_address_of_device,
'username': username,
'password': password
}
hp_device = {
'device_type': 'hp_procurve',
'ip': ip_address_of_device,
'username': username,
'password': password
}
# Loop menu in case incorrect option is selected, and user declines confirming menu option
while True:
print "\n"
print "------------------ Nettools v2 ------------------ \n"
print "1) SSH Switches & Push commands"
print "2) Setup VLAN (Work in progress)"
print "9) Exit menu\n"
menuChoice = raw_input("Choose a menu option: ")
elif menuChoice == '1':
while True:
model = raw_input("\nEnter the models type of your switch: " )
if model != 'HP' and model != 'Cisco' and model != 'ICX':
print "\nPlease enter HP , Cisco or ICX only. \n"
continue
elif model == 'HP':
r5 = r5_connect()
output = r5.send_config_set(commands_list_hp)
r5.disconnect()
print output
print "\n Connection has been established and commands has been pushed successfully for your HP Devices...\n"
break
关于在True期间如何解决此问题的任何建议:
谢谢