0
list1 = ['ibsdr1', 'ibsds1', 'ibsds1', 'ibsdm2', 'ibsdm2', 'ibsdm2']

list2 = ['Gig 0/0/1', 'Gig 6/47', 'Gig 5/47', 'Gig 6/7', 'Gig 6/3', 'Gig 5/3']

I have two lists, I need to run below script on each device of list1 with the respective port of list2.

list1[0]. should select only list2[0], it shouldn't select the rest of list2.

Each and every list index should select only their respective index.

ibsdr1 should select Gig 0/0/1
ibsds1 should select Gig 6/47
ibsds1 should select Gig 5/47
ibsdm2 should select Gig 6/7
ibsdm2 should select Gig 6/3
ibsdm2 should select Gig 5/3

Below is the script I am trying to run, but I am not getting the right output. list1 indexes are selecting all the list2 indexes one by one.

for (sw, op) in zip(list1, list2):
    connect = {'device_type': 'cisco_ios', 'ip': sw, 'username': user, 'password': password, 'port': 22}
    net_connect1 = ConnectHandler(**connect)
    opout = net_connect1.send_command_expect('show interfaces '+op+' switchport')
    opp.append(opout)
    print (opp)
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • What is the output you get instead of what you want? Your code seems to make sense to me. – mkrieger1 Aug 17 '18 at 18:36
  • 1
    I haven't got a ConnectHandler library installed on my machine. Can you provide a [MCVE] that demonstrates the problem, and doesn't require third party libraries? – Kevin Aug 17 '18 at 18:37
  • Check the datatype if opp using type(opp). If it is a list then it will surely show the ordered collection. List is ordered collection so in that case if something at 0 index, it will remain at 0 index. Your loop should work fine if there is issue with the datatype then we can see. – Manu Gupta Aug 17 '18 at 18:38
  • All the list1 indexes selecting the last index of the list2. Thats how i am getting the output. I am running the script on Network Devices using Netmiko library. Not sure what i am missing here. – sam chel Aug 17 '18 at 18:58
  • Can you please show the output you actually get, and the output you expect instead, in comparison? – mkrieger1 Aug 17 '18 at 19:00
  • Are you sure that there is no typo in your code where you mix up `op`, `opp`, and `opout`? – mkrieger1 Aug 17 '18 at 19:03
  • sorry Guys, its my mistake. its typo error i was using different variable. After correcting the right one, i am getting the right output. Thanks a lot for helping me. I have taken all of your time because of my mistake. Sorry again for that – sam chel Aug 17 '18 at 19:14

0 Answers0